Environmental metrics with Cumulus Linux
Custom metrics with Cumulus Linux describes how to extend the set of metrics exported by the sFlow agent and used the export of BGP metrics as an example. This article demonstrates how environmental metrics (power supplies, temperatures, fan speeds etc.) can be exported.The smonctl command can be used to dump sensor data as JSON formatted text:
cumulus@cumulus$ smonctl -jThe following Python script, smon_sflow.py, invokes the command, parses the output, and posts a set of custom sFlow metrics:
[
{
"pwm_path": "/sys/devices/soc.0/ffe03100.i2c/i2c-1/1-004d",
"all_ok": "1",
"driver_hwmon": [
"fan1"
],
"min": 2500,
"cpld_path": "/sys/devices/ffe05000.localbus/ffb00000.CPLD",
"state": "OK",
"prev_state": "OK",
"msg": null,
"input": 8998,
"type": "fan",
"pwm1": 121,
"description": "Fan1",
"max": 29000,
"start_time": 1450228330,
"var": 15,
"pwm1_enable": 0,
"prev_msg": null,
"log_time": 1450228330,
"present": "1",
"target": 0,
"name": "Fan1",
"fault": "0",
"pwm_hwmon": [
"pwm1"
],
"driver_path": "/sys/devices/soc.0/ffe03100.i2c/i2c-1/1-004d",
"div": "4",
"cpld_hwmon": [
"fan1"
]
},
...
#!/usr/bin/env python
import json
import socket
from subprocess import check_output
res = check_output(["/usr/sbin/smonctl","-j"])
smon = json.loads(res)
fan_maxpc = 0
fan_down = 0
fan_up = 0
psu_down = 0
psu_up = 0
temp_maxpc = 0
temp_up = 0
temp_down = 0
for s in smon:
type = s["type"]
if(type == Continue reading