Slow statistics collector - UserParameters or zabbix_sender?

  • Filter
  • Time
  • Show
Clear All
new posts

    Slow statistics collector - UserParameters or zabbix_sender?

    I'm using zabbix to monitor several linux servers and other devices. However, i have a few questions about items, keys etc.

    To monitor a Dell MD3000i i have to use a JVM with a Java cli from Dell. I can get statistics from it, and have them displayed in my console. However, to have it run once, spit out the statistics and stop takes around 30 seconds-1 minute.

    I want to get roughly 20 items from this box to monitor (in/out traffic on the 4 interfaces, read/write io on the disks etc). I believe i can do this with a UserParameter for each key. However, if i understand zabbix correctly, as soon as the server queries those UserParameters it will run the java cli, get that 1 particular key, returns it and closes the cli. As this takes 30 seconds in a best case scenario, i think i can expect to have a minimum of 10 cli's running at any time (with a check every 60 seconds).

    That isn't acceptable. For one it is kinda silly to have to run this cli 20 times to get all the data, select 1 key from it, return that key, run it again; get the same data and return another key.

    So what is the best practice for a situation like this? Have 20-odd UserParameters running the same slow and resourcehugging application everytime does not sound like a good practice.

    So is there a way to have 1 UserParameter return multiple keys? So i can run the script once, and return all 20 keys at the same time.

    Or should i make a script that uses a zabbix_sender to send the keys whenever it is called from a UserParameter (i don't want to use a crontab for it if possible, so i can let the zabbix server query the data when it wants it)

    And can i use zabbx_sender to send multiple keys at once? (i want to limit the amount of processes i have to start/stop for the data collection as much as possible - so a 'grep item cachefile|tr|cut|uniq|sort|uniq' construction launching multiple programs is not what i want - nor do i want a script that starts a zabbix_sender more than once to send data to the server if possible)

    Anyway, my preference would be a UserParameter that can return multiple keys at once, but if that isnt possible i'd have to write a script that uses one instance of zabbix_sender; and if that fails, i guess i have to write my own function to send data to the zabbix server so i can call it from my own script.

    As there are not many response, i went forward and made myself a script.

    Based on:

    First; i wanted to do it in php, as most of our codebase is in php (and i think perl looks ugly )

    Anyway, this is what i came up with. A way to collect and send multiple keys at once to the server:
    	define("SERVER", "");
    	define("PORT", "10051");
    	 * function zabbix_sender - send data to the zabbix server
    	 * @param array $data array(array("host" => $host, "key" => $key, "value" => $value), ... )
    	 * @return string if a string is returned, something went wrong
    	function zabbix_sender($data)
    		// open a socket to the zabbix server
    		$socket = fsockopen(SERVER, PORT, $errno, $errstr, 1000);
    		if (!$socket)
    			return "$errstr ($errno)\n";
    			// prepare the string in the JSON format used by zabbix_sender 1.6.4
    			$request = json_encode(array("request" => "sender data", "data" => $data));
    			// send it
    			fwrite($socket, $request);
    			// read response 
    			while (!feof($socket)) 
    				$response .= trim(fgets($socket, 1024)); 
    			$return = json_decode(trim(substr($response,6)),true);
    			// check the response for failures
    			if ($return["response"] != "success")
    				return "Response: " . $return["response"] . "\n";
    			// check if everything went OK
    			if (!strstr($return["info"], "Processed " . count($data)))
    				return "Some keys failed to update: " . $return["info"] . "\n";
    Using this script is childplay; Make sure you have the correct keys set up in Zabbix, have the port and host configured correctly in the defines, and make a data collector script + send it; like this:

    Here i have a 'Testhost' with three items; a '' a 'tv.out' and a 'tv.all'. To send the values to the zabbix_server, you give them to the function, which accepts an array filled with associative arrays with the keys 'host', 'key' and 'value' set. For example:
    	$tmp = array(
    			array("host" => "Testhost", "key" => "", "value" => rand(1,10)), 
       			array("host" => "Testhost", "key" => "tv.out", "value" => rand(1,10))
    With this function i should be able to collect and send tons of statistics to the server without having to fire up a zabbix_sender process for every key.



    No announcement yet.