Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample Python program providing a Prometheus exporter that exposes system CPU and memory usage every 5 minutes.
import prometheus_client
import time
import psutil
UPDATE_PERIOD = 300
SYSTEM_USAGE = prometheus_client.Gauge('system_usage',
'Hold current system resource usage',
['resource_type'])
if __name__ == '__main__':
prometheus_client.start_http_server(9999)
while True:
SYSTEM_USAGE.labels('CPU').set(psutil.cpu_percent())
SYSTEM_USAGE.labels('Memory').set(psutil.virtual_memory()[2])
time.sleep(UPDATE_PERIOD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.