Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GPU sensors to output #20

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions glances_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,14 @@ async def get_ha_sensor_data(self) -> dict[str, Any] | None:
sensor_data["raid"] = data
if data := self.data.get("uptime"):
sensor_data["uptime"] = data
if data := self.data.get("gpu"):
sensor_data["gpu"] = {}
for sensor in data:
sensor_data["gpu"][f"GPU_{sensor['gpu_id']}__{sensor['name']}"] = {
"name": sensor["name"],
"temperature": sensor["temperature"],
"mem": sensor["mem"],
"proc": sensor["proc"],
"fan_speed": sensor["fan_speed"] if "fan_speed" in sensor else 0,
}
Comment on lines +167 to +173

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using more descriptive names here in the glances-api package already instead of doing the translation in Home Assistant?

Suggested change
sensor_data["gpu"][f"GPU_{sensor['gpu_id']}__{sensor['name']}"] = {
"name": sensor["name"],
"temperature": sensor["temperature"],
"mem": sensor["mem"],
"proc": sensor["proc"],
"fan_speed": sensor["fan_speed"] if "fan_speed" in sensor else 0,
}
unique_name = f"GPU_{sensor['gpu_id']}__{sensor['name']}"
sensor_data["gpu"][unique_name] = {
"name": sensor["name"],
"memory_use_percent": round(sensor["mem"], 1),
"processor_use_percent": sensor["proc"],
"temperature_celsius": sensor["temperature"],
"fan_speed_percent": sensor.get("fan_speed", 0),
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that adding the unit of measurement to a sensor name could be problematic as I'm frankly not sure if the return value could depend on the system's settings (Celsius vs. Fahrenheit, etc.).

Copy link

@fhoekstra fhoekstra Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Home Assistant interface will need to display a unit anyways so I figured the closer to the source we resolve the ambiguity, the better.

I based myself on the comments in this part of the glances codebase to be sure about the units:
https://github.com/nicolargo/glances/blob/develop/glances/plugins/gpu/model.py#L278

A bit further up in that same file, I see a mention of Fahrenheit conversion but that seems to be only for the GUI, not the API

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API HOST 61208/api/3/gpu
[{"key":"gpu_id","gpu_id":0,"name":"Tesla P4","mem":26.248677571614582,"proc":0,"temperature":42,"fan_speed":null}]

return sensor_data
Loading