New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


How do I poll sensor twice per second?

Votes:

0

Your Vote:

Up

Down

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...?

api custom-sensor log-stream-data real-time

Created on Feb 14, 2019 11:10:00 PM by  AlexS (87) 1 2

Last change on Feb 15, 2019 6:54:20 AM by  Erhard Mikulik [Paessler Support]



2 Replies

Accepted Answer

Votes:

3

Your Vote:

Up

Down

I figured out how to do it!

  1. Based on:
  2. https://www.paessler.com/manuals/prtg/push_monitoring
  3. https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors
  4. https://www.paessler.com/manuals/prtg/http_push_data_advanced_sensor#how-to
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")

Created on Feb 15, 2019 5:06:14 AM by  AlexS (87) 1 2

Last change on Feb 15, 2019 6:54:48 AM by  Erhard Mikulik [Paessler Support]



Votes:

1

Your Vote:

Up

Down

Well done, Alex, thank you for sharing your solution!

Created on Feb 15, 2019 6:56:11 AM by  Erhard Mikulik [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.