I'm testing Pushgateway along Prometheus, pushing simple data about my VMs' services every minute with a bash script and curl, triggered by crontab.
I have two bash scripts.
The first one, cpu_usage.sh
, parse and send data about ps -aux
command to pushgateway, via curl :
#!/usr/bin/env bash
z=$(ps aux)
while read -r z
do
var=$var$(awk '{print "cpu_usage{process=\""$11"\", pid=\""$2"\", cpu=\""$3"\"}", $3z}');
done <<< "$z"
curl -X POST -H "Content-Type: text/plain" --data "$var
" http://localhost:9091/metrics/job/top/instance/machine
Everything's ok on this one, my crontab send every minute the formatted data to localhost:9091
, my pushgateway instance.
Now, I'm trying to send a parsed result of the service --status-all
command, with a script called services_list.sh
, exactly the way I've dealed with the cpu_usage.sh
script :
#!/usr/bin/env bash
y=$(service --status-all)
while read -r y
do
varx=$varx$(awk '{print "services_list{service=\""$y"\"}", 1}');
done <<< "$y"
curl -X POST -H "Content-Type: text/plain" --data "$varx
" http://localhost:9091/metrics/job/top/instance/machine
When executing both scripts manually, like ./cpu_usage.sh
and ./services_list.sh
, everything's fine, Pushgateway is successfully retrieving data from both scripts.
But when I'm passing theses calls by CRON, only cpu_usage.sh
is sending data to pushgateway (timestamp of last push on services_list
method on Pushgateway stays unchanged).
My crontab syntax is like : * * * * * cd /path/ && ./script.sh
Scripts are in 777
/ root:root
, crontab is always edited as root. I've tried to concatenate both scipts in one bash file, and no matter the order I put them, the curl call for services_list
method is never made (but everything's ok on cpu_usage
method).
I'm a bit lost, as the two scripts are very similar, and manual calls on services_list.sh
are working fine. Any thoughts ? Thank you.
Running on Debian 9 with Pushgateway 0.10.