1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-05-02 06:33:25 +01:00

Adds hassio-system-metrics (#7105)

This commit is contained in:
Joakim Sørensen
2020-09-22 21:58:31 +02:00
committed by GitHub
parent 0304c0eca0
commit bd511887a7
3 changed files with 198 additions and 0 deletions

View File

@@ -1,8 +1,21 @@
import { HomeAssistant } from "../../types";
export interface HassioResponse<T> {
data: T;
result: "ok";
}
export interface HassioStats {
blk_read: number;
blk_write: number;
cpu_percent: number;
memory_limit: number;
memory_percent: number;
memory_usage: number;
network_rx: number;
network_tx: number;
}
export const hassioApiResultExtractor = <T>(response: HassioResponse<T>) =>
response.data;
@@ -15,3 +28,15 @@ export const extractApiErrorMessage = (error: any): string => {
};
export const ignoredStatusCodes = new Set([502, 503, 504]);
export const fetchHassioStats = async (
hass: HomeAssistant,
container: string
): Promise<HassioStats> => {
return hassioApiResultExtractor(
await hass.callApi<HassioResponse<HassioStats>>(
"GET",
`hassio/${container}/stats`
)
);
};