@@ -46,8 +46,35 @@ def get_sensordef():
4646 "default" : "yes" ,
4747 "help" : "Internal sensor used to monitor the health of a PRTG probe" ,
4848 "tag" : "mpprobehealthsensor" ,
49- "fields" : [],
50- "groups" : []
49+ "groups" : [
50+ {
51+ "name" :"Group" ,
52+ "caption" :"Temperature settings" ,
53+ "fields" :[
54+ {
55+ "type" :"radio" ,
56+ "name" :"celfar" ,
57+ "caption" :"Choose between Celsius or Fahrenheit display" ,
58+ "help" :"Choose wether you want to return the value in Celsius or Fahrenheit" ,
59+ "options" :{
60+ "C" :"Celsius" ,
61+ "F" :"Fahrenheit"
62+ },
63+ "default" :"C"
64+ },
65+ {
66+ "type" :"integer" ,
67+ "name" :"maxtemp" ,
68+ "caption" :"Error temperature" ,
69+ "required" :"1" ,
70+ "minimum" :20 ,
71+ "maximum" :75 ,
72+ "help" :"Set the maximum temperature above which the temperature sensor will provide a error (not below 20 or above 75)" ,
73+ "default" :45
74+ },
75+ ]
76+ }
77+ ]
5178 }
5279 return sensordefinition
5380
@@ -59,6 +86,7 @@ def get_data(data):
5986 cpu = probehealth .read_cpu ('/proc/loadavg' )
6087 temperature = probehealth .read_temp ()
6188 disk = probehealth .read_disk ()
89+ health = probehealth .read_probe_health (data )
6290 logging .info ("Running sensor: %s" % probehealth .get_kind ())
6391 except Exception as e :
6492 logging .error ("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (probehealth .get_kind (),
@@ -71,6 +99,8 @@ def get_data(data):
7199 }
72100 return data
73101 probedata = []
102+ for element in health :
103+ probedata .append (element )
74104 for element in mem :
75105 probedata .append (element )
76106 for element in temperature :
@@ -196,3 +226,37 @@ def read_temp(self):
196226 "value" : float (data [i ])})
197227 return chandata
198228
229+ def read_probe_health (self , config ):
230+ health = 100
231+ logging .debug ("Current Health: %s percent" % health )
232+ data = []
233+ chandata = []
234+ temp = open ("/sys/class/thermal/thermal_zone0/temp" , "r" )
235+ lines = temp .readlines ()
236+ temp .close ()
237+ temp_float = float (lines [0 ]) / 1000.0
238+ if temp_float > config ['maxtemp' ]:
239+ health = health - 25
240+ logging .debug ("Current Health: %s percent" % health )
241+ disks = []
242+ for line in os .popen ("df -k" ):
243+ if line .startswith ("/" ):
244+ disks .append (line .rstrip ().split ())
245+ tmpHealth = 25 / len (disks )
246+ for line in disks :
247+ free = (float (line [3 ]) / (float (line [2 ]) + float (line [3 ]))) * 100
248+ if free < 10 :
249+ health = health - tmpHealth
250+ logging .debug ("Current Health: %s percent" % health )
251+ cpu = open ('/proc/loadavg' , "r" )
252+ for line in cpu :
253+ for element in line .split (" " ):
254+ data .append (element )
255+ if float (data [1 ]) > 0.70 :
256+ health = health - 25
257+ logging .debug ("Current Health: %s percent" % health )
258+ chandata .append ({"name" : "Overall Probe Health" ,
259+ "mode" : "integer" ,
260+ "unit" : "percent" ,
261+ "value" : health })
262+ return chandata
0 commit comments