HWiNFO to InfluxDB (2.00+)

Reggiceide

New Member

HWiNFO to InfluxDB (2.00+)​

Revision 1.00 28/04/2022
Initial push


Python:
#HWiNFO to influxDB 2
#Revision 1.00 28/04/2022

####Python Dependancies
#pip install influxdb_client

###Other Depenendencices
#Remote Sensor Monitor
#https://www.hwinfo.com/forum/threads/introducing-remote-sensor-monitor-a-restful-web-server.1025/

#HWiNFO PRO
#You must have HWiNFO pro - as the normal HWiNFO only gives shared memory support for 12 hrs and then resets.
#This is not an issue but it means that you have to constantly enable it every 12hrs and restart the Remote Sensor Monitor below.


####################################################################################################
# Import modules
####################################################################################################

import requests
import time
from datetime import datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS



####################################################################################################
# Variables to Set
####################################################################################################

# InfluxDB Database Details
token = "5Bn-0sJQIPMmq28lUXyfmBSWQjEJMj0qHgWRSz-5Ku2-er52wrxRWl7Yr1Sum7qIG8GbMEw4zuPFdv7Y6BkooA=="   ##sampledb
org = "yourinfluxDBorghere"
bucket = "yourbuckernamehere"
db_url = "http://192.168.1.100:8086"

# Variables of PC
sample_time = 10 # in seconds
poll_ip = "http://192.168.1.101:55555"  #ip address of PC you are monitering
device_id = "nameforyourdevicehere"

####################################################################################################
#Functions start here
####################################################################################################

#test html webserver is up
def init():
    try:
        hwinfo = requests.get(poll_ip)
        print("Remote Sensor Moniter is reachable")
    except:
        print("Unable to conact Remote Sensor Moniter web server. Check both Remote Sensor Moniter and HWiNFO are running.")
        exit()


#####Polling function
def poll():
 
    try:      
        hwinfo_web_data = requests.get(poll_ip)
    except:
        print(datetime.now(), " Error! Unable to conact Remote Sensor Moniter web server. Check both Remote Sensor Moniter and HWiNFO are running.")
        return

    try:  
        data=hwinfo_web_data.json()              
        process_data(data,write_api)    
    except AssertionError as error:
        print(error)
        return

#########Process data
def process_data(data,write_api):
    for a in data:  
        sensorclass=a['SensorClass']
        sensorname=a['SensorName']
        sensorvalue=a['SensorValue']

        #parse to format accepted by influxDB
        influxdata=str(device_id+",Measurement=" + sensorclass.replace(" ", "_")+" "+str(sensorname.replace(" ", "_"))+"="+str(sensorvalue))

        #Write to influxDB
        try:
            write_api.write(bucket, org, influxdata)
        except:
            print(datetime.now(), " Error! Could not write to database")
            return
    print(datetime.now(), ": Successfully posted data to server.")



####################################################################################################
#Main Script Starts here
####################################################################################################
print("starting....")
client = InfluxDBClient(url=db_url, token=token)
write_api = client.write_api(write_options=SYNCHRONOUS)
init()
while True:  
    poll()
    time.sleep(sample_time - time.monotonic() % sample_time)

Description and general notes​

The python script pulls HWiNFO via Remote Sensor Monitor and posts it to innfluxDB (version 2 and above only).

This program does not have to run on the local host that HWiNFO is running on. I personally have a Docker container running it on my NAS, where the InfluxDB is also installed. I'll get around to uploading the Docker container to DockerHub eventually. The script itself pushes directly to InfluxDB. It does not require Telegraf.

From influxDB, you can push to Grafana, to make pretty dashboards.

--------Python Dependencies------------​

Tested with Python 3.9, I can't comment on the compatibility of other versions but there is no reason to believe that it won't work on other versions.

pip install influxdb_client

Other Depenendencices​

Remote Sensor Monitor​

(https://www.hwinfo.com/forum/threads/introducing-remote-sensor-monitor-a-restful-web-server.1025/)

Remote Sensor Monitor is a Windows console application designed to present various hardware sensor parameters reported by HWiNFO / GPU-Z / AIDA64 / Open Hardware Monitor as a JSON string and make it available over the network. Enabling GPU-Z, HWiNFO and AIDA64 requires the programs to be running the background. The minimum supported versions are: GPU-Z: 0.7.4, HWiNFO: 4.30, AIDA64: 4.00.2706. Open Hardware Monitor sensors can be reported only if OpenHardwareMonitorLib.dll is present in the same folder as that of the application. Once the web server starts up, the JSON string is available at http://: ; The reported parameters can be filtered / configured via the web interface at http://:/config ; The program requires administrative privileges in order to open and close the applicable port in the firewall when necessary.
Download Link

To launch from the command line

Remote Sensor Monitor.exe --hwinfo=1 --gpuz=0 --aida64=0 --ohm=0

HWiNFO PRO​

Although I have only tested with the pro version, I did see the following comment here.

"You must have HWiNFO pro - as the normal HWiNFO only gives shared memory support for 12 hrs and then resets. This is not an issue but it means that you have to constantly enable it every 12hrs and restart the Remote Sensor Monitor below."

Link to Github project

Feel free to modify it to your use case.
 
Last edited:
Back
Top