Skip to content

Instantly share code, notes, and snippets.

@untergeek
Last active January 24, 2017 12:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save untergeek/c56e5c7aa3b94cdc493e to your computer and use it in GitHub Desktop.
Save untergeek/c56e5c7aa3b94cdc493e to your computer and use it in GitHub Desktop.
Logstash heartbeat plugin -> Zabbix monitoring
input {
heartbeat {
message => "epoch"
interval => 10
add_field => { "zabbix_host" => "host.example.tld" "zabbix_key" => "ls_heartbeat" }
tags => [ "heartbeat" ]
}
}
filter { }
output {
if "heartbeat" in [tags] {
zabbix {
zabbix_server_host => "localhost"
zabbix_host => "zabbix_host"
zabbix_key => "zabbix_key"
zabbix_value => "clock"
}
} else {
# ... Other outputs
}
}
Name: Logstash Heartbeat
Type: Zabbix trapper
Key: ls_heartbeat
Type of information: Numeric unsigned
Data type: Decimal
Units: unixtime
#!/usr/bin/env python
# Send calculated difference between "lastclock" (which is the epoch timestamp when Zabbix recorded "lastvalue")
# and "lastvalue" (which must also be an epoch timestamp) to "lag_key" at the ls_host on
# the specified Zabbix server.
from zoop import *
from zbxsend import Metric, send_to_zabbix
api = zoop(url='http://zabbix.example.tld/zabbix', username='user', password='supersecretpassphrase')
ls_host = 'host.example.tld'
item_key = 'ls_heartbeat'
lag_key = 'ls_heartbeat_lag'
zabbix_server = 'localhost'
zabbix_port = 10051
zabbixhost = api.host()
zabbixhost.get(name=ls_host)
zabbixitem = api.item()
zabbixitem.get(hostid=zabbixhost["hostid"], key_=item_key)
diff = int(zabbixitem["lastclock"]) - int(zabbixitem["lastvalue"])
send_to_zabbix([Metric('host.example.tld', lag_key, diff)], zabbix_server, zabbix_port)
Name: Logstash Heartbeat Lag
Type: Zabbix trapper
Key: ls_heartbeat_lag
Type of information: Numeric unsigned
Data type: Decimal
Units: s
@tuudik
Copy link

tuudik commented Jan 24, 2017

@untergeek I would love to see some small guide, how to setup Zabbix monitoring for logstash.

Or perhaps you can recommend easier way to monitor if logstash is working or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment