Getting CPU info from Linux box via SNMP

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
gilson
Posts: 27
Joined: Wed Jan 23, 2002 7:00 pm
Contact:

Getting CPU info from Linux box via SNMP

Post by gilson »

First of all, create this script in <path_cacti>/scripts/get_snmp_cpu_info_linux.sh

Code: Select all

#!/bin/sh
  ssCpuRawUser=`$1 -Ont $2 $3 .1.3.6.1.4.1.2021.11.50.0|cut -d" " -f4`
  ssCpuRawNice=`$1 -Ont $2 $3 .1.3.6.1.4.1.2021.11.51.0|cut -d" " -f4`
ssCpuRawSystem=`$1 -Ont $2 $3 .1.3.6.1.4.1.2021.11.52.0|cut -d" " -f4`
  ssCpuRawIdle=`$1 -Ont $2 $3 .1.3.6.1.4.1.2021.11.53.0|cut -d" " -f4`

echo $ssCpuRawUser $ssCpuRawNice $ssCpuRawSystem $ssCpuRawIdle
Create a Data Input:
Name:

Code: Select all

Get SNMP CPU Info Linux
Input String:

Code: Select all

<path_cacti>/scripts/get_snmp_cpu_info_linux.sh <path_snmpget> <ip> <community>
Output String:

Code: Select all

<user> <nice> <sys> <idle>
In "Current Data Input Source Fields" create the parameters (except <path_snmpget> that is automatically replaced by the value in "Cacti Settings"):

Code: Select all

Type the Linux IP        / ip        / input / not update RRA
Type the Linux community / community / input / not update RRA

User / user / output / update RRA
Nice / nice / output / update RRA
Sys  / sys  / output / update RRA
Idle / idle / output / update RRA
NOTE: the last four must be entered in this order.

Create the Data Source as usual (using "Get SNMP CPU Info Linux" as Data Input Type). Notice: these values are COUNTERS, not GAUGE (although it's a CPU information). So the "Minimum Value" MUST BE set to "4294967296" or higher (Counter32 data type)

Don't forget to click in "Edit Data" and input the IP and COMMUNITY.

Feel free to create the Graph using these values.
My Graph is like this:

Code: Select all

Graph Item Data Source Name               Graph Item Type  Item Color
Item #1    peg_lnx_cpu_sys                AREA             562B29
-Item #2   peg_lnx_cpu_sys:  Current:     GPRINT
-Item #3   peg_lnx_cpu_sys:  Average:<HR> GPRINT
Item #4    peg_lnx_cpu_user               STACK            4444FF
-Item #5   peg_lnx_cpu_user: Current:     GPRINT
-Item #6   peg_lnx_cpu_user: Average:<HR> GPRINT
Item #7    peg_lnx_cpu_nice               STACK            CCBB00
-Item #8   peg_lnx_cpu_nice: Current:     GPRINT
-Item #9   peg_lnx_cpu_nice: Average:<HR> GPRINT
Item #10   peg_lnx_cpu_idle               STACK            CDCFC4
-Item #11  peg_lnx_cpu_idle: Current:     GPRINT
-Item #12  peg_lnx_cpu_idle: Average:<HR> GPRINT
-Gilson
Last edited by gilson on Tue Oct 01, 2002 12:19 pm, edited 1 time in total.
bbice
Cacti User
Posts: 71
Joined: Mon May 13, 2002 6:53 pm

getting CPU stats from linux or other unixes

Post by bbice »

Using the script posted here (or other similar scripts) works ok. Another option I
prefer is to compile ucd-snmp/net-snmp with the host mib enabled. Then I can get
cacti to just monitor a handful of MIBs for various CPU stats like User CPU, System
CPU, IO Wait CPU, and Idle CPU. They make a nice looking graph if you stack all of
'em except for idle and graph idle as a LINE1. :-)

See the net-snmp MIB file for details on what the OIDs to use are -- it's a standard
part of mib2, but, sorry, I don't have all the OIDs memorized. :wink:

If you must use scripts, you can also use commands like vmstat on Solaris to get
similar stats. I used to use a script called vmfind to get these stats:

#!/bin/sh
bobo=`vmstat -s |egrep "$1" | awk '{print $1}'`
echo "$bobo\c"

I'd run the script like this:
vmfind user
vmfind system
vmfind idle
vmfind wait
vmfind "page ins"
vmfind "page outs"

etc...

You can also hook these into the extensible part of ucd-snmp/net-snmp if you'd
prefer (this is how I did it before I compiled in the host mib) using the "exec" commands
in the snmpd.conf file.
bocasman
Posts: 24
Joined: Mon Aug 19, 2002 8:27 am
Location: Panama
Contact:

Post by bocasman »

Hi Gilson,

I am trying to setup this script, but you said that I have to set this:

Code: Select all

User / user / output / update RRA 
Nice / nice / output / update RRA 
Sys  / sys  / output / update RRA 
Idle / idle / output / update RRA
In this same order, but when I set them they arrenge them self in alphabetic order and I was wondering if is this a problem?

Please advise,
Regards,
BM
bbice
Cacti User
Posts: 71
Joined: Mon May 13, 2002 6:53 pm

Scripts and Other Addons for cacti

Post by bbice »

Well, I think you mis-understood how I used the scripts. I didn't call vmfind from
cacti. I just used cacti to monitor a specific OID on the unix machine. On that UNIX
machine I was running net-snmp. IT was configured to call the vmfind shell script.

Actually, I have an article coming out in the November issue of SysAdmin Magazine
about net-snmp and how to configure it. If you watch for it, you could use it to see how
to compile/install/configure net-snmp so you can monitor ANYTHING via snmp. For
instance, on my SMTP gateway machine, I can monitor the number of email messages
sent or received and the number of SPAM messages blocked because it runs net-snmp
and net-snmp is configured to run shell-scripts that return these values upon demand.
Then when I configure cacti, I just tell cacti to monitor the specific OID I've defined for
each of these variables...

'Hope this helps...
dbenders
Posts: 28
Joined: Mon Oct 14, 2002 2:02 pm
Location: Santiago, CHILE

Getting duplicated parameters in the RRD comand

Post by dbenders »

Hi Guilson, I follow your great post and I did it 3 times, and get the same problems. I guess that there is somthing wrong.

After I create the Data Source, it looks fine:

..../cacti/rra/app1_cpu.rrd --template user:nice:sys:idle N:U:U:U:U

Until here it looks fine!

After 5 minutes, I get :

..../cacti/rra/app1_cpu.rrd --template user:nice:nice:sys:sys:idle:idle N:5331893:U:254:U:2388262:U:82071859

As you can see, for some strange reason I get duplicated "nice", "sys" and "idle" DS.

I did it 3 times and each time I get a diferent result, but in all of them at least one DS is duplicated so I cannot get a graph.

Any idea in what is going bad?

Also, i tried with your "MUST" minimum value, but what is the max value? can you post here the code of the RRD please? so It will be easier to check what I'm doing wrong.

Thanks!
BSDeality
Posts: 35
Joined: Tue Oct 08, 2002 7:56 am
Location: Connecticut
Contact:

Re: Getting duplicated parameters in the RRD comand

Post by BSDeality »

dbenders wrote: Any idea in what is going bad?
Try manually deleting the .rra file for the snmp stuff, and then regenerate it.
[url=http://geekfort.com/cacti/graph_view.php?action=tree]Geekfort.com/cacti[/url]
gilson
Posts: 27
Joined: Wed Jan 23, 2002 7:00 pm
Contact:

Post by gilson »

bocasman wrote:Hi Gilson,

I am trying to setup this script, but you said that I have to set this:

Code: Select all

User / user / output / update RRA 
Nice / nice / output / update RRA 
Sys  / sys  / output / update RRA 
Idle / idle / output / update RRA
In this same order, but when I set them they arrenge them self in alphabetic order and I was wondering if is this a problem?

Please advise,
Bocasman,
Just create then in this order. Afterwards, will be shown in alphabetic order. See Rax reply for this topic: http://www.raxnet.net/board/viewtopic.php?t=623.
bocasman
Posts: 24
Joined: Mon Aug 19, 2002 8:27 am
Location: Panama
Contact:

Post by bocasman »

Thanks for your answer Gilson,

I did it in the specific order an every thing is working pretty well.

I would also point an strange issue that I have pass through, when I was trying to plot CPU stats for a dual processesor server the values that I was getting were greater than 100, thus something should be wrong. So seeking in the web I got this:

http://library.n0i.net/linux-unix/faq/u ... d_average_

Any way, I noticed that the sum off all the values was really close to 200 (199.75 more or less) so what I did was create a CDEF function that divide all individuals values by two (2), and I have verified those values executing the

Code: Select all

top
command on the multiprocessors server, and they were accurate.

Thanks again.
Regards,
BM
BSDeality
Posts: 35
Joined: Tue Oct 08, 2002 7:56 am
Location: Connecticut
Contact:

Post by BSDeality »

well, i tried the above script... and i've got a really interesting result.....

Image

also, does anyone have any scripts made up that i could use for monitoring CPU usage (that has a little better looking graph than above), memory, disk, load, uptime or any other neat graphable stuff from a linux box?
[url=http://geekfort.com/cacti/graph_view.php?action=tree]Geekfort.com/cacti[/url]
bocasman
Posts: 24
Joined: Mon Aug 19, 2002 8:27 am
Location: Panama
Contact:

Post by bocasman »

Hi dbenders,

I think you have made a mistake in the type of data. Remember its a counter32 data type.
Regards,
BM
LiquidKernel
Posts: 8
Joined: Fri Sep 20, 2002 11:18 am
Location: San Francisco, CA
Contact:

Re: Getting CPU info from Linux box via SNMP

Post by LiquidKernel »

gilson wrote: Create the Data Source as usual (using "Get SNMP CPU Info Linux" as Data Input Type). Notice: these values are COUNTERS, not GAUGE (although it's a CPU information). So the "Minimum Value" MUST BE set to "4294967296" or higher (Counter32 data type)
Gilson,

Whenever I try to put "4294967296" into the "Minimum Value" field, it turns to "8388607" after I save changes and view it again.

And yes, the data source type is set to COUNTER.

Running this:

Code: Select all

/usr/local/rrdtool/bin/rrdtool create \
/web/stats.gfxcafe.com/cacti/rra/vcrouter_system_cpu.rrd \
--step 300 \
DS:user:COUNTER:600:8388607:1 \
DS:nice:COUNTER:600:8388607:1 \
DS:sys:COUNTER:600:8388607:1 \
DS:idle:COUNTER:600:8388607:1 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
Gives me this:

Code: Select all

ERROR: min must be less than max in DS definition
Thanks for any help.
.: Serge
http://sergio.gfxcafe.com
User avatar
bulek
Cacti Pro User
Posts: 854
Joined: Mon May 20, 2002 2:07 am
Location: Poland
Contact:

Post by bulek »

This is a mistake I guess. For COUNTER you set the limits for change rate... not for current value. This means in case of CPU usage 0 as minimum and 100 as maximum should be a right choice.
And setting minimum above maximum is a mistake for sure.

- bulek
LiquidKernel
Posts: 8
Joined: Fri Sep 20, 2002 11:18 am
Location: San Francisco, CA
Contact:

Post by LiquidKernel »

Thanks! It works fine now.
.: Serge
http://sergio.gfxcafe.com
jasonb885
Posts: 8
Joined: Mon Jul 14, 2003 12:37 pm

And it was so

Post by jasonb885 »

http://www.samag.com/articles/2002/0211/

He wasn't kidding. It's a shame the only way to gain access to that insight is to buy a back issue.
b0fh
Posts: 32
Joined: Fri Jul 18, 2003 3:46 am

Post by b0fh »

Did any of you get this to work on cacti 0.8? Some fields are different there and I can't set this up :( Or is there a template for linux with ucd-snmp for getting cpu info? DIdn't find anything :(
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests