Compare commits
2 Commits
db3717bcb6
...
6e8437a6c3
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e8437a6c3 | |||
| 67bfd252a4 |
@@ -4,6 +4,7 @@ import time
|
||||
import argparse
|
||||
import subprocess
|
||||
import socket
|
||||
import cpufantemp
|
||||
from prometheus_client import start_http_server, Gauge
|
||||
|
||||
|
||||
@@ -78,6 +79,29 @@ def collectHddTemp(gaugeDict):
|
||||
print("")
|
||||
|
||||
|
||||
def collectFanSpeed(gaugeDict):
|
||||
fanTempDict = cpufantemp.getCpuTempAndFanSpeed()
|
||||
|
||||
if "fan" not in fanTempDict:
|
||||
return
|
||||
|
||||
for fanKey in sorted(fanTempDict["fan"].keys()):
|
||||
fanSpeed = fanTempDict["fan"][fanKey]
|
||||
|
||||
gaugeName = f"{fanKey}_rpm"
|
||||
gaugeDescription = f"Fan RPM of {gaugeName}"
|
||||
|
||||
## If gauge doesn't exist, create it
|
||||
gaugeObj = gaugeDict.get(gaugeName, None)
|
||||
if gaugeObj is None:
|
||||
gaugeObj = Gauge(gaugeName, gaugeDescription)
|
||||
gaugeDict[gaugeName] = gaugeObj
|
||||
|
||||
gaugeObj.set(fanSpeed)
|
||||
print(f"{gaugeName}{fanSpeed:>5} RPM")
|
||||
print("")
|
||||
|
||||
|
||||
def main(configs):
|
||||
gaugeDict = {}
|
||||
pollingInterval = configs.get("polling_interval", DEFAULT_POLLING_INTERVAL)
|
||||
@@ -86,6 +110,7 @@ def main(configs):
|
||||
while True:
|
||||
try:
|
||||
collectHddTemp(gaugeDict)
|
||||
collectFanSpeed(gaugeDict)
|
||||
time.sleep(pollingInterval)
|
||||
except KeyboardInterrupt:
|
||||
print("\nUser stopped process.")
|
||||
@@ -94,7 +119,7 @@ def main(configs):
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-p", "--port", default=DEFAULT_PORT, help="The port of exportor")
|
||||
parser.add_argument("-p", "--port", type=int, default=DEFAULT_PORT, help="The port of exportor")
|
||||
parser.add_argument("-i", "--polling_interval", default=DEFAULT_POLLING_INTERVAL, help="Polling interval for collect HDD temperature")
|
||||
args = parser.parse_args()
|
||||
DEFAULT_CONFIGS["port"] = args.port
|
||||
Reference in New Issue
Block a user