日志平台背景:
日志的分析和監控在系統開發中占非常重要的地位,系統越複雜,日志的分析和監控就越重要,常見的需求有:
- 根據關鍵字查詢日志詳情
- 監控系統的運作狀況
- 統計分析,比如接口的調用次數、執行時間、成功率等
- 異常資料自動觸發消息通知
- 基于日志的資料挖掘
很多團隊在日志方面可能遇到的一些問題有:
- 開發人員不能登入線上伺服器檢視詳細日志,經過運維周轉費時費力
- 日志資料分散在多個系統,難以查找
- 日志資料量大,查詢速度慢
- 一個調用會涉及多個系統,難以在這些系統的日志中快速定位資料
- 資料不夠實時
ELK+Redis版本: elasticsearch-2.1.0 kibana-4.3.1-linux-x64 logstash-2.1.1 redis-2.8.3 elk安裝參考位址: https://www.cnblogs.com/davidgu/p/6639307.html elasticsearch配置:
Kibana配置:
Logstash配置:
input {
input {
redis {
codec => json
host => "127.0.0.1"
port => 8098
key => "logstash"
data_type => "list"
threads => 10
}
}
filter {
json {
source => "message"
}
if ([message] =~ "^(?!.*?xx_data_logs_type).*$") {
drop {}
}
}
output {
if [message] =~ "xx_data_logs_type" and [message] =~ "xx_error" {
elasticsearch {
hosts => ["localhost:9200"]
index => "xx_app_error_%{+YYYY.MM.dd}"
}
}
if [message] =~ "xx_data_logs_type" and [message] =~ "xx_request_info" {
elasticsearch {
hosts => ["localhost:9200"]
index => "xx_app_request_info_%{+YYYY.MM.dd}"
}
}
if [message] =~ "xx_data_logs_type" and [message] =~ "xx_sql_info" {
elasticsearch {
hosts => ["localhost:9200"]
index => "xx_app_sql_info_%{+YYYY.MM.dd}"
}
}
if [message] =~ "xx_data_logs_type" and [message] =~ "xx_info" {
elasticsearch {
hosts => ["localhost:9200"]
index => "xx_app_info_%{+YYYY.MM.dd}"
}
}
stdout {
codec => dots
}
}
logback+redis配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="LOGSTASH" class="com.cwbase.logback.RedisAppender">
<host>127.0.0.1</host>
<port>8098</port>
<key>logstash</key>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.預設的,如果隊列的80%已滿,則會丢棄TRACT、DEBUG、INFO級别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改預設的隊列的深度,該值會影響性能.預設值為256 -->
<queueSize>5120</queueSize>
<appender-ref ref="LOGSTASH" />
</appender>
<logger name="com.xx" level="info">
<appender-ref ref="ASYNC"/>
</logger>
</configuration>