日誌平臺背景:
日誌的分析和監控在系統開發中佔非常重要的地位,系統越複雜,日誌的分析和監控就越重要,常見的需求有:
- 根據關鍵字查詢日誌詳情
- 監控系統的運行狀況
- 統計分析,比如接口的調用次數、執行時間、成功率等
- 異常數據自動觸發消息通知
- 基於日誌的數據挖掘
很多團隊在日誌方面可能遇到的一些問題有:
- 開發人員不能登錄線上服務器查看詳細日誌,經過運維週轉費時費力
- 日誌數據分散在多個系統,難以查找
- 日誌數據量大,查詢速度慢
- 一個調用會涉及多個系統,難以在這些系統的日誌中快速定位數據
- 數據不夠實時
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
}
}
<?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>