View Full Version : zabbix_mpstat.pl
rayslinky
13-03-2005, 22:25
i've setup the following mpstat readings on a couple of machines and am using zabbix_sender to send them to my zabbix server:
mpstat_user[cpu_num]
mpstat_system[cpu_num]
mpstat_iowait[cpu_num]
mpstat_busy[cpu_num]
i haven't looked into it, but this works great when i start it from the command line, but when i start it from a cron job, zabbix_sender is never called...
EDIT: removed code -- fresher version attached in this thread.
lbergman
20-03-2005, 06:21
When you look into let us know how you fixed it.
Permissions and path are to big reason that cron jobs fail when they work for you in a live session. What are the environemnt variables that are differetn for cron than for you?
rayslinky
21-03-2005, 19:09
it turned out to be an issue with bash. when i start it with tcsh from cron, it works great. i've rewritten this quite a bit, expanding it to deal with iostat and vmstat, as well. once i get it cleaned up a bit, i'll repost it.
cheers
rayslinky
26-03-2005, 19:01
hope someone else finds this useful...
i've rewritten this to work with iostat, vmstat, and mpstat on linux (tested with suse 9.2 and redhat enterprise 3), solaris (tested with solairs 8), and aix (briefly tested with aix 5.2). it now contacts the zabbix server directly, instead of using zabbix_sender via Socket. it is necessary to set the environment variable PERLIO=perlio, to avoid a memory leak in some versions of Socket.
create symbollic links to zabbix_mpstat zabbix_iostat and zabbix_vmstat, it will figure out the rest.
i also added code for generating mysql insert statements to make the process of installing easier -- since number of cpus, what you want monitored, and i/o media and configuration varies widely.
and when starting it from cron, use csh or tcsh -- sh/bash doesn't work.
I am looking to get this type of data out of my Sun boxes.
How do I use this?
rayslinky
27-04-2005, 23:04
its a pretty straight forward perl script. create symbloic links to it (it runs and parses mpstat, vmstat, or iostat based on how it is called) as zabbix_mpstat.pl, zabbix_vmstat.pl, zabbix_iostat.pl. you'll need to verify the paths to your vmstat/iostat/mpstat/ps/grep/uname binaries and edit the $Z_SERV variable (changing it to the ip or your zabbix server). if you are using 1.1alpha, you will also have to change the $Z_PORT variable.
look at your zabbix site and itentify the host id# (like 10001). if you run
zabbix_mpstat.pl -i host_id -a this_ip_address -u seconds_update_int -d history_days
ex: zabbix_mpstat.pl -i 10001 -a 192.168.1.1 -u 60 -d 30
it will generate mysql insert statements to bulk upload the new items, once you have the new items in your database, you can start the appropriate zabbix_xxstat.pl and it will send updates to your zabbix_trapperd every 60 seconds.
if you set it to start from a cron job (as in
"0 0 * * * PERLIO=perlio /bin/csh -c /usr/local/bin/zabbix_mpstat.pl > /dev/null"), you should be all set -- this will restart it once daily, incase something goes wrong in the meantime.
illumin8
01-02-2007, 18:17
its a pretty straight forward perl script.You're absolutely brilliant, and I think you've understated your perl skills a bit. :)
These scripts have saved me countless hours manually adding items to Zabbix for all of my Oracle servers. Thank you thank you thank you!
its a pretty straight forward perl script. create symbloic links to it (it runs and parses mpstat, vmstat, or iostat based on how it is called) as zabbix_mpstat.pl, zabbix_vmstat.pl, zabbix_iostat.pl. you'll need to verify the paths to your vmstat/iostat/mpstat/ps/grep/uname binaries and edit the $Z_SERV variable (changing it to the ip or your zabbix server). if you are using 1.1alpha, you will also have to change the $Z_PORT variable.
look at your zabbix site and itentify the host id# (like 10001). if you run
zabbix_mpstat.pl -i host_id -a this_ip_address -u seconds_update_int -d history_days
ex: zabbix_mpstat.pl -i 10001 -a 192.168.1.1 -u 60 -d 30
it will generate mysql insert statements to bulk upload the new items, once you have the new items in your database, you can start the appropriate zabbix_xxstat.pl and it will send updates to your zabbix_trapperd every 60 seconds.
if you set it to start from a cron job (as in
"0 0 * * * PERLIO=perlio /bin/csh -c /usr/local/bin/zabbix_mpstat.pl > /dev/null"), you should be all set -- this will restart it once daily, incase something goes wrong in the meantime.
Hello there! I am interested in running your script but I am not understanding a couple of items (or it doesn't work on 1.3.2). So when you say ./zabbix_mpstat.pl -i 10001 -a 192.168.1.1 -u 60 -d 30 what is the -i parameter, the port that zabbix server is listening on? If not then what exactly is the zabbix server-id and where do I get this info? I am testing your script on the zabbix server itself, so I modified the zabbix_stat.pl per your instructions:
$Z_SERV = "127.0.0.1"; # zabbix server to send to
$Z_PORT = "10051"; # which port to send on
I then run:
./zabbix_stat.pl -i 10051 -a 127.0.0.1 -u 60 -d 30
I get the following error:
something went wrong
uname=Linux
how_called=
statcmd=
search=
Also if/when I do get the SQL statements to generate, does it actually do the insert or will I need to execute this via mysq? (either way is fine, just want to know what to expect :)) Am I missing something? Sorry if I am being dense, I am rather new to zabbix.
rayslinky
02-02-2007, 17:19
Hello there! I am interested in running your script but I am not understanding a couple of items (or it doesn't work on 1.3.2). So when you say ./zabbix_mpstat.pl -i 10001 -a 192.168.1.1 -u 60 -d 30 what is the -i parameter, the port that zabbix server is listening on? If not then what exactly is the zabbix server-id and where do I get this info? I am testing your script on the zabbix server itself, so I modified the zabbix_stat.pl per your instructions:
$Z_SERV = "127.0.0.1"; # zabbix server to send to
$Z_PORT = "10051"; # which port to send on
I then run:
./zabbix_stat.pl -i 10051 -a 127.0.0.1 -u 60 -d 30
I get the following error:
something went wrong
uname=Linux
how_called=
statcmd=
search=
Also if/when I do get the SQL statements to generate, does it actually do the insert or will I need to execute this via mysq? (either way is fine, just want to know what to expect :)) Am I missing something? Sorry if I am being dense, I am rather new to zabbix.
You need to make sym links to zabbix_stat.pl (for zabbix_mpstat.pl, zabbix_iostat.pl, and zabbix_vmstat.pl), then call each of these sym links as in:
./zabbix_iostat.pl -i 10051 -a 127.0.0.1 -u 60 -d 30
This will generate the insert statements, you will have to manually run this output against mysql.
I haven't played with this since 1.1, so I'm not sure that everything still works.
Ok, now I get it, I can generate the MySQL statements. I wanted to actually get everyone's opinion on moving forward with this script in it's present state or modify it to work within the zabbix agent framework. I think your wrapper script gets great info, far better than the built in capability of the current 1.3.2 agent (also I tend to believe this info is going to be reliable since it is using well known unix utils), however since the agent is already running on the box I am not sure I want another resident process on the box. What was the idea behind using trapper? Would it be a relatively simple matter to use UserParameters on the agent to run the script and get the values? With this approach I would setup templates on the server rather than do manual inserts into the database, however I am willing to go either way depending on what is best. What were the use and design considerations when you created this script to begin with?
Opinions anyone? Thanks!
/Christian
Ok, I took the plunge on the current configuation, did the insert statements for zabbix_mpstat, zabbix_iostat, and zabbix_vmstat. All the entries now appear in the Zabbix server for the correct host, I am assuming I needed to run the perl script resident in memory as:
/usr/lib/zabbix/zabbix_mpstat.pl &
/usr/lib/zabbix/zabbix_iostat.pl &
/usr/lib/zabbix/zabbix_vmstat.pl &
So there are three processes running, one for each symlink. Is this correct? If so I am not getting updates :( I did edit the script to send on port 10051 which is the value of ListenPort=10051 in the /etc/zabbix/zabbix_server.conf. Any ideas?
Thanks!