Memory graphing / Mac OSX /script and template

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Memory graphing / Mac OSX /script and template

Post by tamias »

I have Linux /mac osx memory script base on vm_stat (Mac OSX) and cat /proc/meminfo (Linux) commands.

Code: Select all

#!/usr/bin/perl
$page = 4096;
open(PROC, '/proc/meminfo') || open(PROC, '/usr/bin/vm_stat |') || die "$!";
while (<PROC>) {
    $page = $1 if /page\s+size\s+of\s+(\d+)\s+bytes/;
    print $1*$page,"\n" and exit 0 if (/^$ARGV[0]\:\s+(\d+)/i);
}
close(PROC);
Here's an example in Mac OSX:

Code: Select all

$ nix_memory.pl 'Pages free'
568799232
$ nix_memory.pl 'Pages inactive'
999067648
and etc. (‘Pages active' 'Pages inactive' 'Pages wired down' 'Translation faults' 'Pages copy-on-write' 'Pages zero filled' 'Pages reactivated' 'Pageins' 'Pageouts' )

That is how I try to use it for free + inactive mamory an example:
1 ) copy nix_memory.pl file to /cacti/scripts/ directory
2) Create two DataInputMethod

Image

and create second DataInputMethod , the same, only to change
Name -> |host_description| - Memory - inactive
Grep String -> 'Pages inactive'


3) Create Data Templates
Memory - free

Image


3) Create Graph Templates
Image

4) Create New Graph
New Graph -> Create: Mac_Linux - Memory Usage -> Create


but cacti graph is not displayed
Image


I am receiving the folling error:
12/03/2008 12:15:05 PM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[205] Graphs['Localhost - Memory Usage'] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl , output: U
12/03/2008 12:15:05 PM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[205] Graphs['Localhost - Memory Usage'] WARNING: Result from CMD not valid. Partial Result:
12/03/2008 12:15:05 PM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[204] Graphs['Localhost - Memory Usage'] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl , output: U
12/03/2008 12:15:05 PM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[204] Graphs['Localhost - Memory Usage'] WARNING: Result from CMD not valid. Partial Result:
Please help me solve the problem!
Last edited by tamias on Mon Jan 12, 2009 8:59 pm, edited 1 time in total.
Regards, Michail A.
soloslinger
Posts: 32
Joined: Fri Jan 19, 2007 2:11 pm

Post by soloslinger »

Just a thought, try taking the new line character out of the script output.

soloslinger
plugin: 2.1
cacti: 0.8.7b
apache 2.0
php: 5.2.5
mysql: 5.1
os: freebsd 6.2
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Post by tamias »

soloslinger wrote:Just a thought, try taking the new line character out of the script output.

soloslinger
Thank you! I'm not sure that it helped but, nevertheless,
now I can not create more than 2 graphs with one Graph Template Item DS[238] , DS[239]
Others graphs remain in a state of NaNet

Image

This is sample log :

Code: Select all

12/04/2008 09:55:05 AM - SYSTEM STATS: Time:5.2647 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:42 RRDsProcessed:35
12/04/2008 09:55:05 AM - CMDPHP: Poller[0] Time: 4.8557 s, Theads: N/A, Hosts: 1
12/04/2008 09:55:05 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[238] Graphs['Localhost - Memory Usage Pageins'] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl 'Pageins', output: 372318208
12/04/2008 09:55:04 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[243] Graphs['Localhost - Memory Usage Wired '] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl , output: U
12/04/2008 09:55:04 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[243] Graphs['Localhost - Memory Usage Wired '] WARNING: Result from CMD not valid. Partial Result:
12/04/2008 09:55:04 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[242] Graphs['Localhost - Memory Usage Total '] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl , output: U
12/04/2008 09:55:04 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[242] Graphs['Localhost - Memory Usage Total '] WARNING: Result from CMD not valid. Partial Result:
12/04/2008 09:55:04 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[244] Graphs['Localhost - Memory Usage Free '] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl , output: U
12/04/2008 09:55:04 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[244] Graphs['Localhost - Memory Usage Free '] WARNING: Result from CMD not valid. Partial Result:
12/04/2008 09:55:03 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[239] Graphs['Localhost - Memory Usage Inactive '] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl 'Pages inactive', output: 265003008
12/04/2008 09:55:03 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[241] Graphs['Localhost - Memory Usage Total '] CMD: perl /opt/local/share/cacti/scripts/nix_memory.pl , output: U
12/04/2008 09:55:03 AM - CMDPHP: Poller[0] Host[1] Description[Localhost] DS[241] Graphs['Localhost - Memory Usage Total '] WARNING: Result from CMD not valid. Partial Result:

12/04/2008 09:55:00 AM - POLLER: Poller[0] WARNING: Poller[0] Host[1] Description[Localhost] Ping Time was not numeric
12/04/2008 09:55:00 AM - CMDPHP: Poller[0] WARNING: sockets support not enabled in PHP, falling back to SNMP ping
12/04/2008 09:55:00 AM - POLLER: Poller[0] NOTE: Poller Int: '300', Cron Int: '300', Time Since Last: '299', Max Runtime '298', Poller Runs: '1'
Any clue?
Regards, Michail A.
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Post by tamias »

I have built a second graph from the same "inactive" graph template and the new graph is empty (nan) . It the reason is the script code?
Regards, Michail A.
soloslinger
Posts: 32
Joined: Fri Jan 19, 2007 2:11 pm

Post by soloslinger »

tamias wrote: Thank you! I'm not sure that it helped but, nevertheless,
now I can not create more than 2 graphs with one Graph Template Item DS[238] , DS[239]
Others graphs remain in a state of NaNet
I am not sure I understand what you are trying to do. Are you trying to create multiple graphs of that script? Wouldn't you only need one graph for graphing memory usage on the localhost? Also another thing you might want to try is to change the output of the script from just spitting out a digit to outputting the field name as if you were outputing multiple values from the script.

To be honest, I haven't used and scripts in cacti that take inputs in order to run. That seems like an extra hoop to jump through when the script could be made to just output both numbers needed by cacti upon execution.


soloslinger
plugin: 2.1
cacti: 0.8.7b
apache 2.0
php: 5.2.5
mysql: 5.1
os: freebsd 6.2
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Post by tamias »

soloslinger wrote:you might want to try is to change the output of the script
If I understood you correctly, the script must be rebuilt so that the output of the script is all values in a single launch ?
Like the following:
<fieldname_1>:<value_1> <fieldname_2>:<value_2> ... <fieldname_n>:<value_n>
?
Regards, Michail A.
soloslinger
Posts: 32
Joined: Fri Jan 19, 2007 2:11 pm

Post by soloslinger »

:-D I believe we are on the same page. If I have read/retained the cacti docs correctly, if only one value is to be returned from the script, the fieldname isn't required. However, cacti still works with the script if you define the field name.

I am not sure that this will solve your problem, but I know cacti can be fickle about the way that information comes out of your scripts ( for instance, the newline character ). Of the handful of scripts I have running on my cacti install, I have definited the fieldname in the output regardless of the number of fields I output.

You could also "tail -f <cacti root directory>/log/cacti.log | grep <your script name>" and see what the cacti log says it's getting from the script.

Also, if you could answer a few of the other questions I asked, it might help me help you.

Lastly, I am not nearly as skilled as the other folk around these forums when it comes to cacti; it is quite possible I am full of, ... well you get the idea.

soloslinger
plugin: 2.1
cacti: 0.8.7b
apache 2.0
php: 5.2.5
mysql: 5.1
os: freebsd 6.2
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Post by tamias »

soloslinger wrote:

Now I try himself and ask others to help write a script that uses $ vm_stat, like this:

$perl script.pl
Pages free:248491 Pages active: 345632 Pages inactive: 306207 Pages wired down:146885 "Translation faults": 598998500 Pages copy-on-write:42312589 Pages zero filled: 64106 Pages reactivated:64106 Pageins: 243273 Pageouts: 84934 Object cache:15930737

I would like to use it in cacti graph:
Image

It is built using 4 scripts (that is an above) , but it is expensive.

I need a single script and if someone will write it, I try to use it and it will be the best way to explore the cacti.


Thank you!
Regards, Michail A.
renef
Posts: 5
Joined: Tue Jan 30, 2007 11:42 am

linux_memory.pl for non-linux servers

Post by renef »

Okay! So my post is not *quite*, but almost on the same topic.

I'm running cacti on a Solaris 10 server and that linux_memory.pl file is making me nutty. From all of the Googling and searching through the cacti forums, this thread has come the closest to helping me. Now I at least understand what and where the script is getting called and what for. I just need to alter it to return the two values I need:

Code: Select all

vmstat | tail -1 | awk '{print $4" "$5}'
2268708 552928
That's what I think I need. The question is how to do it. I will look at the scripts in this thread and get back with a result.
khufure
Cacti User
Posts: 203
Joined: Wed Oct 24, 2007 5:47 pm
Location: San Francisco, CA
Contact:

Post by khufure »

soloslinger wrote:It is built using 4 scripts (that is an above) , but it is expensive.
SNMP would be much more efficient but perhaps not exactly what you want:
Linux - ucd/net - Memory Usage
Windows 2003 - Memory Statistics

Not to mention, it is really easy in Cacti. Add those to your host template and create a host using the template. You will also need to configure SNMPd.

A good start:

Code: Select all

1) ucd/net - CPU Usage  	 Delete
2) ucd/net - Load Average 	Delete
3) ucd/net - Memory Usage 	Delete
4) TCP Active/Passive Connection Stats 	Delete
5) TCP Connection Attempt Failed Stats 	Delete
6) TCP Current Established Stats 	Delete
7) TCP Established Reset Stats 	Delete
8) TCP Segment Stats 	Delete

Associated Data Queries
1) SNMP - Disk Statistics 	Delete
2) SNMP - Interface Statistics 	Delete
3) ucd/net - Get Monitored Partitions 

Code: Select all

1) Windows 2003 - Cache Statistics  	 Delete
2) Windows 2003 - CPU Statistics 	Delete
3) Windows 2003 - Disk Statistics 	Delete
4) Windows 2003 - Disk Statistics 2 	Delete
5) Windows 2003 - Memory Statistics 	Delete
6) Windows 2003 - Page Memory Statistics 	Delete
7) Windows 2003 - Process Statistics 	Delete
8) Windows 2003 - Process Statistics 2 	Delete
9) Windows 2003 - TCP Connections 	Delete
10) Windows 2003 - Thread Statistics

Associated Data Queries
1) SNMP - Get Mounted Partitions 	Delete
2) SNMP - Interface Statistics 
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Post by tamias »

I wrote a NEW script that displays all the values of the memory of my system
My vm_stat command displays the following:

Code: Select all

$ vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                   319884.
Pages active:                 323012.
Pages inactive:               241247.
Pages wired down:             163275.
"Translation faults":      172380874.
Pages copy-on-write:         4789497.
Pages zero filled:          94112959.
Pages reactivated:            290389.
Pageins:                      644365.
Pageouts:                     382208.
Object cache: 1419680 hits of 1595025 lookups (89% hit rate)

This is my script:

Code: Select all

#!/bin/sh
vm_stat | perl -ne 's/\s/_/g; $ps = $1 if (/page.size.*?(\d+)/); print "$1:".$3*$ps." " if(/^\W*(.+?)\W*:(\s|_)*(\d+).*$/);'
And this is the result message after running the script :

Code: Select all

$ vm_stat | perl -ne 's/\s/_/g; $ps = $1 if (/page.size.*?(\d+)/); print "$1:".$3*$ps." " if(/^\W*(.+?)\W*:(\s|_)*(\d+).*$/);'
Pages_free:1318334464 Pages_active:1317085184 Pages_inactive:987983872 Pages_wired_down:666238976 Translation_faults:708042547200 Pages_copy-on-write:19690225664 Pages_zero_filled:386373156864 Pages_reactivated:1189437440 Pageins:2639544320 Pageouts:1565523968 Object_cache:5833719808 
Attachments
cacti_graph_template_memory_mac_osx_gt.xml
This is graph template that above.
After the import template, you can change the graph and add more memory options.
(20.71 KiB) Downloaded 338 times
memory_mac.sh.zip
The script which displays all the values of memory on my computer, it may need to be adjusted individually for different unix systems.
(394 Bytes) Downloaded 279 times
Regards, Michail A.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Would you please mind posting this to the scripts and templates forum. At least, it's supposed to get more search hits there :wink:
Reinhard
tamias
Posts: 49
Joined: Thu Oct 16, 2008 7:12 am

Post by tamias »

gandalf wrote:Would you please mind posting this to the scripts and templates forum. At least, it's supposed to get more search hits there :wink:
Reinhard
I will do it soon.
Regards, Michail A.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest