From 4b0e5521384d629eb2a9f57da917aba9d51b60d8 Mon Sep 17 00:00:00 2001 From: ebner Date: Mon, 20 Nov 2023 10:56:55 +0100 Subject: [PATCH] added some examples --- admin-guide/configuration/metrics_telegraf.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/admin-guide/configuration/metrics_telegraf.md b/admin-guide/configuration/metrics_telegraf.md index 2d5206b3..371ac4aa 100644 --- a/admin-guide/configuration/metrics_telegraf.md +++ b/admin-guide/configuration/metrics_telegraf.md @@ -53,3 +53,33 @@ telegraf::metrics: ``` This will only work if you have deployed the necessary script (in the example `/your/script/location/script.sh`) and the necessary sudo rule(s) beforehand. For this you might wanna use techniques described in [Distribute Files](distribute_files) and/or [Custom sudo Rules](sudo). +## Examples + +### Custom Script + +A custom telegraf collector can look something like this: +```bash +#!/bin/bash + +CONNECTED=$(/usr/NX/bin/nxserver --history | awk '$7 == "Connected" {print}' | wc -l) +DISCONNECTED=$(/usr/NX/bin/nxserver --history | awk '$7 == "Disconnected" {print}' | wc -l) +FINISHED=$(/usr/NX/bin/nxserver --history | awk '$7 == "Finished" {print}' | wc -l) + +# Provide data to telegraf +echo "nxserver open_sockets=$(lsof -i -n -P | wc -l),connected_sessions=${CONNECTED},disconnected_sessions=${DISCONNECTED},finished_sessions=${FINISHED}" +``` + +The first string of the echo command is the name of the series the data is written into. This name can be overwritten in the metric config via `name_override = "nxserver_report"` + +### Custom Config File + +A custom config file in /etc/telegraf/telegraf.d could look like this: + +``` +[[inputs.exec]] + name_override = "remacc_report" + timeout = "30s" + interval = "5m" + data_format = "influx" + commands = ["sudo /usr/lib/telegraf/scripts/remacc_report.sh"] +```