⚙️ تنظیمات اتصال لاگ به ELK Stack
تنظیمات Logstash:
input {
beats {
port => 5044
}
file {
path => "/var/log/application/*.log"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
if [message] =~ /ERROR/ {
mutate {
add_tag => ["error"]
}
}
if [message] =~ /WARN/ {
mutate {
add_tag => ["warning"]
}
}
grok {
match => {
"message" => "%{TIMESTAMP_ISO8601:timestamp} \[%{LOGLEVEL:level}\] %{GREEDYDATA:log_message}"
}
}
date {
match => [ "timestamp", "ISO8601" ]
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "application-logs-%{+YYYY.MM.dd}"
}
stdout {
codec => rubydebug
}
}
تنظیمات Filebeat:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/application/*.log
- /var/log/system/*.log
multiline.pattern: '^\d{4}-\d{2}-\d{2}'
multiline.negate: true
multiline.match: after
output.logstash:
hosts: ["localhost:5044"]
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
تنظیمات Kibana Dashboard:
# ایجاد Index Pattern
PUT _index_template/application-logs
{
"index_patterns": ["application-logs-*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"level": {
"type": "keyword"
},
"log_message": {
"type": "text",
"analyzer": "standard"
},
"host": {
"type": "keyword"
}
}
}
}
}
# تنظیمات Visualization
{
"version": "7.15.0",
"objects": [
{
"id": "error-count-timeline",
"type": "visualization",
"attributes": {
"title": "Error Count Timeline",
"visState": "{\"title\":\"Error Count Timeline\",\"type\":\"line\",\"params\":{\"grid\":{\"categoryLines\":false,\"style\":{\"color\":\"#eee\"}},\"categoryAxes\":[{\"id\":\"CategoryAxis-1\",\"type\":\"category\",\"position\":\"bottom\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\"},\"labels\":{\"show\":true,\"truncate\":100},\"title\":{}}],\"valueAxes\":[{\"id\":\"ValueAxis-1\",\"name\":\"LeftAxis-1\",\"type\":\"value\",\"position\":\"left\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\",\"mode\":\"normal\"},\"labels\":{\"show\":true,\"rotate\":0,\"filter\":false,\"truncate\":100},\"title\":{\"text\":\"Count\"}}],\"seriesParams\":[{\"show\":\"true\",\"type\":\"line\",\"mode\":\"normal\",\"data\":{\"label\":\"Count\",\"id\":\"1\"},\"valueAxis\":\"ValueAxis-1\",\"drawLinesBetweenPoints\":true,\"showCircles\":true}],\"addTooltip\":true,\"addLegend\":true,\"legendPosition\":\"right\",\"times\":[],\"addTimeMarker\":false}",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"application-logs-*\",\"query\":{\"match\":{\"level\":\"ERROR\"}},\"filter\":[]}"
}
}
}
]
}