pcp
[Top] [All Lists]

Re: PCP Zabbix Agent PMDA

To: myllynen@xxxxxxxxxx
Subject: Re: PCP Zabbix Agent PMDA
From: fche@xxxxxxxxxx (Frank Ch. Eigler)
Date: Mon, 02 Nov 2015 17:51:37 -0500
Cc: pcp developers <pcp@xxxxxxxxxxx>
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <56309994.8020404@xxxxxxxxxx> (Marko Myllynen's message of "Wed, 28 Oct 2015 11:47:00 +0200")
References: <56309994.8020404@xxxxxxxxxx>
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)
myllynen wrote:

> [...]  The PMDA was easy enough to implement so I did it anyway and
> thought to share it here.  [...]

As a data source, perhaps zabbix is a bit too thin (low
quality/quantity) to bother pull from, but if we did:


> [...]
> +our $host  = '127.0.0.1';
> +our $port  = '10050';
> +our $srcip = '';
> +our $pmda  = PCP::PMDA->new('zabbixagent', 480);
> +
> +# Example instance configuration
> +our $net_indom = 0;
> +our $vfs_indom = 1;
> +our @net_insts = sort(split('\n', `ls -1 /sys/class/net`));
> +our @vfs_insts = sort(split('\n', `awk '/^\\/|tmpfs/ {print \$2}' 
> /proc/mounts`));


If the idea is that we'd poll remote zabbix servers too (as $host is
configurable), then polling the local /sys or /proc files is going to
give the wrong information.


> [...]
> +# Fetch command (could be replaced with direct socket communications)
> +# 
> https://www.zabbix.com/documentation/3.0/manual/appendix/items/activepassive
> +if ($srcip ne '') {
> +     $getcmd = "zabbix_get -s $host -p $port -I $srcip -k ";
> +} else {
> +     $getcmd = "zabbix_get -s $host -p $port -k ";
> +}

How fast is this operation generally?  If it's a large fraction of a
second or more, it'd bog down pmcd and other clients, so we'd have to
use background threads or some other elaboration.


> +sub zabbix_agent_connection_test {
> +     $pmda->log("pinging $host");
> +     my $res = `$getcmd agent.ping`;
> [...]
> +
> +sub zabbix_agent_fetch_callback {
> +     if (!defined($conn_ok)) {
> +             zabbix_agent_connection_test();
> +     }
> +     return (PM_ERR_NOTCONN, 0) unless $conn_ok;

In a real deployment, you wouldn't want to give up for a single error
like that.  How about just attempting the $getcmd all the time, and
handling the timeout or whatnot error indication with PM_ERR_*?  (Is
the timeout too long?  Maybe one can shorten it with /usr/bin/timeout
e.g.)


> [...]
> +     my ($name, $mode) = $q =~ /(.*)\.(.*)/;
> +     # Reformat the queried item key as needed
> +     if (exists($insts{$name})) {
> +             # vfs.fs.size.mode -> vfs.fs.size[mnt,mode]
> +             $q = $name . "[$insts{$name}[$inst],$mode]";
> +     [...]

This may be fine, but I'd be a bit concerned using plain regexps to
parse data that may not always be the vanilla form we like.  What if
there are special characters or more dots or quotes or something in
the name components?


> [...]
> +$pmda->add_metric(pmda_pmid(0,0), PM_TYPE_STRING, PM_INDOM_NULL,
> +             PM_SEM_INSTANT, pmda_units(0,0,0,0,0,0),
> +             'zabbixagent.agent.hostname', '', '');
> +$pmda->add_metric(pmda_pmid(0,1), PM_TYPE_U32, PM_INDOM_NULL,
> +             PM_SEM_DISCRETE, pmda_units(0,0,0,0,0,0),
> +             'zabbixagent.agent.ping', '', '');
> [... * dozens ...]

Could this list of metadata be generated by querying zabbix 
instead of being hard-coded here?


- FChE

<Prev in Thread] Current Thread [Next in Thread>