Compare commits
2 Commits
db3717bcb6
...
6e8437a6c3
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e8437a6c3 | |||
| 67bfd252a4 |
@@ -4,6 +4,7 @@ import time
|
|||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import socket
|
import socket
|
||||||
|
import cpufantemp
|
||||||
from prometheus_client import start_http_server, Gauge
|
from prometheus_client import start_http_server, Gauge
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +79,29 @@ def collectHddTemp(gaugeDict):
|
|||||||
print("")
|
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):
|
def main(configs):
|
||||||
gaugeDict = {}
|
gaugeDict = {}
|
||||||
pollingInterval = configs.get("polling_interval", DEFAULT_POLLING_INTERVAL)
|
pollingInterval = configs.get("polling_interval", DEFAULT_POLLING_INTERVAL)
|
||||||
@@ -86,6 +110,7 @@ def main(configs):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
collectHddTemp(gaugeDict)
|
collectHddTemp(gaugeDict)
|
||||||
|
collectFanSpeed(gaugeDict)
|
||||||
time.sleep(pollingInterval)
|
time.sleep(pollingInterval)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nUser stopped process.")
|
print("\nUser stopped process.")
|
||||||
@@ -94,7 +119,7 @@ def main(configs):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
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")
|
parser.add_argument("-i", "--polling_interval", default=DEFAULT_POLLING_INTERVAL, help="Polling interval for collect HDD temperature")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
DEFAULT_CONFIGS["port"] = args.port
|
DEFAULT_CONFIGS["port"] = args.port
|
||||||
Reference in New Issue
Block a user