Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
import datetime
import psutil
from influxdb import InfluxDBClient
# influx configuration - edit these
ifuser = "grafana"
ifpass = "<yourpassword>"
ifdb = "home"
ifhost = ""
ifport = 8086
measurement_name = "system"
# take a timestamp for this measurement
time = datetime.datetime.utcnow()
# collect some stats from psutil
disk = psutil.disk_usage('/')
mem = psutil.virtual_memory()
load = psutil.getloadavg()
# format the data as a single measurement for influx
body = [
"measurement": measurement_name,
"time": time,
"fields": {
"load_1": load[0],
"load_5": load[1],
"load_15": load[2],
"disk_percent": disk.percent,
"disk_used": disk.used,
"mem_percent": mem.percent,
"mem_used": mem.used
# connect to influx
ifclient = InfluxDBClient(ifhost,ifport,ifuser,ifpass,ifdb)
# write the measurement

This comment has been minimized.

Copy link
Owner Author

@simonhearne simonhearne commented Jan 19, 2021

remove trailing comma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment