Last active
August 29, 2015 14:11
-
-
Save RaviH/48d9a423efa7e098d05f to your computer and use it in GitHub Desktop.
Logstash: Parsing logs, reading stats and sending it to graphite.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
stdin { } | |
file { | |
path => "/var/log/your_app/your_app.log" | |
start_position => beginning | |
codec => multiline { | |
'negate' => true | |
'pattern' => '^\d' | |
'what' => 'previous' | |
} | |
} | |
} | |
filter { | |
grok { | |
match => [ "message", "Number of requests:%{SPACE}%{NUMBER:TotalReq},%{SPACE}Successes:%{SPACE}%{NUMBER:TotalSuccess},%{SPACE}Errors:%{SPACE}%{NUMBER:TotalErrors}.%{GREEDYDATA:LogMessage}" ] | |
add_tag => [ "API_Stats", "Regular_Logs" ] | |
} | |
grok { | |
match => [ "message", "API errors:%{SPACE}Total Errors:%{SPACE}%{NUMBER:API_TotalErrors}%{SPACE}\[400: %{NUMBER:API_400_Errors}, 401: %{NUMBER:API_401_Errors}, 404: %{NUMBER:API_404_Errors}, 4xx: %{NUMBER:API_4xx_Errors}, 500: %{NUMBER:API_500_Errors}, 5xx: %{NUMBER:API_5xx_Errors}, others: %{NUMBER:API_Others_Errors}\]" ] | |
add_tag => [ "API_Error_Stats", "Regular_Logs" ] | |
} | |
} | |
output { | |
if "API_Stats" in [tags] { | |
stdout { codec => rubydebug } | |
graphite { | |
host => "10.11.12.13" | |
port => 2003 | |
metrics => [ | |
"environments/staging/servers/stga-API/overall/total_requests", "%{TotalReq}", | |
"environments/staging/servers/stga-API/overall/total_success", "%{TotalSuccess}", | |
"environments/staging/servers/stga-API/overall/total_errors", "%{TotalErrors}" | |
] | |
} | |
} else if "API_Error_Stats" in [tags] { | |
stdout { codec => rubydebug } | |
graphite { | |
host => "10.11.12.13" | |
port => 2003 | |
metrics => [ | |
"environments/staging/servers/stga-API/API/total_errors", "%{API_TotalErrors}", "environments/staging/servers/stga-API/API/total_400_errors", "%{API_400_Errors}", | |
"environments/staging/servers/stga-API/API/total_401_errors", "%{API_401_Errors}", "environments/staging/servers/stga-API/API/total_404_errors", "%{API_404_Errors}", | |
"environments/staging/servers/stga-API/API/total_4xx_errors", "%{API_4xx_Errors}", "environments/staging/servers/stga-API/API/total_500_errors", "%{API_500_Errors}", | |
"environments/staging/servers/stga-API/API/total_5xx_errors", "%{API_5xx_Errors}", "environments/staging/servers/stga-API/API/total_others_errors", "%{API_Others_Errors}" | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment