LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   how can I use snmp to gather data from other network hosts and display on conky? (http://www.linuxquestions.org/questions/slackware-14/how-can-i-use-snmp-to-gather-data-from-other-network-hosts-and-display-on-conky-4175454084/)

gtludwig 03-14-2013 01:17 PM

how can I use snmp to gather data from other network hosts and display on conky?
 
I'm trying to build a conky config file (.conkyrc) that polls into 4 linux servers I have on the network so I can have a quick glance at my desktop and be able to check each server for the top processes, memory and cpu consumption, network interface usage, etc.

I originally posted a related question on unix.stackexchange.com here and someone there said the ideal way to poll a network server is via snmp.
Is it so? If so, how can I poll a snmpd running on another server?

Thanks in advance,

Richard Cranium 03-14-2013 09:38 PM

As far as I can tell from a 2 minute read of the conky documentation, there's no built-in support for snmp polling.

A detailed answer depends upon if you want to use snmpv3 to poll or snmpv2c (the security models are different). Essentially, you'd have to run snmpget/snmpbulk to get the OID values for the various MIBs that you want.

If you don't know SNMP, the "simple" part isn't referring to how you actually get any information out of the *bleeping* thing.

You'd spend a lot less time running gkrellmd on each machine that you want to monitor and run gkrellm instances on your desktop to see the values you are interested in seeing.

mumpster 03-14-2013 10:03 PM

Quote:

Originally Posted by gtludwig (Post 4911621)
I'm trying to build a conky config file ... be able to check each server for the top processes, memory and cpu consumption, network interface usage, etc.
...
If so, how can I poll a snmpd running on another server?

Hm. I has not dealt with conky but IMHO usually it is much more easier just to poll Linux servers through special scripts rather than trying to grok and to figure out "Simple" management protocol. Frankly, it is simpler when compares with TNM, ha-ha-ha :).

Nevertheless...I'm sure almost anyone can cope with SNMP.
So you just need:
1) to choose (if there is something suitable) or to make youself a script for SNMPd giving correct results depending on requested OID.
2) to tell conky which OID to use. That's the main problem because there are too many OIDs.:-|
Though to give you a common idea about SNMP usage I put here my simple handler for SNMPd:

#!/bin/sh -f
#Give used real memory

PLACE=".1.3.6.1.4.1.2021.4.55"
REQ="$2"

case "$REQ" in
$PLACE.0) RET=$PLACE.0 ;;
*) exit 0 ;;
esac
case "$RET" in
$PLACE.0) echo "integer"; \
# total=`snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.4.5.0 | cut -d\ -f4`; \
# avail=`snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.4.6.0 | cut -d\ -f4`; \
#/usr/bin/free | /usr/bin/awk '{if (FNR==2) print $3}';;
/usr/bin/vmstat | /usr/bin/awk '{if (NR==3) print $4}'; exit 0;;
*) echo "string"; echo "ack... $RET $REQ"; exit 0 ;;
esac

I also have in my snmpd.conf this line:

pass .1.3.6.1.4.1.2021.4.55.0 /bin/sh /MY-SWEETHOME/bin/passtest

snmpget/snmpwalk utility allows to check manually what and where. I.e. to verify you can really get what you want if any.
After snmpget results make you happy you can proceed further with conky itself...
I suggest this way.
BTW, there are a lot stuff in /etc/snmp/snmpd.conf
It worths to read and there are good and ready-to-use examples in that config file
but you have to read about SNMP first. Otherwise some things look Greek.:)

And as always, YMMV.
Cheers!

Richard Cranium 03-15-2013 12:31 AM

Quote:

Originally Posted by mumpster (Post 4911910)
Hm. I has not dealt with conky but IMHO usually it is much more easier just to poll Linux servers through special scripts rather than trying to grok and to figure out "Simple" management protocol. Frankly, it is simpler when compares with TNM, ha-ha-ha :).

Nevertheless...I'm sure almost anyone can cope with SNMP.
So you just need:
1) to choose (if there is something suitable) or to make youself a script for SNMPd giving correct results depending on requested OID.
2) to tell conky which OID to use. That's the main problem because there are too many OIDs.:-|
Though to give you a common idea about SNMP usage I put here my simple handler for SNMPd:

#!/bin/sh -f
#Give used real memory

PLACE=".1.3.6.1.4.1.2021.4.55"
REQ="$2"

case "$REQ" in
$PLACE.0) RET=$PLACE.0 ;;
*) exit 0 ;;
esac
case "$RET" in
$PLACE.0) echo "integer"; \
# total=`snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.4.5.0 | cut -d\ -f4`; \
# avail=`snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.4.6.0 | cut -d\ -f4`; \
#/usr/bin/free | /usr/bin/awk '{if (FNR==2) print $3}';;
/usr/bin/vmstat | /usr/bin/awk '{if (NR==3) print $4}'; exit 0;;
*) echo "string"; echo "ack... $RET $REQ"; exit 0 ;;
esac

I also have in my snmpd.conf this line:

pass .1.3.6.1.4.1.2021.4.55.0 /bin/sh /MY-SWEETHOME/bin/passtest

snmpget/snmpwalk utility allows to check manually what and where. I.e. to verify you can really get what you want if any.
After snmpget results make you happy you can proceed further with conky itself...
I suggest this way.
BTW, there are a lot stuff in /etc/snmp/snmpd.conf
It worths to read and there are good and ready-to-use examples in that config file
but you have to read about SNMP first. Otherwise some things look Greek.:)

And as always, YMMV.
Cheers!

Heh. TMN documents are like peanuts: you can't read just one.
For those who haven't had to read TMN docs, the people who write them never duplicate information. They just refer to other documents. It's like unraveling a ball of string.
In fact, the OP would have to read /etc/snmp/snmpd.conf since the Slackware default values don't allow access to any OIDs that are useful. If the OP wants to do this to learn about SNMP (which is not a bad idea if you work in IT or telecom), then it's not a bad exercise. In that case, you should bookmark the MIB depot. Slackware comes with tkmib, which allows you to use a GUI to examine what an SNMP agent has in it. (There's some Perl dependencies that you'll have to resolve to get it to work.)

Habitual 03-17-2013 06:53 PM

Code:

${execpi 60 snmpwalk -v 2c -c public <host> .1.3.6.1.4.1.2021.4.55}
for example. :)

other usual conky data ("top 5" etc...) could best be utilized via key-based ssh commands such as top.
It will take quite a bit of scripting, both in ConkyRCs and or .sh scripts proper.


All times are GMT -5. The time now is 06:29 AM.