Skip to content

Commit 91bc879

Browse files
committed
Revert cpu clock to mean of all core clocks, fix warning message for empty net interfaces
1 parent 76180c0 commit 91bc879

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

library/sensors/sensors_librehardwaremonitor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import math
77
import os
88
import sys
9+
from statistics import mean
910
from typing import Tuple
1011

1112
import clr # Clr is from pythonnet package. Do not install clr package
@@ -106,8 +107,8 @@ def frequency() -> float:
106107
# Keep only real core clocks, ignore effective core clocks
107108
if "Core #" in str(sensor.Name) and "Effective" not in str(sensor.Name):
108109
frequencies.append(float(sensor.Value))
109-
# Take the highest core clock as "CPU clock"
110-
return max(frequencies)
110+
# Take mean of all core clock as "CPU clock"
111+
return mean(frequencies)
111112

112113
@staticmethod
113114
def load() -> Tuple[float, float, float]: # 1 / 5 / 15min avg:

library/sensors/sensors_python.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,19 @@ def stats(if_name, interval) -> Tuple[
262262
download_rate = 0
263263
downloaded = 0
264264

265-
if if_name in pnic_after:
266-
try:
267-
upload_rate = (pnic_after[if_name].bytes_sent - PNIC_BEFORE[if_name].bytes_sent) / interval
268-
uploaded = pnic_after[if_name].bytes_sent
269-
download_rate = (pnic_after[if_name].bytes_recv - PNIC_BEFORE[if_name].bytes_recv) / interval
270-
downloaded = pnic_after[if_name].bytes_recv
271-
except:
272-
# Interface might not be in PNIC_BEFORE for now
273-
pass
274-
275-
PNIC_BEFORE.update({if_name: pnic_after[if_name]})
276-
else:
277-
logger.warning("Network interface '%s' not found. Check names in config.yaml." % if_name)
265+
if if_name != "":
266+
if if_name in pnic_after:
267+
try:
268+
upload_rate = (pnic_after[if_name].bytes_sent - PNIC_BEFORE[if_name].bytes_sent) / interval
269+
uploaded = pnic_after[if_name].bytes_sent
270+
download_rate = (pnic_after[if_name].bytes_recv - PNIC_BEFORE[if_name].bytes_recv) / interval
271+
downloaded = pnic_after[if_name].bytes_recv
272+
except:
273+
# Interface might not be in PNIC_BEFORE for now
274+
pass
275+
276+
PNIC_BEFORE.update({if_name: pnic_after[if_name]})
277+
else:
278+
logger.warning("Network interface '%s' not found. Check names in config.yaml." % if_name)
278279

279280
return upload_rate, uploaded, download_rate, downloaded

0 commit comments

Comments
 (0)