Filebeat在Ubuntu上運行慢可能是由于多種原因造成的,以下是一些常見的優化措施和排查步驟:
multiline.pattern: '\['
multiline.negate: true
multiline.match: after
multiline.max_lines: 10000
json.keys_under_root: true
json.overwrite_keys: true
json.message_key: log
json.add_error_key: true
queue.type: persisted
queue.max_bytes: 1024mb
flush.min_events: 2048
flush.timeout: 1s
harvester_limit
可以限制同時運行的harvester數量,避免資源過度占用。harvester_limit: 512
bulk_max_size
可以設置每次批量發送的最大文檔數,提高發送效率。output.elasticsearch:
hosts: ["localhost:9200"]
bulk_max_size: 2048
output.compression: true
filebeat.inputs:
- type: filestream
paths:
- /var/log/*.log
pipeline.workers
數量和pipeline.batch.size
。setup.monitor.enabled: true
sudo systemctl status filebeat
tail -f /var/log/filebeat/filebeat
filebeat -c /etc/filebeat/filebeat.yml validate
sudo chmod 644 /path/to/logfile
sudo netstat -tuln | grep 端口號
import requests
import json
def check_filebeat_status():
response = requests.get('http://localhost:5066')
if response.status_code == 200:
print("Filebeat is running")
else:
print("Filebeat is not running")
def query_elasticsearch():
es_url = 'http://localhost:9200'
query = {
"query": {
"match_all": {}
},
"size": 10
}
response = requests.post(f"{es_url}/_search", json=query)
results = json.loads(response.text)
for hit in results['hits']['hits']:
print(hit['_source'])
check_filebeat_status()
query_elasticsearch()
通過上述配置和優化措施,可以顯著提升Filebeat在Ubuntu系統上的性能。建議根據實際場景選擇合適的配置參數,并持續監控Filebeat的運行狀態,以確保其高效穩定地處理日志數據。