Skip to content

Instantly share code, notes, and snippets.

@mjf
Last active June 24, 2022 10:33
Show Gist options
  • Save mjf/16b50e06790ac0465c26b640d3337892 to your computer and use it in GitHub Desktop.
Save mjf/16b50e06790ac0465c26b640d3337892 to your computer and use it in GitHub Desktop.
Telegraf config to collect per-CPU cycles and instructions
# Telegraf configuration to collect per-CPU cycles and instructions
# using perf(1). You can then calculate CPI / IPC from the metrics.
# If Telegraf is not running as UID 0 (aka "root") you can either use
# sudo(1) with the perf(1) command, raise Telegraf capability, or set
# kernel.perf_event_paranoid = 0. But be warned: "Hic sunt dracones".
[[inputs.exec]]
name_prefix = "cpu_"
name_suffix = "_sample_1s"
interval = "10s"
commands = [
"perf stat -x, -A -e cycles,instructions --timeout 1000 --log-fd 1"
]
data_format = "csv"
csv_column_names = ["cpu", "count", "dummy", "probe"] # the rest is ignored
csv_tag_columns = ["cpu"]
csv_measurement_column = "probe"
fielddrop = ["dummy"]
@mjf
Copy link
Author

mjf commented Jun 24, 2022

Sample:

cpu_cycles_sample_1s,cpu=CPU0,host=host.example.com count=1296679258i 1656065203000000000
cpu_instructions_sample_1s,cpu=CPU0,host=host.example.com count=999403573i 1656065203000000000

Enjoy!

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