amonapp / amon

Amon is a modern server monitoring platform.
https://docs.amon.cx
GNU Affero General Public License v3.0
1.33k stars 108 forks source link

Bash plugin returning no data #191

Closed jamestombs closed 6 years ago

jamestombs commented 7 years ago

Struggling to understand how custom plugins are supposed to be working.

We have some openvz guests which we want to monitor but the disk space isn't being picked up. I've created the following bash script:

#!/bin/bash

TOTAL="$(df -h | grep "/vz/" | awk '{ print $2; }')"
USED="$(df -h | grep "/vz/" | awk '{ print $3; }')"
AVAIL="$(df -h | grep "/vz/" | awk '{ print $4; }')"
PERC="$(df -h | grep "/vz/" | awk '{ print $5; }')"

echo "hdd.total:${TOTAL}|gauge"
echo "hdd.used:${USED}|gauge"
echo "hdd.available:${AVAIL}|gauge"
echo "hdd.percentage:${PERC}|gauge"

This outputs the following:

hdd.total:70G|gauge
hdd.used:13G|gauge
hdd.available:57G|gauge
hdd.percentage:19%|gauge

In /etc/opt/amonagent/plugins-enabled/custom.conf we have:

[{
  "command":"bash /path/to/hdd.sh",
  "name":"hdd"
}]

Which when tested results in:

# /opt/amonagent/amonagent -test-plugin=custom
{"hdd":{}}

Executed in 13.758446ms
martinrusev commented 7 years ago

@jamestombs The current implementation works only with an integer, meaning 70G or 19% is not going to work.

jamestombs commented 7 years ago

Thanks. For those using bash you can use | sed 's/[^0-9]*//g' to everything other than the numbers.

The following code is now working:

#!/bin/bash

TOTAL="$(df -h | grep "/vz/" | awk '{ print $2; }' | sed 's/[^0-9]*//g')"
USED="$(df -h | grep "/vz/" | awk '{ print $3; }' | sed 's/[^0-9]*//g')"
AVAIL="$(df -h | grep "/vz/" | awk '{ print $4; }' | sed 's/[^0-9]*//g')"
PERC="$(df -h | grep "/vz/" | awk '{ print $5; }' | sed 's/[^0-9]*//g')"

echo "hdd.total:${TOTAL}|gauge"
echo "hdd.used:${USED}|gauge"
echo "hdd.available:${AVAIL}|gauge"
echo "hdd.percentage:${PERC}|gauge"
jamestombs commented 7 years ago

Spoke too soon. Although the test on the local machine is working:

# /opt/amonagent/amonagent -test-plugin=custom
{"hdd":{"gauges":{"hdd.available":58,"hdd.percentage":19,"hdd.total":70,"hdd.used":13}}}

The plugin is appearing on the amon server but states that there's no data.

jamestombs commented 6 years ago

Moved bash script to /usr/local/bin but still not getting any data through to Amon.

amonagent@hostname:~$ amonagent -test-plugin=custom
{"hdd":{"gauges":{"hdd.available":57,"hdd.percentage":19,"hdd.total":70,"hdd.used":14}}}

Executed in 15.446176ms
martinrusev commented 6 years ago

@jamestombs Can you try running it as the amonagent user:

sudo -u amonagent -s
whoami # amonagent
amonagent -test-plugin=custom
jamestombs commented 6 years ago

That command was as amonagent.

martinrusev commented 6 years ago

@jamestombs The next step would be to see if you get at least the metric names in the Amon interface, when you click on Servers -> Plugins -> Custom?

jamestombs commented 6 years ago

Actually it has picked up now. Guess it needed a bit of time to gather data before plotting the graph. Looks like it was just a simple case of amonagent not being able to read the script from /root.

martinrusev commented 6 years ago

@jamestombs Nice to hear that it is working. I will put the potential permissions / location issue in a more prominent place in the documentation for future reference.