I have a sensor that needs to polled at least twice per second to produce any meaningful data… In my testing so far, it seems that even the desktop version of PRTG struggles with intervals below 5 seconds.
What is the best way forward? For example, should I get my custom sensor to log the data and somehow import that log every 5 seconds? If so, what format should the log be in? I figured out the format (based on https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors) to give a sensor a single value for each channel:
reply = read_angles()
result = CustomSensorResult("Sensor added")
result.add_channel(channel_name="X axis",
unit="Custom",
value=reply['x'],
is_float=True,
primary_channel=True,
is_limit_mode=True,
limit_min_error=-46,
limit_max_error=46,
limit_error_msg="Value out of range")
result.add_channel(channel_name="Y axis",
unit="Custom",
value=reply['y'],
is_float=True,
primary_channel=False,
is_limit_mode=True,
limit_min_error=-46,
limit_max_error=46,
limit_error_msg="Value out of range")
but don't know how to give a sensor channel multiple values at once...?
I figured out how to do it!
import time import urllib3 from urllib.parse import urlencode import inclinometer MOXA_IP = '192.168.1.2' MOXA_PORT = '5002' PRTG_SERVER = 'http://192.168.1.2' # Needs to be http otherwise it doesn't work PRTG_API = PRTG_SERVER + '/api/' SENSOR_PORT = '5050' SENSOR_TOKEN = '12345678' # See Push Data Advanced try: urllib3.disable_warnings() http = urllib3.PoolManager() im = inclinometer.Inclinometer(MOXA_IP, MOXA_PORT) while True: reply = im.read_angles() result = f'''{{ "prtg": {{ "result": [{{ "channel": "X axis", "value": {reply["x"]} "float": 1 }}, {{ "channel": "Y axis", "value": {reply["y"]} "float": 1 }}] }} }}''' encoded_args = urlencode({'content': result}) url = f'{PRTG_SERVER}:{SENSOR_PORT}/{SENSOR_TOKEN}?{encoded_args}' response = http.request('GET', url) time.sleep(0.5) except KeyboardInterrupt: print("User stopped pushing")Feb, 2019 - Permalink