Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 1.57 KB

README.md

File metadata and controls

36 lines (29 loc) · 1.57 KB

telegraf-chrony-clients

grab total number of chrony clients for telegraf/influxdb

This is an exec script meant for telegraf in order to export the total number of clients that are communicating with chrony. It could be easily modified to POST directly to influxdb if you wanted.

You will need to give the telegraf user read access to /etc/chrony.keys (default) in order for it to be able to read the network key to contact chronyd as the clients command is not available over the UNIX socket. If you don't you'll see telegraf reporting 0 clients. The script also needs to be set as an executeable and readable/executeable by the telegraf user

setfacl -m user:telegraf:r /etc/chrony.keys setfacl -m user:telegraf:rx /opt/chronyclients.sh

chmod +x /opt/chronyclients.sh

You can test that the telegraf user has proper access by running: su -s /bin/bash -c '/opt/chronyclients.sh' telegraf

Example telegraf.conf:

[[inputs.exec]]
   commands = [ "/opt/chronyclients.sh" ]
   interval = "1m"
   timeout = "5s"
   data_format = "influx"

Example bash output:

[root@myserver ~]# /opt/chronyclients.sh
chrony,host=myserver.mydomain.com clients=500

Example telegraf output:

[root@myserver ~]# telegraf --config /etc/telegraf/telegraf.conf --input-filter exec --test
* Plugin: inputs.exec, Collection 1
* Internal: 1m0s
> chrony,host=myserver.mydomain.com clients=500 1501160403000000000

Example grafana influxdb query:

SELECT "clients" FROM "chrony" WHERE "host" =~ /^$host$/ AND $timeFilter GROUP BY "host"