Telegraf: Difference between revisions

From Leo's Notes
This page was last edited on 13 January 2021, at 23:51.
Line 7: Line 7:
{{Highlight
{{Highlight
| code = [[inputs.exec]]
| code = [[inputs.exec]]
   commands = ["bash -c \"cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq {{!}} /bin/awk '{freq += \\$1; n++} END{printf(\\\"%f\\\", freq/n/1000); }'\" "]
   commands = ["bash -c \"grep MHz /proc/cpuinfo {{!}} /bin/awk -F: '{freq += \\$2; n++} END{printf(\\\"%f\\\", freq/n); }'\" "]
   name_override = "cpu_freq"
   name_override = "cpu_freq"
   data_format = "value"
   data_format = "value"
   data_type = "float"
   data_type = "float"
| lang = toml
| lang = toml
}}This will just retrieve the CPU speeds which <code>awk</code> will average out as a single value.
{{Highlight
| code = $ grep MHz /proc/cpuinfo {{!}} awk -F: '{freq+=$2; n++} END {printf("%f", freq/n);}'
3099.926000
| lang = terminal
}}
}}

Revision as of 23:51, 13 January 2021

Telegraf is an agent that pushes metrics to a server, such as InfluxDB.

Tasks

Monitoring CPU frequency

Simplest way is to use an exec input:

[[inputs.exec]]
  commands = ["bash -c \"grep MHz /proc/cpuinfo | /bin/awk -F: '{freq += \\$2; n++} END{printf(\\\"%f\\\", freq/n); }'\" "]
  name_override = "cpu_freq"
  data_format = "value"
  data_type = "float"

This will just retrieve the CPU speeds which awk will average out as a single value.

$ grep MHz /proc/cpuinfo | awk -F: '{freq+=$2; n++} END {printf("%f", freq/n);}'
3099.926000