Monitor APC for PHP with Zabbix

De Wiki de Romain RUDIGER
Aller à : navigation, rechercher


Introduction

The goal is to monitor some informations about the APC cache module of PHP in Zabbix.

I found some informations on these sites:

The php pages

I created three pages to get the informations from APC. You need to put these files in a directory served by Apache.

  • apc-stats-mem.php
<? if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") { print(serialize(apc_sma_info())); } ?>
  • apc-stats.php
<? if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") { print(serialize(apc_cache_info('',true))); } ?>
  • apc-stats-user.php
<? if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") { print(serialize(apc_cache_info('user',true))); } ?>

The php getter script

I created one php script which retrieve the data from the web server: /etc/zabbix/apc-check.php

<?php

$url = $argv[1];
$key = $argv[2];

$results = file_get_contents($url);

if ($results)
        $results = unserialize($results);
else
        exit;

echo $results["$key"];

?>

The Zabbix agent configuration

/etc/zabbix/zabbix_agentd.conf

UserParameter=apc.mem.used,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats-mem.php";echo "($(php $script "$url" "seg_size")*$(php $script "$url" "num_seg"))-$(php $script "$url" "avail_mem")"|bc
UserParameter=apc.mem.avail,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats-mem.php";php $script "$url" "avail_mem"
UserParameter=apc.hits,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats.php";php $script "$url" "num_hits"
UserParameter=apc.misses,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats.php";php $script "$url" "num_misses"
UserParameter=apc.hits_ratio,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats.php";echo "scale=2;($(php $script "$url" "num_hits")/($(php $script "$url" "num_hits")+$(php $script "$url" "num_misses")))*100"|bc
UserParameter=apc.entries,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats.php";php $script "$url" "num_entries"
UserParameter=apc.user.entries,script=/etc/zabbix/apc-check.php;url="https://127.0.0.1/apc-stats-user.php";php $script "$url" "num_entries"

The Zabbix Template

I configured 7 elements and 2 charts.

The configured elements.
The last values of these elements.
The hits rate chart.

Content of the template 'zbx_templates_export.xml':

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export version="1.0" date="19.09.12" time="18.01">
  <hosts>
    <host name="Template_App_Apache">
      <proxy_hostid>0</proxy_hostid>
      <useip>1</useip>
      <dns></dns>
      <ip>127.0.0.1</ip>
      <port>10050</port>
      <status>3</status>
      <useipmi>0</useipmi>
      <ipmi_ip>127.0.0.1</ipmi_ip>
      <ipmi_port>623</ipmi_port>
      <ipmi_authtype>0</ipmi_authtype>
      <ipmi_privilege>2</ipmi_privilege>
      <ipmi_username></ipmi_username>
      <ipmi_password></ipmi_password>
      <groups>
        <group>Templates</group>
      </groups>
      <triggers/>
      <items>
        <item type="0" key="apc.entries" value_type="3">
          <description>Apache APC File Cache Entries</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units></units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
        <item type="0" key="apc.hits" value_type="3">
          <description>Apache APC File Cache Hits</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units></units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
        <item type="0" key="apc.hits_ratio" value_type="3">
          <description>Apache APC File Cache Hits in %</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units>%</units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
        <item type="0" key="apc.mem.avail" value_type="3">
          <description>Apache APC File Cache Memory Free</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units>B</units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
        <item type="0" key="apc.mem.used" value_type="3">
          <description>Apache APC File Cache Memory Used</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units>B</units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
        <item type="0" key="apc.misses" value_type="3">
          <description>Apache APC File Cache Misses</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units></units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
        <item type="0" key="apc.user.entries" value_type="3">
          <description>Apache APC User Cache Entries</description>
          <ipmi_sensor></ipmi_sensor>
          <delay>60</delay>
          <history>7</history>
          <trends>365</trends>
          <status>0</status>
          <data_type>0</data_type>
          <units></units>
          <multiplier>0</multiplier>
          <delta>0</delta>
          <formula>1</formula>
          <lastlogsize>0</lastlogsize>
          <logtimefmt></logtimefmt>
          <delay_flex></delay_flex>
          <authtype>0</authtype>
          <username></username>
          <password></password>
          <publickey></publickey>
          <privatekey></privatekey>
          <params></params>
          <trapper_hosts></trapper_hosts>
          <snmp_community></snmp_community>
          <snmp_oid></snmp_oid>
          <snmp_port>161</snmp_port>
          <snmpv3_securityname></snmpv3_securityname>
          <snmpv3_securitylevel>0</snmpv3_securitylevel>
          <snmpv3_authpassphrase></snmpv3_authpassphrase>
          <snmpv3_privpassphrase></snmpv3_privpassphrase>
          <valuemapid>0</valuemapid>
          <applications>
            <application>Apache</application>
          </applications>
        </item>
      </items>
      <templates/>
      <graphs>
        <graph name="Apache APC File Cache Hits Rate" width="900" height="200">
          <ymin_type>1</ymin_type>
          <ymax_type>1</ymax_type>
          <ymin_item_key></ymin_item_key>
          <ymax_item_key></ymax_item_key>
          <show_work_period>0</show_work_period>
          <show_triggers>0</show_triggers>
          <graphtype>0</graphtype>
          <yaxismin>0.0000</yaxismin>
          <yaxismax>100.0000</yaxismax>
          <show_legend>0</show_legend>
          <show_3d>0</show_3d>
          <percent_left>0.0000</percent_left>
          <percent_right>0.0000</percent_right>
          <graph_elements>
            <graph_element item="Template_App_Apache:apc.hits_ratio">
              <drawtype>1</drawtype>
              <sortorder>0</sortorder>
              <color>009900</color>
              <yaxisside>0</yaxisside>
              <calc_fnc>2</calc_fnc>
              <type>0</type>
              <periods_cnt>5</periods_cnt>
            </graph_element>
          </graph_elements>
        </graph>
        <graph name="Apache APC File Cache Memory Usage" width="900" height="200">
          <ymin_type>0</ymin_type>
          <ymax_type>0</ymax_type>
          <ymin_item_key></ymin_item_key>
          <ymax_item_key></ymax_item_key>
          <show_work_period>0</show_work_period>
          <show_triggers>0</show_triggers>
          <graphtype>1</graphtype>
          <yaxismin>0.0000</yaxismin>
          <yaxismax>1.0000</yaxismax>
          <show_legend>0</show_legend>
          <show_3d>0</show_3d>
          <percent_left>0.0000</percent_left>
          <percent_right>0.0000</percent_right>
          <graph_elements>
            <graph_element item="Template_App_Apache:apc.mem.used">
              <drawtype>0</drawtype>
              <sortorder>0</sortorder>
              <color>990000</color>
              <yaxisside>0</yaxisside>
              <calc_fnc>2</calc_fnc>
              <type>0</type>
              <periods_cnt>5</periods_cnt>
            </graph_element>
            <graph_element item="Template_App_Apache:apc.mem.avail">
              <drawtype>0</drawtype>
              <sortorder>2</sortorder>
              <color>009900</color>
              <yaxisside>0</yaxisside>
              <calc_fnc>2</calc_fnc>
              <type>0</type>
              <periods_cnt>5</periods_cnt>
            </graph_element>
          </graph_elements>
        </graph>
      </graphs>
      <macros/>
    </host>
  </hosts>
  <dependencies/>
</zabbix_export>