kiwimato / nut-influxdb-exporter Goto Github PK
View Code? Open in Web Editor NEWA script that can be used to export data from NUT to InfluxDB on Docker - Unraid
License: Mozilla Public License 2.0
A script that can be used to export data from NUT to InfluxDB on Docker - Unraid
License: Mozilla Public License 2.0
This project is unlicensed and as such cannot be actually used as Open Source by anyone. Please consider adding a license if the current copyright holders can agree on one.
Been getting the below error in my log every once in a while. Seems like it disconnects and struggles to reconnect again. Would be good to have this fixed or have the docker restart so that it can try and reconnect again.
Connecting to InfluxDB host:10.168.40.1, DB:nut
Connected successfully to InfluxDB
Connecting to NUT host 10.168.40.1:3493
Connected successfully to NUT
Error getting data from NUT
Error connecting to InfluxDB.
Error getting data from NUT
Error getting data from NUT
Error getting data from NUT
Error getting data from NUT
Error getting data from NUT
Due to a quirk with how the UPS shows battery voltage in NUT I've added an extra parameter on the NUT server, override.battery.voltage.nominal = 12 and override.battery.packs = 2.
With these changes I'm no longer able to export to InfluxDB
Here's the log
[DEBUG] list_vars called...
[{'measurement': 'ups_status', 'fields': {'battery.charge': 100,
'battery.packs': 2, 'battery.runtime': 1020, 'battery.voltage': 13.7, 'battery.voltage.high': 13.0, 'battery.voltage.low': 10.4,
'battery.voltage.nominal': 12,
'driver.parameter.chargetime': 14400, 'driver.parameter.pollinterval': 2, 'driver.parameter.port': 'auto',
'driver.parameter.runtimecal': '102,100,300,50', 'driver.parameter.synchronous': 'no', 'input.current.nominal': 7.0, 'input.frequency': 50.1,
'input.frequency.nominal': 50, 'input.voltage': 228.7, 'input.voltage.fault': 228.7,
'input.voltage.nominal': 230, 'output.voltage': 228.7,
'ups.delay.shutdown': 30, 'ups.delay.start': 180, 'ups.load': 14,
'ups.status': 'OL', 'ups.type': 'offline / line interactive',
'watts': 168.0},
'tags': {'host': 'power', 'device.type': 'ups', 'driver.version': '2.7.4', 'ups.productid': '5161', 'ups.vendorid': '0665'}}]
[DEBUG] http://10.0.0.44:8086 "POST /write?db=nutty HTTP/1.1" 400 174
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 112, in <module>
print(client.write_points(json_body))
File "/usr/local/lib/python3.7/site-packages/influxdb/client.py", line 530, in write_points
consistency=consistency)
File "/usr/local/lib/python3.7/site-packages/influxdb/client.py", line 598, in _write_points
protocol=protocol
File "/usr/local/lib/python3.7/site-packages/influxdb/client.py", line 343, in write
headers=headers
File "/usr/local/lib/python3.7/site-packages/influxdb/client.py", line 302, in request
raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"partial write: field type conflict: input field
\"battery.voltage.nominal\" on measurement \"ups_status\" is type integer, already exists as type float dropped=1"
Hi, getting the following error:
Connecting to InfluxDB host:192.168.1.15, DB:nut
Connected successfully to InfluxDB
INFLUXDB_DATABASE: nut
INFLUXDB_USER:
INFLUXDB_PORT: 8086
INFLUXDB_HOST: 192.168.1.15
NUT_USER: None
UPS_NAME ups
INTERVAL: 21.0
VERBOSE: true
Connecting to NUT host 192.168.1.15:3493
[DEBUG] Class initialization...
[DEBUG] -> Host = 192.168.1.15 (port 3493)
[DEBUG] -> Login = 'None' / 'None'
[DEBUG] Connecting to host
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/nut2.py", line 97, in _connect
self._srv_handler = telnetlib.Telnet(self._host, self._port,
File "/usr/local/lib/python3.8/telnetlib.py", line 218, in __init__
self.open(host, port, timeout)
File "/usr/local/lib/python3.8/telnetlib.py", line 235, in open
self.sock = socket.create_connection((host, port), timeout)
File "/usr/local/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/local/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 47, in <module>
ups_client = PyNUTClient(host=nut_host, port=nut_port, login=nut_username, password=nut_password, debug=(verbose == 'true'))
File "/usr/local/lib/python3.8/site-packages/nut2.py", line 70, in __init__
self._connect()
File "/usr/local/lib/python3.8/site-packages/nut2.py", line 112, in _connect
raise PyNUTError("Socket error.")
nut2.PyNUTError: Socket error.
I have verified my InfluxDB IP and port. Any idea what might be causing this?
There is a mismatch between the docker environment variable and the line used to set the name of the UPS in the python script nut-influxdb-exporter.py.
The docker environment variable is NUT_ALIAS
The corresponding line 23 in the python code is:
ups_alias = os.getenv('UPS_ALIAS', 'UPS')
These need to match -- the docker environment variable UPS_ALIAS does not exist, so the container won't connect to a remote NUT server if the UPS has a different name than the default 'UPS.'
It will produce an error:
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 107, in
json_body = construct_object(ups_data, remove_keys, tag_keys)
NameError: name 'ups_data' is not defined
Connecting to InfluxDB host:192.168.1.4, DB:telegraf
Connected successfully to InfluxDB
Connecting to NUT host 192.168.1.4:3493
Connected successfully to NUT
Error getting data from NUT
Recommended fix:
Change the docker environment variable to UPS_NAME
Change line 23 in nut-influxdb-exporter.py to:
ups_alias = os.getenv('UPS_NAME', 'UPS')
The current docker environment variable named NUT_ALIAS is confusing, as there's no indication what this refers to. Changing the variable to "UPS_NAME" in both places will match the wording in the unraid NUT settings panel.
Since InfluxDB 2.0 has been released, I was wondering if you could add support for InfluxDB 2.0 ?
Thanks
Have influxdb running on port 8086 and requiring SSL... using a QNAP NAS and static IP addresses/MACs on my LAN directly.
Is there something I'm doing wrong with regards to getting the influxDB connection set up properly?
Telegraf, Grafana, and other services are connecting to my influxDB just fine with SSL certs and such, but there doesn't seem to be a way to specify HTTPS for the influxdb-python connection.
Error in your container's logs:
Connecting to InfluxDB host:192.168.4.81, DB:upsd
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 30, in <module>
client.create_database(dbname)
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 737, in create_database
self.query("CREATE DATABASE {0}".format(quote_ident(dbname)),
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 512, in query
response = self.request(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 369, in request
raise InfluxDBClientError(err_msg, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: Client sent an HTTP request to an HTTPS server.
Running the containers like this:
docker run -d --name influxdb --hostname influxdb \
--network="qnet-static-bond0-25effd" --mac-address="02:42:26:84:55:51" --ip="192.168.4.81" \
-p 8086:8086 \
-e TZ=America/Detroit \
-v /share/CACHEDEV1_DATA/docker/influxdb-data/config/influxdb.conf:/etc/influxdb/influxdb.conf:ro \
-v /share/CACHEDEV1_DATA/docker/influxdb-data/ssl:/etc/ssl \
-v /share/CACHEDEV1_DATA/docker/influxdb-data/var_lib_influxdb:/var/lib/influxdb \
influxdb -config /etc/influxdb/influxdb.conf
docker run -d --name="nut-influxdb-exporter" --hostname="nut-influxdb-exporter" \
--network="qnet-static-bond0-25effd" --mac-address="02:42:26:84:55:56" --ip="192.168.4.86" \
-e TZ=America/Detroit \
-e "INFLUXDB_HOST=192.168.4.81" \
-e "INFLUXDB_PORT=8086" \
-e "INFLUXDB_USER=nut" \
-e "INFLUXDB_PASSWORD=upsdDataSubmit8455" \
-e "INFLUXDB_DATABASE=upsd" \
-e "NUT_HOST=192.168.4.15" \
-e "INTERVAL=20" \
-t maihai/nut-influxdb-exporter
/etc/influxdb/influxdb.conf HTTP config:
[http]
enabled = true
bind-address = ":8086"
auth-enabled = false
log-enabled = true
suppress-write-log = false
write-tracing = false
flux-enabled = false
flux-log-enabled = false
pprof-enabled = true
debug-pprof-enabled = false
https-enabled = true
https-certificate = "/etc/ssl/influx.crt"
https-private-key = "/etc/ssl/influx.key"
max-row-limit = 0
max-connection-limit = 0
shared-secret = ""
realm = "InfluxDB"
unix-socket-enabled = false
unix-socket-permissions = "0777"
bind-socket = "/var/run/influxdb.sock"
max-body-size = 25000000
access-log-path = ""
max-concurrent-write-limit = 0
max-enqueued-write-limit = 0
enqueued-write-timeout = 30000000000
Hi there, I'm getting an issue whereby I don't believe anything is being written to the database, not sure what is the issue but this is the debug info from the Unraid docker log
Connecting to InfluxDB host:192.168.1.5, DB:nut
Connected successfully to InfluxDB
INFLUXDB_DATABASE: nut
INFLUXDB_USER:
INFLUXDB_PORT: 8086
INFLUXDB_HOST: 192.168.1.5
NUT_USER: monuser
UPS_ALIAS UPS
INTERVAL: 21.0
VERBOSE: true
Connecting to NUT host 192.168.1.5:3493
[DEBUG] Class initialization...
[DEBUG] -> Host = 192.168.1.5 (port 3493)
[DEBUG] -> Login = 'user removed' / 'pw removed'
[DEBUG] Connecting to host
Connected successfully to NUT
[DEBUG] list_vars called...
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 107, in <module>
json_body = construct_object(ups_data, remove_keys, tag_keys)
File "/src/nut-influxdb-exporter.py", line 85, in construct_object
fields['watts'] = watts * 0.01 * fields['ups.load']
KeyError: 'ups.load'
Any ideas what could be causing this?
I just installed a new APC UPS, and the docker image is now giving an error data type conflict and can't write to Influxdb. See log below.
It was working fine with my old -- ancient -- APC UPS. The new one is an APC BN1500M2.
Any ideas?
Thank you!
Connecting to InfluxDB host:192.168.1.4, DB:telegraf
Connected successfully to InfluxDB
INFLUXDB_DATABASE: telegraf
INFLUXDB_USER:
INFLUXDB_PORT: 8086
INFLUXDB_HOST: 192.168.1.4
NUT_USER: nutslave
UPS_NAME qnapups
INTERVAL: 21.0
VERBOSE: true
Connecting to NUT host 192.168.1.4:3493
[DEBUG] Class initialization...
[DEBUG] -> Host = 192.168.1.4 (port 3493)
[DEBUG] -> Login = 'nutslave' / 'nutslave'
[DEBUG] Connecting to host
Connected successfully to NUT
[DEBUG] list_vars called...
[{'measurement': 'ups_status', 'fields': {'battery.charge': 99, 'battery.charge.low': 10, 'battery.charge.warning': 50, 'battery.date': '2001/09/25', 'battery.runtime': 2739, 'battery.runtime.low': 120, 'battery.voltage': 27.3, 'battery.voltage.nominal': 24.0, 'driver.parameter.pollfreq': 30, 'driver.parameter.pollinterval': 2, 'driver.parameter.port': 'auto', 'driver.parameter.synchronous': 'no', 'input.sensitivity': 'medium', 'input.transfer.high': 142, 'input.transfer.low': 88, 'input.voltage': 121.0, 'input.voltage.nominal': 120, 'ups.delay.shutdown': 20, 'ups.firmware': '957.e4 .D', 'ups.firmware.aux': 'e4', 'ups.load': 15, 'ups.mfr.date': '2020/08/08', 'ups.realpower.nominal': 900, 'ups.status': 'OL CHRG', 'ups.test.result': 'No test initiated', 'ups.timer.reboot': 0, 'ups.timer.shutdown': -1, 'watts': 135.0}, 'tags': {'host': 'citadel', 'battery.type': 'PbAc', 'device.mfr': 'American Power Conversion', 'device.model': 'Back-UPS NS 1500M2', 'device.serial': '4B2032P27636', 'device.type': 'ups', 'driver.version': '2.7.4.1', 'driver.version.data': 'APC HID 0.96', 'ups.mfr': 'American Power Conversion', 'ups.model': 'Back-UPS NS 1500M2', 'ups.productid': '0002', 'ups.serial': '4B2032P27636', 'ups.vendorid': '051d'}}]
[DEBUG] http://192.168.1.4:8086 "POST /write?db=telegraf HTTP/1.1" 400 151
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 113, in <module>
print(client.write_points(json_body))
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 594, in write_points
return self._write_points(points=points,
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 672, in _write_points
self.write(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 404, in write
self.request(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 369, in request
raise InfluxDBClientError(err_msg, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"partial write: field type conflict: input field \"ups.load\" on measurement \"ups_status\" is type integer, already exists as type float dropped=1"}
Error connecting to InfluxDB.
Hello, Im wondering if it is possible to pull the data from multi NUT instances?
I have an UNRAID server connected to a UPS and run the NUT plug in. I then have a 3D printer in another room and have installed NUT on OctoPi. I could like to point your Docker at both NUT instances and then feed the data into the same Influx DB.
Is this possible?
Its my first time using NUT so I might have got someone wrong. Not sure if its possible to get my UNRAID NUT plugin to monitor my 3D printer NUT and then get your plugin to pull the data from my UNRAID NUT...?
please ignore
I'm having trouble connecting to NUT on a different machine than my unraid box.
I'm at a bit of a loss on what the issue is.
Here's my config
https://imgur.com/Ufbklop
pfsense config
https://imgur.com/a/u1m9vrY
And docker log
Traceback` (most recent call last):
File "/src/nut-influxdb-exporter.py", line 107, in <module>
json_body = construct_object(ups_data, remove_keys, tag_keys)
NameError: name 'ups_data' is not defined
Connecting to InfluxDB host:10.0.0.44, DB:nut
Connected successfully to InfluxDB
INFLUXDB_DATABASE: nut
INFLUXDB_USER: admin
INFLUXDB_PORT: 8086
INFLUXDB_HOST: 10.0.0.44
NUT_USER: monuser
UPS_ALIAS UPS
INTERVAL: 21.0
VERBOSE: true
Connecting to NUT host 10.0.0.1:3493
[DEBUG] Class initialization...
[DEBUG] -> Host = 10.0.0.1 (port 3493)
[DEBUG] -> Login = 'monuser' / '1234'
[DEBUG] Connecting to host
Connected successfully to NUT
[DEBUG] list_vars called...
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 100, in <module>
ups_data = ups_client.list_vars(ups_alias)
File "/usr/local/lib/python3.7/site-packages/nut2.py", line 160, in list_vars
raise PyNUTError(result.replace("\n", ""))
nut2.PyNUTError: ERR UNKNOWN-UPS
Error getting data from NUT
Traceback (most recent call last):
File "/src/nut-influxdb-exporter.py", line 107, in <module>
json_body = construct_object(ups_data, remove_keys, tag_keys)
NameError: name 'ups_data' is not defined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.