Skip to content

Instantly share code, notes, and snippets.

@rchakode
Last active October 28, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rchakode/b4fcfbce4803d37cd8c31f72c45081d5 to your computer and use it in GitHub Desktop.
Save rchakode/b4fcfbce4803d37cd8c31f72c45081d5 to your computer and use it in GitHub Desktop.
Script that periodically monitor system disks counters using sar utility, samples are pushed to a Graphite's carbon-cache instance.
#!/bin/bash
SAMPLING_INTERVAL=5
GRAPHITE_SERVER="127.0.0.1"
GRAPHITE_CARBON_PAINTEXT_PORT=2003
LC_ALL=C \
sar -d $SAMPLING_INTERVAL | \
gawk -vhostname="$(hostname)" '{
if (NF == 10 && $2 != "DEV") {
timestamp = systime();
printf("%s.%s.rd_sec %s %d\n", hostname, $2, $4, timestamp);
printf("%s.%s.wr_sec %s %d\n", hostname, $2, $5, timestamp);
printf("%s.%s.await %s %d\n", hostname, $2, $8, timestamp);
printf("%s.%s.util %s %d\n", hostname, $2, $10, timestamp);
}
}' | \
nc ${GRAPHITE_SERVER} ${GRAPHITE_CARBON_PAINTEXT_PORT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment