Monitoring disk I/O using Zabbix

How to set up disk monitoring on Linux in Zabbix. The standard Linux template in Zabbix provides monitoring on the filling of your disks, but not too much about real utilisation. For example, it doesn’t tell you how many writes per second are being handled by a disk or partition.

However, this kind of information can be vital for the health of your servers. Disks are almost always a bottleneck, so I like to keep an eye on them.

The inspiration for this blogpost and some code is from Renaldo Maclons’ weblog.

Goal:

Monitor the utilisation of my disk devices in Linux servers. Being lazy as a sysadmin is always a good thing, so I’m going to implement low-level discovery of my disk devices and create a template to go with it.

We’ll be configuring the Zabbix agent which is running on my Linux boxes to support the low-level discovery of my disk devices, and the items we need to monitor on the host.

For the quick-starters:

1. Download the template.
2. Import the template in your Zabbix instance
3. Enable the low-level discovery script on the Zabbix agents
4. Enrich the Zabbix agent with these UserParameters
5. Add the template to a host and test

For the rest of you, please read on to understand how the template is made and what the scripts actually do.

Environment:

  • Zabbix Server/Agent version: 2.2.1
  • Linux version: RHEL5/6
  • Custom Zabbix scripts path: /opt/zabbix/
  • Custom UserParameter files: /etc/zabbix/zabbix_agentd.d/

Enabling auto-discovery of the devices:

I’ve created a small and simple Perl script to do the low-level discovery of the devices in a server. It can be found on GitHub.  On the linux servers where the Zabbix agent is running we need to download the script and tell the agent to use it:

 $ mkdir -p /opt/zabbix/linux
 $ cd /opt/zabbix/linux
 $ wget https://raw2.github.com/dkanbier/zabbix-linux/master/LLD/queryDisks.pl
 $ chmod +x queryDisks.pl
 $ chown -R zabbix:zabbix /opt/zabbix

The script is now in place. You can run it if you like, in short it will look in /proc/diskstats and filter out the device names. Then it prints them to the screen in JSON format, because Zabbix likes to talk in JSON:

./queryDisks.pl
{
 "data":[
  { "{#DISK}":"ram0" },
  { "{#DISK}":"ram1" },
  { "{#DISK}":"sda" },
  { "{#DISK}":"sda1" }
 ]
}

I shortened the output a bit to keep it readable, but you get the idea. We have a {#DISK} key with a value of the device name. Don’t worry about the fact that you probably see devices you don’t want to monitor, we will handle that soon but not here.

Let’s enable the Zabbix agent to support the auto discovery of disks. Open the zabbix_agentd.conf file:

$ vi /etc/zabbix/zabbix_agentd.conf

And add the following line to it:

UserParameter=custom.vfs.dev.discovery,/opt/zabbix/linux/queryDisks.pl

After editing the configuration we need to restart the agent:

$ sudo service zabbix-agent restart

Done!

The agent is now capable of discovering the disk devices. The first part (custom.vfs.dev.discovery) is the key that Zabbix can use for the discovery, the second part is the implementation of that key on the Linux server. Let’s notify the Zabbix Server about this by creating a new template and use the discovery rule.

Configure Zabbix to use the low-level discovery key custom.vfs.dev.discovery:

Start by creating a new template. I’ll be naming mine “Template Linux Disk IO”. Open the Zabbix web interface and go to Configuration -> Templates and click “Create template”.

Fill in a name and add the new template to the group “Templates”. Then click save.

Screen Shot 2014-01-31 at 15.52.07

Now you’re back in the Templates overview. In the row of the template we just created, click “Discovery” and then “Create discovery rule”.

Fill in:

Name: Disk device discovery
Key: custom.vfs.dev.discovery
Description: Discovery of disk devices on linux.

Screen Shot 2014-01-31 at 15.56.29

 

Now we still need to limit the types of devices we want to auto-discover. Remember the list that was presented when you ran the queryDisks.pl script? What if you only want to add the “sd” devices for example?

This is where filters and regexp rules come into play. I’ve written a post about how to use them, so I won’t cover it again in detail. I’ll just create a regexp that only matches “sd” devices and configure the discovery rule to use it:

Screen Shot 2014-01-31 at 16.01.50 Screen Shot 2014-01-31 at 16.02.32

 

Auto discovering of “sd” devices is now operational.

Please be aware that you have to enable the custom.vfs.dev.discovery key on every host you want to use it on by placing the queryDisks.pl script and modify the Zabbix agent configuration.

From discovery to items in Zabbix:

Now what good are discovery rules if they don’t make any items. Sure we can tell Zabbix we have a sda, sda1 and sdb device, but what is the point if we don’t monitor anything with it.

The file /proc/diskstats contains valuable information regarding your disk devices. The official documentation can be found here.

I’ve placed a UserParameter file containing logic for extracting this information on GitHub. If you place this file in the “Include” directory of the Zabbix agent on the hosts you want to monitor your disks on it will enable monitoring of this information using custom keys.

On the client linux boxes:

$ wget https://raw2.github.com/dkanbier/zabbix-linux/master/UserParameters/userparameter_linux_disks.conf
$ sudo mv userparameter_linux_disks.conf /etc/zabbix/zabbix_agentd.d/
$ sudo service zabbix-agent restart

Now the agent is capable of extracting data from /proc/diskstats and report it to Zabbix using the keys defined in  userparameter_linux_disks.conf.

Let’s create item prototypes so the items for this data are automatically created when low-level discovery is started. We need to create an item prototype for every custom key we’ve added using the user parameter_linux_disks.conf file ( 8 in total). I’ll show the process of creating 1, the rest is available by downloading the pre-configured custom template.

In the Zabbix interface click “Configuration -> Templates. In the row of our new template “Template Linux Disk IO” click Discovery ->  Item prototypes -> Create item prototype.

Fill in:

Name: Disk:{#DISK}:reads completed    <-- {#DISK} will be filled with a value by LLD
Key: custom.vfs.dev.read.ops[{#DISK}] <-- custom.vfs.dev.read.ops comes from userparameter_linux_disks.conf
Units: Reads
New Application: I/O Stats

Screen Shot 2014-01-31 at 16.37.40

Click Save.

If you deploy this template now on your Linux hosts it will auto-discover your disk devices, only add “sd” devices as host items and monitor the total completed reads on them:

Screen Shot 2014-01-31 at 16.54.08Making sense of it all:

If we take a closer look to the stats we’re using to be put in Zabbix, there is a way to make them even more valuable and easier to interpet.

I’d like to take a closer look to the following items:

UserParameter=custom.vfs.dev.read.ops[*] # reads completed successfullly
UserParameter=custom.vfs.dev.read.sectors[*] # sectors read
UserParameter=custom.vfs.dev.write.ops[*] # writes completed
UserParameter=custom.vfs.dev.write.sectors[*] # sectors written

The data from these items comes from /proc/diskstats, and the data in there is accumulative. For example, when a sector is written the number of write.sectors will go up by 1. So if we would put these values in Zabbix, we will just have an ever growing graph.

Sure this isn’t totally useless, you can still see trends in how fast (or slow) sectors are being written over time. But for me, far more interesting is the number of sectors written per second.

Luckily Zabbix comes with a builtin feature to calculate just that. While configuring an item, you can set it’s Store value to “Delta (speed per second)”.

This will evaluate the data as (valueprev_value)/(timeprev_time), where
value – current value
value_prev – previously received value
time – current timestamp
prev_time – timestamp of previous value

Using this option will give me the number of sectors written per second, instead of an accumulated value of all sectors ever written:

Screen Shot 2014-02-01 at 23.35.17

Completed template and setup:

If you’re interested, I’ve completed and exported the template I build in this post so you can set it up in your own environment. To do so:

1. Download the template.
2. Import the template in your Zabbix instance
3. Be sure to enable your Zabbix agents to do the auto discovery and custom keys (see post above)
4. Add the template to a host and test

As always, if you need any assistance please let me know ;-).

Happy monitoring!

 

33 thoughts on “Monitoring disk I/O using Zabbix

  1. Hey Dennis,

    I am proud to have been apart of the detailed post you made here. It certainly is something I wanted to get around to doing, but studies have been getting the best of me lately.

    I must say that I do appreciate the fact that you have written it in the volume that is here.

    Good luck, and thank you 🙂
    Renaldo.

  2. I’m recommending to parse /proc/partitions for discovery script. In this case you must filter only sr0.

    Also it will be excellent to show friendly name of partitions in item “display name”

    • Thanks for the feedback! I think you’re right about /proc/partitions.. the ram and loop devices are probably not of too much interest for anybody, but it’s possible to monitor them if you like.

      I’m not too sure what you mean by friendly names, maybe you can give an example?

  3. Great post!

    After importing the template xml there were no items or graphs associated with the template. Is this expected? Next step would be to create some custom graphs?

    • Thank you!

      The template is intended to be used in combination with the auto discovery script. The only things in the template are the auto discovery rule and item prototypes.

      So if you enable the auto discovery script on your clients and add these client hosts to my template in Zabbix, it will automatically discover disk devices on these clients and add items for them.

      Let me know if you need help 🙂

  4. Great Post!

    I’m on zabbix 2.2.2 (server and agent) , but it say that the item created by discovery rule are not supported from the agent.
    I’m trying to monitor the zabbix server disk i/o itself. any Idea?

    • Thank you!

      Are you sure the userparameter_linux_disks.conf file is picked up by the zabbix agent? This file contains the logic for the items, maybe you have to Include the directory manually in zabbix_agentd.conf.

      After placing userparameter_linux_disks.conf in /etc/zabbix/zabbix_agentd.d/ check for this line in zabbix_agentd.conf and if it’s missing add it:

      Include=/etc/zabbix/zabbix_agentd.d/

      If the file already is in place you could try to debug the zabbix agent (check the debug option in zabbix_agentd.conf and set it to DebugLevel=4) and see if the commands are actually executed or not. If they are failing for some reason you should see it there.

      Let me know if you could get it to work, if not I’ll be more than happy to help out!

  5. Sorry for my question… what is the difference with:


    # zabbix_agentd -V
    Zabbix Agent (daemon) v2.2.3 (revision 44105) (7 April 2014)
    Compilation time: Apr 8 2014 18:49:57

    # zabbix_agentd -t vfs.dev.write[,operations]
    vfs.dev.write[,operations] [u|833571555]
    # zabbix_agentd -t vfs.dev.read[,operations]
    vfs.dev.read[,operations] [u|1265275596]

    Or, by drive:


    # zabbix_agentd -t vfs.dev.write[/dev/sda,operations]
    vfs.dev.write[/dev/sda,operations] [u|58977406]
    # zabbix_agentd -t vfs.dev.write[/dev/sda,sectors]
    vfs.dev.write[/dev/sda,sectors] [u|1665554779]
    # zabbix_agentd -t vfs.dev.read[/dev/sda,operations]
    vfs.dev.read[/dev/sda,operations] [u|194753874]
    # zabbix_agentd -t vfs.dev.read[/dev/sda,sectors]
    vfs.dev.read[/dev/sda,sectors] [u|82136555896]

    The “discovery” part seems very useful but, with the other part, i don’t know if i understand what is the difference with default agent parameters.

    Thanks Dennis.

    • Hi Vicente, thank you for your comment. I think when I wrote the script I just took every bit of sensible information available to me from /proc/diskstats, as it provides more information than only read/write operations. I think you could just as well use the default items for dev.write and dev.read, provided they can handle the input given (i.e. “sda”) which I think they do.

  6. Hi,

    I was able to put the LLD to work very well.. Thank you ! But I am with a problem.. I Can’t use the Regexp @Disk devices for discovery ,
    I change it to…

    1 » xvdf1 [Result is TRUE]
    2 » ^(xvd.*)$ [Result is TRUE] —>>> Amazon Disk
    3 » ^(sd.*)$ [Result is TRUE]

    Not worked…

    Then I put xvdf1 in Regexp of the host … and worked !

    Any idea ?

  7. Hi,

    I installed your template and the scripts. But zabbix gives me an error:

    Value should be a JSON object.

    I am running zabbix 2.2.3 and the output of ./queryDisks.pl =

    {
    “data”:[

    {
    “{#DISK}”:”ram0″

    }
    ,
    {
    “{#DISK}”:”ram1″

    }
    ,
    {
    “{#DISK}”:”ram2″

    }
    ,
    {
    “{#DISK}”:”ram3″

    }
    ,
    {
    “{#DISK}”:”ram4″

    }

    etc…

    Vis

    • The resulting text is a JSON object. I verified by pasting the text into http://jsonlint.com.

      My text:

      {
      “data”: [
      {
      “{#DISK}”: “ram0”
      },
      {
      “{#DISK}”: “ram1”
      },
      {
      “{#DISK}”: “ram2”
      },
      {
      “{#DISK}”: “ram3”
      },
      {
      “{#DISK}”: “ram4”
      },
      {
      “{#DISK}”: “ram5”
      },
      {
      “{#DISK}”: “ram6”
      },
      {
      “{#DISK}”: “ram7”
      },
      {
      “{#DISK}”: “ram8”
      },
      {
      “{#DISK}”: “ram9”
      },
      {
      “{#DISK}”: “ram10”
      },
      {
      “{#DISK}”: “ram11”
      },
      {
      “{#DISK}”: “ram12”
      },
      {
      “{#DISK}”: “ram13”
      },
      {
      “{#DISK}”: “ram14”
      },
      {
      “{#DISK}”: “ram15”
      },
      {
      “{#DISK}”: “loop0”
      },
      {
      “{#DISK}”: “loop1”
      },
      {
      “{#DISK}”: “loop2”
      },
      {
      “{#DISK}”: “loop3”
      },
      {
      “{#DISK}”: “loop4”
      },
      {
      “{#DISK}”: “loop5”
      },
      {
      “{#DISK}”: “loop6”
      },
      {
      “{#DISK}”: “loop7”
      },
      {
      “{#DISK}”: “sr0”
      },
      {
      “{#DISK}”: “fd0”
      },
      {
      “{#DISK}”: “sda”
      },
      {
      “{#DISK}”: “sda1”
      },
      {
      “{#DISK}”: “sda2”
      },
      {
      “{#DISK}”: “sda5”
      }
      ]
      }

      • Hi, I encountered the similar thing. Strangely enough, the discovery script is okay on the “Zabbix server” host. But when I include other host, Zabbix shows “values should be json object”.

        I verified the resulting json from the perl script using jsonlint.com of both hosts (the Zabbix server and the problematic one), and jsonlint.com shows that both results are valid json.

        We’re running Zabbix 2.2.1 on Centos 6.
        Our resulting json:
        {
        “data”:[

        {
        “{#DISK}”:”ram0″

        }
        ,
        {
        “{#DISK}”:”ram1″

        }
        ,
        {
        “{#DISK}”:”ram2″

        }
        ,
        {
        “{#DISK}”:”ram3″

        }
        ,
        {
        “{#DISK}”:”ram4″

        }
        ,
        {
        “{#DISK}”:”ram5″

        }
        ,
        {
        “{#DISK}”:”ram6″

        }
        ,
        {
        “{#DISK}”:”ram7″

        }
        ,
        {
        “{#DISK}”:”ram8″

        }
        ,
        {
        “{#DISK}”:”ram9″

        }
        ,
        {
        “{#DISK}”:”ram10″

        }
        ,
        {
        “{#DISK}”:”ram11″

        }
        ,
        {
        “{#DISK}”:”ram12″

        }
        ,
        {
        “{#DISK}”:”ram13″

        }
        ,
        {
        “{#DISK}”:”ram14″

        }
        ,
        {
        “{#DISK}”:”ram15″

        }
        ,
        {
        “{#DISK}”:”loop0″

        }
        ,
        {
        “{#DISK}”:”loop1″

        }
        ,
        {
        “{#DISK}”:”loop2″

        }
        ,
        {
        “{#DISK}”:”loop3″

        }
        ,
        {
        “{#DISK}”:”loop4″

        }
        ,
        {
        “{#DISK}”:”loop5″

        }
        ,
        {
        “{#DISK}”:”loop6″

        }
        ,
        {
        “{#DISK}”:”loop7″

        }
        ,
        {
        “{#DISK}”:”sr0″

        }
        ,
        {
        “{#DISK}”:”sda”

        }
        ,
        {
        “{#DISK}”:”sda1″

        }
        ,
        {
        “{#DISK}”:”sda2″

        }
        ,
        {
        “{#DISK}”:”dm-0″

        }
        ,
        {
        “{#DISK}”:”dm-1″

        }
        ,
        {
        “{#DISK}”:”dm-2″

        }

        ]
        }

  8. Hey,

    Great job. This is very useful template.
    Could You help me with make a graph where I can have all drivers io per sec on one graph?

  9. Great Work!
    But I’m having some trouble. I’m sure it’s something I have configured wrong… after adding the template to a Linux host, the custom.vfs.dev.discovery is run and the values returned but the monitored items never get created.

    Any help would be appreciated, I can get you whatever log information you need.

    I am using Zabbix 2.4.1

      • Actually I found my issue. This template has a filter with the discovery rule but I had never put that regexp into Administration -> General – Regexp’s. Once I took care of that it was fine.

  10. Hi,
    The json output of queryDisks.pl has not been passed because of one “}” is missing.

    print “}\n”;

    must be added in the end of perl script.

  11. Hi Dennis,

    Before anything must say thank you very much for that´s excelent work. But for me, It´s a shame that still have not working :(( ….but i´m focus in.
    My question… I follow all steps but discovery item appears as not supported” in zabbix, for server were applies the template. For check it, I run in server console the following commands and looks it ok:
    ./queryDisks.pl
    cat /proc/diskstats
    cat /proc/diskstats | grep sda | head -1 | awk ‘{print $4}’

    …note that without change “sda” for $1 and remove one $ for print, it´s not working and gives me error (egrep sintax error) Any idea about what can it happening?

    Thanks in advance and sry for my english 😉

  12. Hi Dennis,

    I use zabbix version 2.45. and using your guide but zabbix server warning not support item key. Can you help me.

    Thanks

  13. Hi Dennis,

    I restart the service of zabbix-agent and I check my zabbix_log show the message as below

    sh: /opt/zabbix/linux/queryDisks.pl: not found

    Can you help me.

    Thanks

  14. Hi Dennis,

    Thanks a lot for the scripts, I am trying to setup your template on Zabbix 2.4.7. I had followed your instructions and imported the template, copied the perl file, configuration and added regex expression but while adding host to this template, graph is not generated. I have checked the agent debug log its reading the perl script. What might be the cause of the issue?.

  15. Dennis,

    I would just like to thank you for sharing this. I was able to get everthing working in no time with your template and instruction.

    Thank you again!!

  16. If you want to go another route, you can actually use Net-SNMP (SNMPD) on Linux for this. Set up discovery of OID 1.3.6.1.4.1.2021.13.15.1.1.2 (or use diskIODevice) and create prototype items:

    OID 1.3.6.1.4.1.2021.13.15.1.1.12
    diskIONReadX COUNTER64 ReadOnly The number of bytes read from this device since boot.

    OID 1.3.6.1.4.1.2021.13.15.1.1.13
    diskIONWrittenX COUNTER64 ReadOnly The number of bytes written to this device since boot.

    OID 1.3.6.1.4.1.2021.13.15.1.1.5
    diskIOReads COUNTER ReadOnly The number of read accesses from this device since boot.

    OID 1.3.6.1.4.1.2021.13.15.1.1.6
    diskIOWrites COUNTER ReadOnly The number of write accesses to this device since boot.

    All set up with numeric (unsigned), decimal and Delta (speed per second) and unit “Bps”.

    Don’t forget set regex filters for which devices you want to discover like: sda$|sdb$|sdc$

    Works great 🙂

  17. Hi Dennis,

    We are trying to set up a tablespace monitoring for our db2 version 10.5 database using zabbix 2.4.6. We have a db2_parser.pl script as attached below.

    A UserParameter is also defined in the zabbix_agentd.conf. But when we restart the zabbix agent and look on the console, we get an error saying Value should be a JSON object. There was an extra comma in the parser file that has been removed now. But the error still persists.

    Can you please let me know your thoughts about this?

    Spoorthi

    UserParameter=db2.tbsp.discovery,/usr/local/bin/db2_parser.pl -database sample -discover

    #!/usr/bin/perl
    # —————————————————————-
    # Author: Pierce Ward
    # Contact: pierceward@gmail.com
    # —————————————————————-
    # Description: Utility to send DB2 statistics to our Zabbix
    # Server(s).
    # —————————————————————-
    use strict;
    use POSIX qw(strftime);
    use Getopt::Long;

    # —————
    # Configuration
    # —————
    my $db2 = ‘/home/db2inst1/sqllib/bin/db2 -x’;
    my $db2pd = ‘/home/db2inst1/sqllib/adm/db2pd’;
    my $zabbix_conf = ‘/etc/zabbix/zabbix_agentd.conf’;
    my $zabbix_sender = ‘/usr/bin/zabbix_sender’;

    # — defaults
    my $debug = 0;

    # —————
    # GetOptions
    # —————
    GetOptions(“database=s”=>\my $database,
    “discover”=>\my $discover,
    “perf”=>\my $perf,
    “hadr”=>\my $hadr,
    “tablespaces”=>\my $tablespaces,
    “debug”=>\my $debug);

    # Ensure required options were passed or print usage
    if ((!$perf && !$hadr && !$tablespaces && !$discover) || !$database) {

    print “Usage: $0 -database sample [ -discover | -perf | -hadr | -tablespaces ]\n\n”;
    print “Switches:\n”;
    print ” -database (The name of your DB2 database)\n”;
    print ” -discover (Will discover tablespaces. This should only be called by a Zabbix User Parameter).\n”;
    print ” -perf (Sends statistics regarding lock-timeouts and deadlocks to zabbix).\n”;
    print ” -hadr (Sends statistics regarding High Availability Disaster Recovery to zabbix).\n”;
    print ” -tablespaces (Sends tablespace statistics to zabbix).\n\n”;
    print “Example Usage: \n”;
    print “$0 -database sample -perf\n”;
    print “$0 -database sample -hadr\n”;

    exit (-1);

    }

    # If tablespace discovery
    if ($discover) {
    &discoverTablespaces();
    }
    # If Performance stats
    elsif ($perf) {
    &getPerformanceStats();
    }
    # If HADR stats
    elsif ($hadr) {
    &getHadrStats();
    }
    # If Tablespace container stats
    elsif ($tablespaces) {
    &getTablespaceStats();
    }

    # ———————–
    # Query HADR Information
    # ———————–

    sub getHadrStats() {

    # global variables
    local *database, *debug, *db2, *db2pd, *zabbix_conf, *zabbix_sender, *hadr_log;
    my $cmd = `$db2pd -hadr -database $database 2>/dev/null| /bin/grep -A1 Role | /usr/bin/tail -n 1`;
    print “DEBUG: $cmd\n” if $debug;

    # if we have output from our command
    if ($cmd) {
    my($db_role, $db_state) = split ‘ ‘, $cmd;
    system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.hadr.role”, “-o”, “$db_role”);
    system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.hadr.state”, “-o”, “$db_state”);
    }
    }

    # —————————–
    # Query Performance Information
    # —————————–

    sub getPerformanceStats() {

    # global variables
    local *database, *debug, *db2, *zabbix_conf, *zabbix_sender;
    my $sqlcmd = `$db2 connect to $database&>/dev/null && $db2 -x “SELECT SUBSTR (DB_NAME, 1, 20) AS DB_NAME, LOCK_TIMEOUTS, DEADLOCKS FROM sysibmadm.snapdb WHERE DB_NAME LIKE UPPER(‘%$database%’)”`;

    # check for db name in output
    if ($sqlcmd =~ m/$database/i) {
    my($db_name,$db_locktimeouts,$db_deadlocks) = split ‘ ‘, $sqlcmd;
    print “DEBUG: DB_NAME: $db_name, LOCK_TIMEOUTS: $db_locktimeouts, DEADLOCKS: $db_deadlocks\n” if $debug;

    # send to zabbix
    system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.perf.locktimeouts”, “-o”, “$db_locktimeouts”);
    system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.perf.deadlocks”, “-o”, “$db_deadlocks”);
    }

    }

    # —————————–
    # Query Tablespace Information
    # —————————–

    sub getTablespaceStats() {

    # global variables
    local *database, *debug, *db2, *zabbix_conf, *zabbix_sender;
    my $sqlcmd;

    # Set debug options
    if ($debug) {
    $sqlcmd = “$db2 connect to $database && $db2 \”select substr(tbsp_name,1,30) as TBSPC_NAME, TBSP_TYPE, TBSP_USABLE_PAGES, TBSP_USED_PAGES, TBSP_FREE_PAGES from sysibmadm.tbsp_utilization as snapshot_tbs_cfg\””;
    }
    else {
    $sqlcmd = “$db2 connect to $database&>/dev/null && $db2 \”select substr(tbsp_name,1,30) as TBSPC_NAME, TBSP_TYPE, TBSP_USABLE_PAGES, TBSP_USED_PAGES, TBSP_FREE_PAGES from sysibmadm.tbsp_utilization as snapshot_tbs_cfg\””;
    }

    # Prepare our command
    open my $cmd, ‘-|’, “$sqlcmd”;

    # Loop through command output
    while (my $line = ) {
    chomp; # remove newlines

    # if debug print full line
    print “DEBUG: \n” if $debug;

    # split text
    my($ts_name,$ts_type,$ts_usable,$ts_used,$ts_free) = split ‘ ‘, $line;

    # only send stats for Database Managed Storage
    if ($ts_type =~ m/DMS/) {
    my $tstype = system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.tbsp[$ts_name,tbsp_type]”, “-o”, “$ts_type”);
    my $tsusable = system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.tbsp[$ts_name,tbsp_usable_pages]”, “-o”, “$ts_usable”);
    my $tsused = system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.tbsp[$ts_name,tbsp_used_pages]”, “-o”, “$ts_used”);
    my $tsfree = system(“$zabbix_sender”, “-c”, “$zabbix_conf”, “-k”, “db2.tbsp[$ts_name,tbsp_free_pages]”, “-o”, “$ts_free”);
    }
    }
    close $cmd;
    }

    # ———————
    # Discover Tablespaces
    # ———————

    sub discoverTablespaces() {

    # global variables
    local *database, *debug, *db2, *zabbix_conf, *zabbix_sender;
    my $sqlcmd;
    my $first=1;

    # Set debug options
    if ($debug) {
    $sqlcmd = “$db2 connect to $database && $db2 \”select substr(tbsp_name,1,30) as TBSPC_NAME, TBSP_TYPE from sysibmadm.tbsp_utilization as snapshot_tbs_cfg\””;
    }
    else {
    $sqlcmd = “$db2 connect to $database&>/dev/null && $db2 \”select substr(tbsp_name,1,30) as TBSPC_NAME, TBSP_TYPE from sysibmadm.tbsp_utilization as snapshot_tbs_cfg\””;
    }

    # Prepare our command
    open my $cmd, ‘-|’, “$sqlcmd”;

    # Start JSON Format
    print “{\n”;
    print “\t\”data\”:[\n\n”;

    # Loop through command output
    while (my $line = ) {
    chomp; # remove newlines

    # if debug print full line
    print “DEBUG: \n” if $debug;

    # split text
    my($ts_name,$ts_type) = split ‘ ‘, $line;

    # print JSON separator only if NOT the first item
    print “\t,\n” if not $first;
    $first = 0;

    # print in JSON format
    print “\t{\n”;
    print “\t\t\”{#TSNAME}\”:\”$ts_name\”,\n”;
    print “\t\t\”{#TSTYPE}\”:\”$ts_type\”\n”;
    print “\t}\n”;

    }
    close $cmd;

    # End JSON Format
    print “\n\t]\n”;
    print “}\n”;

    }

  18. I am trying to implement on 3.x and attached to couple of test systems.

    Implemented all the steps, but I am not getting any data on my zabbix screen. How to verify if I missed any step. Thanks!

  19. Hi,

    Thanks for the great article. It helped a lot.

    I configured all the steps, but still not seeing the data on the zabbix portal.

    I double checked, but could not fifure what is missing.

    How to verify which step is missing from my side? BTW, I am using 3.x

    • Hey Rak, I haven’t tested the script on 3.x yet but I suppose it should work. Does the discovery script return any values when you run it from the command line?

      • you mean queryDisks.pl output? it is fine

        {
        “data”:[

        {
        “{#DISK}”:”xvda”

        }
        ,
        {
        “{#DISK}”:”xvda1″

        }
        ,
        {
        “{#DISK}”:”xvda2″

        }
        ,
        {
        “{#DISK}”:”xvda3″

        }
        ,
        {
        “{#DISK}”:”xvda4″

        }
        ,
        {
        “{#DISK}”:”xvda5″

        }
        ,
        {
        “{#DISK}”:”xvdb”

        }
        ,
        {
        “{#DISK}”:”sr0″

        }

        ]
        }
        ]
        }

  20. Hi

    Great Job, Works fine ! Many Thanks
    How can we make correspondence between raw device sdX or mdX with mountpoint ? to present mountpoint in the graph and see immediately /u01/oracle ou /data/mysql that are most comprehensible that sda4…
    it’ possible ?

Leave a Reply

Your email address will not be published. Required fields are marked *