Last active
December 15, 2022 13:11
-
-
Save rchakode/8c362c23876b82c85e997c029b076540 to your computer and use it in GitHub Desktop.
Sample Python program providing a Prometheus exporter that exposes system CPU and memory usage every 5 minutes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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