Page 1 of 1

Python Plugin: Synology SNMP Monitor

Posted: Sunday 07 July 2019 15:22
by febalci
This plugin monitors the following services on Synology via SNMP service:
You can find the plugin on: https://github.com/febalci/DomoticzSynology

NAS Status
HDD Empty Space %
NAS Temperature
HDD Temperature up to 4 disks
NAS CPU
NAS Memory
UPS Status
UPS Charge %
UPS Battery Time Left

Thanks to @ycahome for SNMP Reader Plugin : https://github.com/ycahome/SNMPreader

Installation

On Synology: Open Control Panel - Terminal & SNMP - SNMP - Enable SNMP Service and SNMPv1,SNMPv2c service and note down Community password.
On Domoticz install pysnmp: sudo pip3 install pysnmp
Install plugin.py to Domoticz plugins folder.

Configuration

Address: Synology IP Address
Community: Synology SNMP Community Password
DSM OID: Change this OID to 38 on DSM 5.1, 41 on DSM 6.0, 42 on DSM 6.1, 51 on DSM 6.2
Check Interval: Poll interval in minutes


This is the First commit and please bear in mind that it is beta at its best. It works well on my Synology DS 916+ on DSM 6.2. Please inform me if you have any problems...

Re: Python Plugin: Synology SNMP Monitor

Posted: Sunday 07 July 2019 19:56
by EddyG
After I made a stupid mistake and corrected it the plugin works. :D
I added drive number 5 because I have a ds1517+

Re: Python Plugin: Synology SNMP Monitor

Posted: Sunday 07 July 2019 20:32
by sincze
Works like a charm. :lol:
Synology Plugin.JPG
Synology Plugin.JPG (61.68 KiB) Viewed 4524 times

Re: Python Plugin: Synology SNMP Monitor

Posted: Sunday 07 July 2019 21:35
by LouiS22
Getting errors in log:

2019-07-07 21:34:28.917 Error: (SynoMonitor) 'onHeartbeat' failed 'ValueError':'non-hexadecimal number found in fromhex() arg at position 1'.
2019-07-07 21:34:28.917 Error: (SynoMonitor) ----> Line 271 in '/home/pi/domoticz/plugins/DomoticzSynology/plugin.py', function onHeartbeat
2019-07-07 21:34:28.917 Error: (SynoMonitor) ----> Line 221 in '/home/pi/domoticz/plugins/DomoticzSynology/plugin.py', function onHeartbeat


Also, HDD temperature monitor is not created (I have a DS416play - so that would be 4 temperature units).

Re: Python Plugin: Synology SNMP Monitor

Posted: Monday 08 July 2019 9:04
by febalci
LouiS22 wrote: Sunday 07 July 2019 21:35 Getting errors in log:

2019-07-07 21:34:28.917 Error: (SynoMonitor) 'onHeartbeat' failed 'ValueError':'non-hexadecimal number found in fromhex() arg at position 1'.
2019-07-07 21:34:28.917 Error: (SynoMonitor) ----> Line 271 in '/home/pi/domoticz/plugins/DomoticzSynology/plugin.py', function onHeartbeat
2019-07-07 21:34:28.917 Error: (SynoMonitor) ----> Line 221 in '/home/pi/domoticz/plugins/DomoticzSynology/plugin.py', function onHeartbeat


Also, HDD temperature monitor is not created (I have a DS416play - so that would be 4 temperature units).
The error comes from UPS Charge percent calculation, i understand you do not have a UPS connected to your Synology right? I have to put a check mechansim for UPS then. Btw the HDD Temperature units are created but not activated. You can find them in Settings-Devices page and activate them.

Re: Python Plugin: Synology SNMP Monitor

Posted: Monday 08 July 2019 9:15
by gizmocuz
Thanks for the Plugin !
It would be great if you could make this more generic....

Map OID xx.yy.zz ====> Percentage sensor
Map OID xx.yy.zz ====> to Temp sensor
Map ...

Where you define this as an array at the top of your plugin/or a file

This way, it could also be used to read out servers/switches/routers/.....

(Of course deliver a example configuration file for the Synology would be great!)

Re: Python Plugin: Synology SNMP Monitor

Posted: Monday 08 July 2019 9:25
by febalci
gizmocuz wrote: Monday 08 July 2019 9:15 Thanks for the Plugin !
It would be great if you could make this more generic....
Great idea, i start working on this then. Thanks a lot gizmocuz...

Re: Python Plugin: Synology SNMP Monitor

Posted: Tuesday 09 July 2019 6:31
by EddyG
Please add RaidStatus to the set of devices.
Also when you do a new setup, make it easy to add an other drive, in my case I have 5 disks

Re: Python Plugin: Synology SNMP Monitor

Posted: Tuesday 09 July 2019 8:35
by EdwinK
When I add this, I get:
2019-07-09 07:31:48.974 Error: (SynoMonitor) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/DomoticzSynology/:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload:/usr/local/lib/python3.7/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.7/dist-packages'.
2019-07-09 07:31:48.974 Error: (DiskStation) Module Import failed, exception: 'ModuleNotFoundError'
2019-07-09 07:31:48.974 Error: (DiskStation) Module Import failed: ' Name: pysnmp'
2019-07-09 07:31:48.975 Error: (DiskStation) Error Line details not available

But
pip3 install pysnmp

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pysnmp in /home/pi/.local/lib/python3.7/site-packages (4.4.9)
Requirement already satisfied: pyasn1>=0.2.3 in /home/pi/.local/lib/python3.7/site-packages (from pysnmp) (0.4.5)
Requirement already satisfied: pycryptodomex in /home/pi/.local/lib/python3.7/site-packages (from pysnmp) (3.8.2)
Requirement already satisfied: pysmi in /home/pi/.local/lib/python3.7/site-packages (from pysnmp) (0.3.4)
Requirement already satisfied: ply in /home/pi/.local/lib/python3.7/site-packages (from pysmi->pysnmp) (3.11)
So, what am I doing wrong?

Re: Python Plugin: Synology SNMP Monitor

Posted: Tuesday 09 July 2019 11:51
by Dnpwwo
Did you run the pip3 command with ‘sudo’?

That’s the most common problem

Re: Python Plugin: Synology SNMP Monitor

Posted: Thursday 11 July 2019 16:39
by EddyG
Unfortunately the plugin has a huge impact on CPU usage % peeks of over 20%, with a normal of around 1-3%.
Also memory consumption is big, more then 20Mb extra.
Even the CPU temperature has a fluctuation of 5 degrees Celsius when the CPU usage peeks.
I have the same functions running in a bash script for years now, without any impact on anything.
So what is going on?

Re: Python Plugin: Synology SNMP Monitor

Posted: Thursday 11 July 2019 20:25
by febalci
EddyG wrote: Thursday 11 July 2019 16:39 Unfortunately the plugin has a huge impact on CPU usage % peeks of over 20%, with a normal of around 1-3%.
Also memory consumption is big, more then 20Mb extra.
Even the CPU temperature has a fluctuation of 5 degrees Celsius when the CPU usage peeks.
I have the same functions running in a bash script for years now, without any impact on anything.
So what is going on?
Well, in my case i see nothing different than as before; if there is a fluctuation as you said, it might be because of the low polling frequency (I kept mine as 5 mins), and high number of requests. As this is pure SNMP requests, these NASes are designed to handle such request loads. Apart from this the only thing i can think of is that there might be a problem on pysnmp package, but as i see there are no complaints on the net regarding this. Is it possible that your Synology might be dealing with some other background processes? Maybe you can restart your Synology and check it with the plugin on and off for 30 mins.
Also,the CPU and Mem usage calculations are as follows, to reflect the same calculation phase as Synology Resource Monitor:
CPU Usage = CPU User + CPU System
Memory Usage = (Total Mem Swap + Total Mem Real) - (memSwap + memCached+memFree)

I suspect most probably that your bash script might be reflecting only CPU System for CPU Usage and Total Mem-memFree for Memory Usage. You can check it by comparing your bash script results to Synology Resource Monitor Results for compliancy.

Re: Python Plugin: Synology SNMP Monitor

Posted: Thursday 11 July 2019 21:52
by EddyG
My bash script has the same values as my DS1517+, so that is working fine for years now.
When I enable the python plugin the problem starts.
The cpu load of the raspberry rises to more then 20% at an interval of 45 to 50 minutes.
NAS cpu load is normally between 0,5% and 2% with sometimes shortly up to max. 10%
This only occurs when I enable the plugin.

Re: Python Plugin: Synology SNMP Monitor

Posted: Friday 12 July 2019 10:21
by febalci
Hi Eddy, for whatever reason, i mistook it as the CPU and Memory usage of the NAS itself... I checked mine, started using the plugin on Sunday,CPU and mem were all normal, and on Wednesday, Mem is normal but CPU usage boosted above 20% all the time. Now i restarted domoticz server and both CPU and mem returned to normal. I took it as a linux kernel upgrade or some process stuck unrelated to plugin or domoticz.

So in short, i do not face a problem on my side; there's nothing fancy about the plugin code itself, it could be related to your domoticz server version and also domoticz-plugin memory and cpu usage is beyond my abilities to comprehend or comment.

Re: Python Plugin: Synology SNMP Monitor

Posted: Friday 12 July 2019 19:16
by EddyG
No problem, I won't investigate further because I have already for years a working bash script.

Re: Python Plugin: Synology SNMP Monitor

Posted: Saturday 13 July 2019 6:27
by florisi
@Eddy
Is it possible for you to share your bash script (+ installation instructions)
Wanna try your solution too.

Re: Python Plugin: Synology SNMP Monitor

Posted: Monday 15 July 2019 20:37
by febalci
v.1.0.2:
- Fixed 'non-hexadecimal number found' error
- Added 5th HDD Temp
- Fixed UPS 'OL CHRG' and 'OB DISCHRG' shown as 'Unknown' problem.

Re: Python Plugin: Synology SNMP Monitor

Posted: Tuesday 11 August 2020 18:55
by nixalsschrott
Hi all,

does that solution also work (the same way), when Domoticz is running on Synology NAS?

Edit:
Meanwhile I tried to setup the script on Synology NAS since my DOMOTICZ is running on that system.
Unfortunately it seems not to work.

First I installed pysnmp on synology (that was not an easy task by the way)

root@DS918Plus:/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages# sudo /volume1/@appstore/py3k/usr/local/bin/pip3 install pysnmp
Collecting pysnmp
Using cached pysnmp-4.4.12-py2.py3-none-any.whl (296 kB)
Collecting pysmi
Using cached pysmi-0.3.4-py2.py3-none-any.whl (80 kB)
Collecting pycryptodomex
Downloading pycryptodomex-3.9.8-cp35-cp35m-manylinux1_x86_64.whl (13.7 MB)
|████████████████████████████████| 13.7 MB 6.2 MB/s
Collecting pyasn1>=0.2.3
Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
|████████████████████████████████| 77 kB 931 kB/s
Collecting ply
Using cached ply-3.11-py2.py3-none-any.whl (49 kB)
Installing collected packages: ply, pysmi, pycryptodomex, pyasn1, pysnmp
Successfully installed ply-3.11 pyasn1-0.4.8 pycryptodomex-3.9.8 pysmi-0.3.4 pysnmp-4.4.12


Afterwards I set up the scipt with modified configuration.
The hardware is not created (I even allowed new hardware before activating).
I cannot regognize the script to run, no log entries visible.

Happy for any tipps or adjustements.

Kind regards

Re: Python Plugin: Synology SNMP Monitor

Posted: Friday 19 February 2021 12:37
by svdhaar
Hi,

nice plugin!
I just don't get the good values on my ds218 with DSM 6.2.3-25426 Update 3
i've tried different oid's but none of them are returning the harddisk space info.

anyone an idea?
This log is with oid 51

2021-02-19 12:38:38.242 (Monitor) NAS Status: Normal
2021-02-19 12:38:39.326 (Monitor) NAS Temperature: 40
2021-02-19 12:38:44.958 (Monitor) RAM Utilization: 7
2021-02-19 12:38:44.958 (Monitor - DS218 Mem) Updating device from 0:'8' to have values 0:'7'.
2021-02-19 12:38:44.967 (Monitor) Update 0:'7' (Monitor - DS218 Mem)
2021-02-19 12:38:47.434 (Monitor) CPU: 28
2021-02-19 12:38:47.434 (Monitor - DS218 CPU) Updating device from 0:'35' to have values 0:'28'.
2021-02-19 12:38:47.447 (Monitor) Update 0:'28' (Monitor - DS218 CPU)
2021-02-19 12:38:48.603 (Monitor) HDD Used: No Such Instance currently exists at this OID
2021-02-19 12:38:49.666 (Monitor) HDD Total: No Such Instance currently exists at this OID
2021-02-19 12:38:49.666 (Monitor) HDD %: Wrong DSM OID!
2021-02-19 12:38:50.988 (Monitor) HDD Temp 1: 23
2021-02-19 12:38:52.053 (Monitor) HDD Temp 2: 23