-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhwinfo_to_influx.py
97 lines (83 loc) · 3.06 KB
/
hwinfo_to_influx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import psutil
import time
import subprocess
import json
import requests
from datetime import datetime
from influxdb import InfluxDBClient
CLIENT = InfluxDBClient("grafana.i.3fu.de", "8086", "user", "pass", "DB")
MEASUREMENT = "arbeitspc"
REMOTE_EXE = "C:\\Users\\Gamienator\\AppData\\Roaming\\RemoteSensorMonitoring\\Remote Sensor Monitor.exe"
def checkIfProcessRunning(processName):
'''
Check if there is any running process that contains the given name processName.
'''
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
def findProcessIdByName(processName):
'''
Get a list of all the PIDs of a all the running process whose name contains
the given string processName
'''
listOfProcessObjects = []
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time'])
# Check if process name contains the given name string.
if processName.lower() in pinfo['name'].lower() :
listOfProcessObjects.append(pinfo)
except (psutil.NoSuchProcess, psutil.AccessDenied , psutil.ZombieProcess) :
pass
return listOfProcessObjects
def startProgram():
SW_HIDE = 0
info = subprocess.STARTUPINFO()
info.dwFlags = subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = SW_HIDE
exe = [REMOTE_EXE, "--gpuz=0", "--aida64=0", "--ohm=0"]
subprocess.Popen(exe, startupinfo=info)
#exe = subprocess.Popen(REMOTE_EXE, creationflags=subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP)
def sendToInflux():
NOW = datetime.now()
hwinfodata = requests.get('http://localhost:55555')
data = hwinfodata.json()
summarized = {}
for d in data:
name = "{}__{}".format(d['SensorClass'], d['SensorName']).replace(" ", "_")
summarized[name]=float(d['SensorValue'].replace(",", "."))
json_body=[
{
"measurement": MEASUREMENT,
"time": NOW,
"fields" : summarized
}
]
CLIENT.write_points(json_body)
def main():
startProgram()
time.sleep(10)
# Find PIDs od all the running instances of process that contains 'chrome' in it's name
listOfProcessIds = findProcessIdByName('Remote Sensor Monitor.exe')
if len(listOfProcessIds) > 0:
#print('Process Exists | PID and other details are')
for elem in listOfProcessIds:
processID = elem['pid']
try:
sendToInflux()
except Exception:
pass
#print((processID ,processName,processCreationTime ))
process = psutil.Process(processID)
process.terminate()
else :
print('No Running Process found with given text')
if __name__ == '__main__':
main()