tomsajan / netio-exporter

Prometheus exporter for NETIO PDUs
5 stars 4 forks source link

netio 8QS with firmware 4.0.5 #9

Open m1012000 opened 3 months ago

m1012000 commented 3 months ago

Hi,

I have set up the docker version. Following what is outlined here: https://www.netio-products.com/en/application-notes/an50-prometheus-and-grafana-for-netio-power-data-analysis-and-visualization

Looking in the console for the container it can query the JSON from the PDU but seems to fail after a certain point (I have starred the SN):

172.17.0.1 - - [20/Aug/2024 06:57:24] "GET /metrics HTTP/1.1" 500 59 DEBUG:netio-exporter:Scraping netio at http://192.168.0.95/netio.json DEBUG:netio-exporter:Successfully scraped netio DEBUG:netio-exporter:Processing netio agent info DEBUG:netio-exporter:Agent info metric: Metric(netio_agent, Global info about Netio agent, info, , [Sample(name='netio_agent_info', labels={'model': '8QS', 'version': '4.0.5', 'json_version': '2.5', 'name': 'PowerPDU-0B', 'outputs': '8', 'sn': '****, 'target': 'http://192.168.0.95/netio.json'}, value=1, timestamp=None, exemplar=None)]) DEBUG:netio-exporter:Processing global stats DEBUG:netio-exporter:Processing global metric "Voltage" DEBUG:netio-exporter:Processing global metric "TotalCurrent" DEBUG:netio-exporter:Processing global metric "OverallPowerFactor" DEBUG:netio-exporter:Global metric "TotalPowerFactor" not processed. Either not known or not wanted DEBUG:netio-exporter:Global metric "OverallPhase" not processed. Either not known or not wanted DEBUG:netio-exporter:Global metric "TotalPhase" not processed. Either not known or not wanted DEBUG:netio-exporter:Processing global metric "Frequency" DEBUG:netio-exporter:Processing global metric "TotalEnergy" DEBUG:netio-exporter:Global metric "TotalReverseEnergy" not processed. Either not known or not wanted DEBUG:netio-exporter:Global metric "TotalEnergyNR" not processed. Either not known or not wanted DEBUG:netio-exporter:Global metric "TotalReverseEnergyNR" not processed. Either not known or not wanted DEBUG:netio-exporter:Processing global metric "TotalLoad" DEBUG:netio-exporter:Global metric "EnergyStart" not processed. Either not known or not wanted DEBUG:netio-exporter:Processing individual Netio outputs. DEBUG:netio-exporter:Output metric "ID" not processed. Either not known or not wanted DEBUG:netio-exporter:Output metric "Name" not processed. Either not known or not wanted DEBUG:netio-exporter:Processing "State" output metric. DEBUG:netio-exporter:Output metric "Action" not processed. Either not known or not wanted DEBUG:netio-exporter:Output metric "Delay" not processed. Either not known or not wanted DEBUG:netio-exporter:Processing "Current" output metric. Traceback (most recent call last): File "/usr/local/lib/python3.12/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/prometheus_client/exposition.py", line 128, in prometheus_app status, headers, output = _bake_output(registry, accept_header, accept_encoding_header, params, disable_compression) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/prometheus_client/exposition.py", line 104, in _bake_output output = encoder(registry) ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/prometheus_client/openmetrics/exposition.py", line 21, in generate_latest for metric in registry.collect(): File "/usr/local/lib/python3.12/site-packages/prometheus_client/registry.py", line 97, in collect yield from collector.collect() File "/netio/netio-exporter.py", line 296, in collect self.process() File "/netio/netio-exporter.py", line 280, in process self.process_outputs() File "/netio/netio-exporter.py", line 269, in process_outputs value=output[metric_name] metric_metadata.scale


KeyError: 'Current'
172.17.0.1 - - [20/Aug/2024 06:57:39] "GET /metrics HTTP/1.1" 500 59

This could be a user error but I'd like to know if this is confirmed as working with 4.0.* firmware (https://www.netio-products.com/en/powerpdu-8qs-firmware) on 8QS as the release notes for  4.0.1 have the following:

**The API for the main system has been changed**, therefore this update is not backward compatible with pre 4.0.0 versions, once you upgrade to this version and newer, you won't be able to downgrade.
 - Syslog - You can now use the syslog (settings -> system) protocol to log the device updates.
 - Rules - Sequences - Ability to set seqences of actions with delays in Rule action configuration.
 - Rules - Startup rules - Use the device power up conditions in rule conditions.
 - PAB - Sunrise & Sunset - "DAYLIGHT" PAB rules based on the sun position in a given geolocation can be used in rule conditions.
 - PAB - Fixes in conditioning with rules
 - JSON - JSON event that can be used as a condition in rule configuration.
 - System - Password brute force attack protection.
 - System - Output name and password length increased to 32 characters.
 - System - Timezones now display status of DST (Daylight Savings Time). DST is activated automatically.
 - MQTT - Support for wildcards in MQTT.
 - MQTT - Now includes 'UTC_TIME' variable.
 - MQTT - Now allows to subscribe as an event to trigger actions using rules.
 - MQTT - New feature called groupEvents, allows to setup a group of different topics to be published by a single event.
 - MQTT - Properly supports backlash escape characters in payloads.
 - SNMP - Scalar "Zero" when getting value by OID is not required
 - Watchdog - Deleting watchdogs no longer causes device restart.
 - Watchdog - Limit increased to 32.
 - Watchdog - New connectivity rules based on the state of the device networking.
 - Watchdog - New behaviour, upon configuration watchdog will be set to 'fail = false' and it will go to a state of rebooting (activates again).
 - NETIO Cloud - Output & device name now synchronize with cloud on change.
 - Firmware update - fixed issue when firmware update failed sometimes
 - Bug fuxes and system optimalization
 - Passwords - maximum length extended to 32 characters
tomsajan commented 3 months ago

Hi @m1012000 , thank you for opening this issue. :) It seems to me that the netio uses an updated structure of the JSON response which is not compatible with the current exporter version. It looks like there is no Current key in the response and the exporter expects it to be there.

Could you please send me the raw json response from the netio? As I don't own this netio I don't have access to the exact json structure. It will allow me to update the exporter so it works with your device :)

You can get the raw json either by using your browser and navigating to http://192.168.0.95/netio.json (and optionally authenticating with your credentials (if you configured them)), or using curl

curl -u username:password http://192.168.0.95/netio.json

(where the -u username:password is optional - only if you configured username and password) You can, of course, redact any information you feel are sensitive. Just please keep the structure intact :)

Once I have the JSON, I think I can update the exporter quite quickly.

Thank you very much, Jan

m1012000 commented 3 months ago

Hi Jan,

Thanks for coming back and supporting the request. Here is the JSON raw as requested: netio.json

Only change made is staring out the SN and MAC.

Hope that works. Please let me know I you need anything else and thanks again.

tomsajan commented 3 months ago

Thank you very much, this really helps tracking down the issue. According to this json, the netio provides power/consumption data only for the first output. The other outputs are visible in the data, but don't provide any power data. My assumption is that the other outputs were not initialized yet.

I am right to assume that you only ever tried the first output to power anything (server, most likely) and the other outputs were never used? If so, could you please try to connect anything that consumes electricity to one of the other outputs, let it run a short while (so that there are non-zero numbers on consumption) and then send me another data json dump? It would help me to determine how to deal with the outputs that don't report any power data - whether it is safe to assume that those missing numbers are just zeros (because the output was never used)

Thank you for your cooperation :)

Jan

tomsajan commented 3 months ago

Hi @m1012000, I've finally found the time to look at the issue. It seems, that in the last few years Netio introduced new models and some of them provide only a limited number of metered outputs. One of them is 8QS, which provides consumption data only for the whole device and for the first output port. The rest of the ports are unmetered (mentioned here on page 21 https://www.netio-products.com/files/NETIO-M2M-API-Protocol-JSON.pdf)

That explains the JSON structure.

So to get you going I prepared a 0.1.0-quickfix version you can start using:

And in the meantime I will be preparing a new release with proper and more robust output handling and input support.

Please try the quickfix version and let me know if it works for you or if I should make any adjustments.

Thank you for the patience and have a great day :)

Jan.