Skip to content

Commit c330b59

Browse files
andrewvcjordansissel
authored andcommitted
Add website healthcheck example
Fixes #18
1 parent 331b633 commit c330b59

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

examples/website_availability.conf

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
input {
2+
http_poller {
3+
urls => {
4+
"localhost" => "http://localhost:8000"
5+
}
6+
automatic_retries => 0
7+
# Check the site every 10s
8+
interval => 10
9+
# Wait no longer than 4 seconds for the request to complete
10+
request_timeout => 8
11+
# Store metadata about the request in this field
12+
metadata_target => http_poller_metadata
13+
# Tag this request so that we can throttle it in a filter
14+
tags => website_healthcheck
15+
}
16+
}
17+
18+
filter {
19+
# The poller doesn't set an '@host' field because it may or may not have meaning
20+
# In this case we can set it to the 'name' of the host which will be 'localhost'
21+
# The name is the key used in the poller's 'url' config
22+
if [http_poller_metadata] {
23+
mutate {
24+
add_field => {
25+
"@host" => "%{http_poller_metadata[name]}"
26+
}
27+
}
28+
}
29+
30+
# Classify slow requests
31+
if [http_poller_metadata][runtime_seconds] and [http_poller_metadata][runtime_seconds] > 0.5 {
32+
mutate {
33+
add_tag => "slow_request"
34+
}
35+
}
36+
37+
# Classify requests that can't connect or have an unexpected response code
38+
if [http_request_failure] or
39+
[http_poller_metadata][code] != 200 {
40+
41+
# Tag all these events as being bad
42+
mutate {
43+
add_tag => "bad_request"
44+
}
45+
}
46+
47+
if "bad_request" in [tags] {
48+
# Tag all but the first message every 10m as "_throttled_poller_alert"
49+
# We will later drop messages tagged as such.
50+
throttle {
51+
key => "%{@host}-RequestFailure"
52+
period => 600
53+
before_count => -1
54+
after_count => 1
55+
add_tag => "throttled_poller_alert"
56+
}
57+
58+
# Drop all throttled events
59+
if "throttled_poller_alert" in [tags] {
60+
drop {}
61+
}
62+
63+
# The SNS output plugin requires special fields to send its messages
64+
# This should be fixed soon, but for now we need to set them here
65+
mutate {
66+
add_field => {
67+
sns_subject => "%{@host} is not so healthy! %{@tags}"
68+
sns_message => '%{http_request_failure}'
69+
codec => json
70+
71+
}
72+
}
73+
}
74+
}
75+
76+
output {
77+
# Catch throttled messages for request failures
78+
# If we hit one of these, send the output to stdout
79+
# as well as an AWS SNS Topic
80+
if "http_request_failure" in [tags] {
81+
sns {
82+
codec => json
83+
access_key_id => "AKIAI7T2WMT5ARV3EBNA"
84+
secret_access_key => "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"
85+
arn => "arn:aws:sns:us-east-1:773216979769:logstash-test-topic"
86+
}
87+
}
88+
89+
90+
stdout {
91+
codec => rubydebug
92+
}
93+
}

0 commit comments

Comments
 (0)