home-assistant-ecosystem / python-glances-api Goto Github PK
View Code? Open in Web Editor NEWPython API for interacting with Glances
License: MIT License
Python API for interacting with Glances
License: MIT License
I would like to be able to see at least some basic SMART data from Glances in Home Assistant so I can set up alerts/automation for potential disk issues.
Here's a sample output from my instance at /api/3/smart
[
{
"DeviceName": "sda Hitachi HDS721010CLA330",
"1": {
"name": "Raw_Read_Error_Rate",
"flags": "1",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "016",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"2": {
"name": "Throughput_Performance",
"flags": "2",
"raw": "95",
"value": "136",
"worst": "136",
"threshold": "054",
"type": "Pre-fail",
"updated": "Offline",
"when_failed": "-"
},
"3": {
"name": "Spin_Up_Time",
"flags": "3",
"raw": "286",
"value": "135",
"worst": "135",
"threshold": "024",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"4": {
"name": "Start_Stop_Count",
"flags": "4",
"raw": "1982",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"5": {
"name": "Reallocated_Sector_Ct",
"flags": "5",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "005",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"7": {
"name": "Seek_Error_Rate",
"flags": "7",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "067",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"8": {
"name": "Seek_Time_Performance",
"flags": "8",
"raw": "31",
"value": "138",
"worst": "138",
"threshold": "020",
"type": "Pre-fail",
"updated": "Offline",
"when_failed": "-"
},
"9": {
"name": "Power_On_Hours",
"flags": "9",
"raw": "14602",
"value": "098",
"worst": "098",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"10": {
"name": "Spin_Retry_Count",
"flags": "0",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "060",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"12": {
"name": "Power_Cycle_Count",
"flags": "2",
"raw": "1706",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"192": {
"name": "Power-Off_Retract_Count",
"flags": "2",
"raw": "1991",
"value": "099",
"worst": "099",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"193": {
"name": "Load_Cycle_Count",
"flags": "3",
"raw": "1991",
"value": "099",
"worst": "099",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"194": {
"name": "Temperature_Celsius",
"flags": "4",
"raw": "25",
"value": "240",
"worst": "240",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"196": {
"name": "Reallocated_Event_Count",
"flags": "6",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"197": {
"name": "Current_Pending_Sector",
"flags": "7",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"198": {
"name": "Offline_Uncorrectable",
"flags": "8",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Offline",
"when_failed": "-"
},
"199": {
"name": "UDMA_CRC_Error_Count",
"flags": "9",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
}
},
{
"DeviceName": "sdb WDC WD20EZRX-00D8PB0",
"1": {
"name": "Raw_Read_Error_Rate",
"flags": "1",
"raw": "449",
"value": "200",
"worst": "199",
"threshold": "051",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"3": {
"name": "Spin_Up_Time",
"flags": "3",
"raw": "4391",
"value": "172",
"worst": "166",
"threshold": "021",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"4": {
"name": "Start_Stop_Count",
"flags": "4",
"raw": "3123",
"value": "097",
"worst": "097",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"5": {
"name": "Reallocated_Sector_Ct",
"flags": "5",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "140",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"7": {
"name": "Seek_Error_Rate",
"flags": "7",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"9": {
"name": "Power_On_Hours",
"flags": "9",
"raw": "17776",
"value": "076",
"worst": "076",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"10": {
"name": "Spin_Retry_Count",
"flags": "0",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"11": {
"name": "Calibration_Retry_Count",
"flags": "1",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"12": {
"name": "Power_Cycle_Count",
"flags": "2",
"raw": "3098",
"value": "097",
"worst": "097",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"192": {
"name": "Power-Off_Retract_Count",
"flags": "2",
"raw": "475",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"193": {
"name": "Load_Cycle_Count",
"flags": "3",
"raw": "1110694",
"value": "001",
"worst": "001",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"194": {
"name": "Temperature_Celsius",
"flags": "4",
"raw": "23",
"value": "124",
"worst": "102",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"196": {
"name": "Reallocated_Event_Count",
"flags": "6",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"197": {
"name": "Current_Pending_Sector",
"flags": "7",
"raw": "10",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"198": {
"name": "Offline_Uncorrectable",
"flags": "8",
"raw": "10",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Offline",
"when_failed": "-"
},
"199": {
"name": "UDMA_CRC_Error_Count",
"flags": "9",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"200": {
"name": "Multi_Zone_Error_Rate",
"flags": "0",
"raw": "11",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Offline",
"when_failed": "-"
}
},
{
"DeviceName": "sdc WDC WD5000AAKX-60U6AA0",
"1": {
"name": "Raw_Read_Error_Rate",
"flags": "1",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "051",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"3": {
"name": "Spin_Up_Time",
"flags": "3",
"raw": "3816",
"value": "143",
"worst": "141",
"threshold": "021",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"4": {
"name": "Start_Stop_Count",
"flags": "4",
"raw": "459",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"5": {
"name": "Reallocated_Sector_Ct",
"flags": "5",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "140",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"7": {
"name": "Seek_Error_Rate",
"flags": "7",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "051",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"9": {
"name": "Power_On_Hours",
"flags": "9",
"raw": "8014",
"value": "090",
"worst": "089",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"10": {
"name": "Spin_Retry_Count",
"flags": "0",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "051",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"11": {
"name": "Calibration_Retry_Count",
"flags": "1",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"12": {
"name": "Power_Cycle_Count",
"flags": "2",
"raw": "401",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"184": {
"name": "End-to-End_Error",
"flags": "4",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "097",
"type": "Pre-fail",
"updated": "Always",
"when_failed": "-"
},
"187": {
"name": "Reported_Uncorrect",
"flags": "7",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"188": {
"name": "Command_Timeout",
"flags": "8",
"raw": "0",
"value": "100",
"worst": "100",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"190": {
"name": "Airflow_Temperature_Cel",
"flags": "0",
"raw": "26",
"value": "074",
"worst": "054",
"threshold": "040",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"192": {
"name": "Power-Off_Retract_Count",
"flags": "2",
"raw": "57",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"193": {
"name": "Load_Cycle_Count",
"flags": "3",
"raw": "401",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"196": {
"name": "Reallocated_Event_Count",
"flags": "6",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"197": {
"name": "Current_Pending_Sector",
"flags": "7",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"198": {
"name": "Offline_Uncorrectable",
"flags": "8",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Offline",
"when_failed": "-"
},
"199": {
"name": "UDMA_CRC_Error_Count",
"flags": "9",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Always",
"when_failed": "-"
},
"200": {
"name": "Multi_Zone_Error_Rate",
"flags": "0",
"raw": "0",
"value": "200",
"worst": "200",
"threshold": "000",
"type": "Old_age",
"updated": "Offline",
"when_failed": "-"
}
}
]
With more data keys being added to this api we are not considering if these keys are available in both V2 and V3 of Glances. Example issue (home-assistant/core#99735).
Should we drop support for V2 or should we implement a check for the specified version when adding new data keys.
cc @fabaff
3.4 puts container information under the "containers" plugin. (3.3 was "docker")
Also, "containers" omits some info, putting specific container data at top level. (i.e. http://localhost:61208/api/3/docker/containers
becomes http://localhost:61208/api/3/containers
Containers API has changed again in Glances v4:
The dictionary becomes a list, which breaks get_ha_sensor_data
In v3.4:
"containers":{"version":{},"version_podman":{},"containers":[ { <CONTAINER1> }, { <CONTAINER2> } ]},
In v4:
"containers":[ { <CONTAINER1> }, { <CONTAINER2> } ],
Error :
File "/usr/local/lib/python3.12/site-packages/glances_api/__init__.py", line 173, in get_ha_sensor_data
if data and (containers_data := data.get("containers")):
^^^^^^^^
AttributeError: 'list' object has no attribute 'get'
The now
sensor is required to implement the Glances uptime
sensor in Home Assistant.
Se the discussion here:
home-assistant/core#111402 (comment)
I'll try to provide a PR for this, but if anybody working on the library wants to chime in ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.