Asked this already in server fault (https://serverfault.com/questions/934468/how-to-monitor-systemd-service-with-snmp) but got no answer so I'm trying it here since I want to retrieve the status with the pysnmp
library in python.
So I have a Gunicorn service on my Ubuntu server.
First I added proc gunicorn
to this file: /etc/snmp/snmpd.conf
.
But I'm not sure how to get the right values.
I've seen this question (How to monitor services with SNMP?) and tried this command snmpwalk -v 2c -c public localhost 1.3.6.1.2.1.25.4.2.1.2
to get the status of the service, but I got this message:
HOST-RESOURCES-MIB::hrSWRunName = No more variables left in this MIB View (It is past the end of the MIB tree)
So I guess the OID is wrong or I have other configurations.
But I also found this answer here (https://stackoverflow.com/a/44496076/5549711).
So I think all I need is the OID of the service and then it should get me the value.
from pysnmp.hlapi import *
for (errorIndication,
errorStatus,
errorIndex,
varBinds) in nextCmd(SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.17.7.1.2.2.1.2'))):
if errorIndication or errorStatus:
print(errorIndication or errorStatus)
break
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
How do I get the OID of my Gunicorn service?