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:
parent
5f6346eb91
commit
de7a937d4c
7 changed files with 91 additions and 0 deletions
|
@ -0,0 +1,11 @@
|
|||
# Calculate host statistics for prometheus
|
||||
# Written by Manuel Friedli
|
||||
# Changelog:
|
||||
# 2019-11-10: Inception
|
||||
|
||||
[Unit]
|
||||
Description=Calculate CPU/Memory stats for prometheus
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/prometheus-cpu-mem-monitor.sh
|
19
app-metrics/prometheus-cpu-mem-monitor/files/prometheus-cpu-mem-monitor.sh
Executable file
19
app-metrics/prometheus-cpu-mem-monitor/files/prometheus-cpu-mem-monitor.sh
Executable 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}
|
|
@ -0,0 +1,15 @@
|
|||
# Timer for calculating host statistics for prometheus
|
||||
# Written by Manuel Friedli
|
||||
# Changelog:
|
||||
# 2019-11-10: Inception
|
||||
|
||||
[Unit]
|
||||
Description=Timer for calculating CPU/Memory stats for prometheus
|
||||
|
||||
[Timer]
|
||||
OnBootSec=1s
|
||||
OnUnitInactiveSec=10s
|
||||
AccuracySec=1s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Add table
Add a link
Reference in a new issue