123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- /**
- * @file
- * APCu instrumentation for Munin.
- *
- * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
- *
- * Licensed under the General Public License version 2 or later.
- */
- /**
- * Implements hook_munin_api_info().
- *
- * Returns an array of Munin graph informations, indexed by graph name, each
- * containing an array of field information.
- */
- function munin_apc_munin_api_info() {
- $int = [
- '#graph_printf' => '%d',
- ];
- $ret = [
- '#title' => t('APCu'),
- '#description' => t('Graphs about PHP APCu memory use'),
- 'munin_apc' => [
- '#title' => t('APCu Caching'),
- '#info' => t('Collect memory-level information for the Alternative PHP Cache for user data). This graph uses IEC binary sizes.'),
- '#graph_args' => '--base 1024 --lower-limit 0',
- 'total_size' => $int + [
- '#label' => t('Bytes allocated'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('Number of bytes allocated to APCu.'),
- ],
- 'used_size' => $int + [
- '#label' => t('Bytes in use'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('Number of bytes actually used by APCu, either cached or deleted'),
- ],
- ],
- 'munin_apc_entries' => [
- '#title' => t('APCu Entries'),
- '#info' => t('Collect entries-level information for APCu.'),
- '#graph_args' => '--base 1000 --lower-limit 0',
- 'num_hits' => $int + [
- '#label' => t('Hits since last restart'),
- '#type' => MUNIN_API_COUNTER,
- ],
- 'num_misses' => $int + [
- '#label' => t('Misses since last restart'),
- '#type' => MUNIN_API_COUNTER,
- ],
- 'num_inserts' => $int + [
- '#label' => t('Insertions since last restart'),
- '#type' => MUNIN_API_COUNTER,
- ],
- /*
- 'hit_rate' => $int + [
- '#label' => t('Hit/miss ratio since last restart'),
- '#type' => MUNIN_API_GAUGE,
- ],
- */
- 'cache_entries' => $int + [
- '#label' => t('Number of cache entries'),
- '#type' => MUNIN_API_GAUGE,
- ],
- 'deleted_entries' => $int + [
- '#label' => t('Number of deleted entries'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('Deleted entries lingering until the garbage collection TTL elapses'),
- ],
- ],
- 'munin_apc_uptime' => [
- '#title' => t('APC Uptime'),
- '#info' => t('Uptime information for APCu.'),
- '#graph_vlabel' => t('Uptime in days'),
- '#graph_scale' => 'no',
- 'uptime' => $int + [
- '#label' => t('Up-time of APCu instance'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('Days since last APCu restart.'),
- '#draw' => MUNIN_API_DRAW_AREA,
- ],
- ],
- ];
- return $ret;
- }
- /**
- * Implements hook_munin_api_fetch().
- *
- * The static cache is useless at this point, but will likely become useful
- * if module builds Munin multigraphs.
- */
- function munin_apc_munin_api_fetch($graph_name) {
- static $cache = [];
- if (empty($cache)) {
- $info = apcu_sma_info();
- // SMA Info.
- $total = $info['num_seg'] * $info['seg_size'];
- $cache['munin_apc']['total_size'] = (int) $total;
- $cache['munin_apc']['used_size'] = (int) ($total - $info['avail_mem']);
- // Cache info.
- $info = apcu_cache_info();
- $cache['munin_apc_uptime']['uptime'] = (REQUEST_TIME - $info['start_time']) / 86400;
- foreach (['num_hits', 'num_misses', 'num_inserts'] as $field) {
- $cache['munin_apc_entries'][$field] = $info[$field];
- }
- $cache['munin_apc_entries']['cache_entries'] = $info['num_entries'] ?? count($info['cache_list']);
- $cache['munin_apc_entries']['deleted_entries'] = count($info['deleted_list']);
- }
- $ret = $cache[$graph_name];
- return $ret;
- }
|