I want to send metrics data to the Prometheus push gateway to monitor CPU and memory.
What I want is to transfer $ps aux
or $htop
information to the push gateway.
I tried this with a bash script, but I didn't succeed, which is why I'd like to try with a python script.
The big problem for me is to convert $ps aux
or $htop
information to metrics data. I really don't know how to manage it.
I tried a simple code, which works correctly:
import requests
job_name='metrics'
instance_name='10.0.0.1:9090'
team_name='cpu'
provider='Rpi'
payload_key='cpu_utilization'
payload_value='33'
response = requests.post('http://localhost:9091/metrics/job/{j}/instance/{i}/team/{t}'.format(j=job_name, i=instance_name, t=team_name), data='{k} {v}\n'.format(k=payload_key, v=payload_value))
print(response.status_code)
What I want now is to modify payload_key='cpu_utilization'
and payload_value='33'
to a list of process as $ps aux
or $htop
command.