app-metrics/prometheus-cpu-mem-monitor: Add very first draft version

Package-Manager: Portage-2.3.76, Repoman-2.3.16
This commit is contained in:
Manuel Friedli 2019-11-11 01:02:17 +01:00
parent 5f6346eb91
commit de7a937d4c
7 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#!/bin/bash
# Extract per-process CPU and memory usage from "ps aux" and send the data to prometheus
#
TARGET_URL="http://localhost:9091/metrics/job/top/instance/vps-02.friedli.info"
z=$(ps aux)
while read -r z
do
cpustats=$cpustats$(awk '{print "cpu_usage{process=\""$11"\", pid=\""$2"\"}", $3z}');
memstats=$memstats$(awk '{print "memory_usage{process=\""$11"\", pid=\""$2"\"}", $4z}');
done <<< "$z"
curl -X POST -H "Content-Type: text/plain" --data "$cpustats
" ${TARGET_URL}
curl -X POST -H "Content-Type: text/plain" --data "$memstats
" ${TARGET_URL}