Ad Widget

Collapse

zabbix and many values.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zeds
    Junior Member
    Zabbix Certified Specialist
    • Jan 2009
    • 20

    #1

    zabbix and many values.

    I am the one who uses zabbix both as a monitoring tool and performance data gathering tool. Some of useful data is CPU load and io data.
    See in the end of post you can see how I currently do monitoring of CPU data. I wrote a script which gets data, script which gets data for agent and then templates in zabbix server.
    It worked quite OK.

    But few days earlier I received SUN T3 dual procesoors server - it has 255 virtual CPUs(threads). mpstat output attached in the end. And I cannot force myself to make a new template with 255x15 items in it . There should be a better ways how to deal with such data. I thought that I could automate it by writing PHP script, but could not find database structure for 1.8.4 database.
    Is it possible to write custom agent and feed a multiple data items at once ?
    May be you have ideas how to gather performance data by not making any item by hand ?
    The same applies to iodata to - when i have a few volumes attached to a server, it is ok to enter them one by one. But when I have do create 4 items for 64 volumes - it is becoming quite an annoing job.


    This is how I do things now:
    * * * * * /opt/zabbix/bin/mpstat_stat.bash 2>&1 >/dev/null

    /etc/zabbix.conf
    UserParameter=solaris.mcpu[*],/opt/zabbix/bin/grep_mpstat.pl $1 $2

    This scripts gets mpstat data
    Script may seem wird , but locking and copying is meant to protect us from
    "item is not supported" when zabbix agent reads file in a moment it is being written to.
    Code:
    #!/bin/bash
    # Script dumps solaris CPU data via mpstat to a file
    # works on Solaris
    NUMCPU=`/usr/sbin/psrinfo|wc -l|awk '{ print  $1 }'`;export NUMCPU
    LOCK=/var/tmp/mpstat.lck
    /usr/bin/mpstat 1 5|/usr/bin/tail -$NUMCPU  >/var/tmp/mpstat.txt.1
    chown zabbix:zabbix /var/tmp/mpstat.txt.1
    /bin/touch $LOCK
    /bin/touch /var/tmp/mpstat.txt
    chown zabbix:zabbix /var/tmp/mpstat.txt
    cat /var/tmp/mpstat.txt.1 >/var/tmp/mpstat.txt 
    /bin/rm -f $LOCK
    and

    This scripts read from previosly saved file. It provide better speed and efficiency.
    Code:
    #!/usr/bin/perl
    #script greps /tmp/mpstat.txt file for changes
    #it is designed to get load on individual CPU and cores
    #for zabbix 
    # script takes two parameters  core number and stat type
    
    use warnings;
    #use strict;
    sub print_usage;
    
    my $statfile='/var/tmp/mpstat.txt';
    my $lockfile='/var/tmp/mpstat.lck';
    
    #if DBGFLAG file exists , then diagnostic debug output is written to $dbgfile
    $DBGFLAG='/etc/zabbix/debug_grep_mpstat';
    my $dbgfile='/var/log/zabbix/grep_mpstat_debug.log';
    
    if($#ARGV!=1) 
     {
     print_usage();
     exit(-1);
     }
    
    $DBG=0;
    if( -f $DBGFLAG ) { $DBG=1 };
    
    my $core=shift;
    my $stattype=shift;
    my $stat_idx;
    
    
    if( ! ( $core =~ /^[0-9]+$/ ))
     {
     print "invalid core number!\n";
     print_usage();
     exit(-2);
     }
    
    my @stat_types=qw/minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl/;
    my $bmatch=0;
    my $stat_len=@stat_types;
    my $i;
    for($i=0;$i<$stat_len;$i++)
     {
     if($stat_types[$i] eq $stattype) 
       {
       $bmatch=1;
       $stat_idx=$i;
       }
     }
    
    if($bmatch==0)
     {
     print "invalid stat type!\n";
     print_usage();
     exit(-3);
     }
    
    my $nothing;
    while( -f "$lockfile" )
     {
     $nothing++;
     }
    
    $result="";
    open FH,"<",$statfile or die "cannot open input file $statfile\n";
    if( $DBG ) { open LOG,">>",$dbgfile or die "cannot open debug file $dbgfile"; };
    while($line=readline(FH))
     {
     if( $DBG ) 
       {
       print LOG  "READ: $line\n";
       }
     $_=$line;
     s/^\s+//;
     s/\s+$//;
     $line=$_;
     
     my @sp=split(/\s+/,$line);
     if( $DBG )  
       {
       print LOG "SP array:";
       $i=0;
       foreach(@sp) 
         {
         print LOG "$i:$_  ";
         $i++;
         }
       print LOG "\n";
       };
     if( $DBG )  { print LOG "core=$core sp[0]=$sp[0]\n"};
     if($sp[0] !~ /^[0-9]+$/) {
       next;
      }; 
     
     if($core==$sp[0])
      {
      $result=$sp[$stat_idx+1];
      if( $DBG ) 
        {
        print LOG  "MATCH: $line\n";
        print LOG  "RESULT: $result\n";
        }
      }
     }
    if ($DBG ) 
     { 
     close(DBG);
     }
    close FH;
    print "$result\n";
    
    #subroutines
    sub print_usage() {
    print <<EOF;
     script greps /tmp/mpstat.txt file for required stat data
     usage:
      grep_mpstat.pl corenum [minf|mjf|xcal|intr|ithr|csw|icsw|migr|smtx|srw|syscl|usr|sys|wt|idl]
      
      Debugging:
       if file  $DBGFLAG exists debugging information is written in logfile $dbgfile
    EOF
    }
    Attached mpstat output of dual T3. It quite interesting also - it shows solaris resource amanagement in action - CPU 128 -to 255 are assigned to a separate processor set , and solaris zone are allowed to use CPUs in this set only.
    Attached Files
Working...