ELK Stack 实时监控实战指南
一 架构与数据流
二 快速落地步骤
input {
file {
path => "/var/log/myapp.log"
start_position => "beginning"
sincedb_path => "/dev/null"
codec => "json_lines"
mode => "tail"
}
}
filter {
grok { match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:loglevel} \[%{DATA:thread}\] %{JAVACLASS:class} - %{GREEDYDATA:message}" } }
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "myapp-%{+YYYY.MM.dd}"
}
}
三 告警与可视化
PUT _watcher/watch/error_count_watch
{
"trigger": { "schedule": { "interval": "10s" } },
"input": {
"search": {
"request": {
"indices": ["logstash-*"],
"body": {
"query": {
"bool": {
"must": [{ "match": { "message": "error" } }],
"filter": [{ "range": { "@timestamp": { "gte": "now-10s" } } }]
}
}
}
}
}
},
"condition": {
"compare": { "ctx.payload.hits.total": { "gt": 0 } }
},
"actions": {
"send_email": {
"email": {
"to": "admin@example.com",
"subject": "Error Alert",
"body": "An error occurred in the system."
}
}
}
}
四 性能与可靠性要点
五 典型场景配置清单
| 场景 | 采集与处理 | 索引与时间字段 | 关键图表/指标 | 告警示例 |
|---|---|---|---|---|
| Linux系统日志 | syslog-ng收集并JSON化,经Logstash入ES | syslog-/linux-/@timestamp | 错误率、服务重启次数、登录失败Top N | 5分钟内ERROR数>阈值 |
| Spring Boot应用 | Logback输出JSON,Filebeat直传或经Logstash | springboot_logs-*/@timestamp | HTTP状态码分布、P95/P99延迟、异常堆栈Top N | 5xx比例>1%持续3分钟 |
| Nginx访问日志 | Filebeat采集,Logstash用grok解析clientip、status、request | nginx-*/@timestamp | QPS、Top 10 URL、4xx/5xx占比、GeoMap | 单IP5分钟请求>100次或5xx激增 |
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。