munin_apc.module 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * APC instrumentation for Munin
  6. *
  7. * @author Frederic G. MARAND
  8. *
  9. * @copyright (c) 2011 Ouest Systèmes Informatiques
  10. *
  11. * Licensed under the General Public License version 2 or later.
  12. */
  13. /**
  14. * Implements hook_munin_api_info().
  15. *
  16. * @return
  17. * An array of Munin graph informations, index by graph name, each containing
  18. * an array of field information.
  19. */
  20. function munin_apc_munin_api_info() {
  21. $int = array(
  22. '#graph_printf' => '%d',
  23. );
  24. $ret = array(
  25. '#title' => t('APC'),
  26. '#description' => t('Graphs about PHP APC'),
  27. 'munin_apc' => array(
  28. '#title' => t('APC Caching'),
  29. '#info' => t('Collect cache information for the Alternative PHP Cache. This graph uses IEC binary sizes.'),
  30. '#graph_args'=> '--base 1024 --lower-limit 0',
  31. 'total_size' => $int + array(
  32. '#label' => t('Bytes allocated'),
  33. '#type' => MUNIN_API_GAUGE,
  34. '#info' => t('Number of bytes allocated to APC.')
  35. ),
  36. 'used_size' => $int + array(
  37. '#label' => t('Bytes in use'),
  38. '#type' => MUNIN_API_GAUGE,
  39. '#info' => t('Number of bytes actually used by APC, either cached or deleted'),
  40. ),
  41. 'num_hits' => $int + array(
  42. '#label' => t('Hits since last restart'),
  43. '#type' => MUNIN_API_COUNTER,
  44. ),
  45. 'num_misses' => $int + array(
  46. '#label' => t('Misses since last restart'),
  47. '#type' => MUNIN_API_COUNTER,
  48. ),
  49. 'num_inserts' => $int + array(
  50. '#label' => t('Insertions since last restart'),
  51. '#type' => MUNIN_API_COUNTER,
  52. ),
  53. // 'hit_rate' => $int + array(
  54. // '#label' => t('Hit/miss ratio since last restart'),
  55. // '#type' => MUNIN_API_GAUGE,
  56. // ),
  57. 'cache_entries' => $int + array(
  58. '#label' => t('Number of cache entries'),
  59. '#type' => MUNIN_API_GAUGE,
  60. ),
  61. 'deleted_entries' => $int + array(
  62. '#label' => t('Number of deleted entries'),
  63. '#type' => MUNIN_API_GAUGE,
  64. '#info' => t('Deleted entries lingering until the garbage collection TTL elapses'),
  65. ),
  66. ),
  67. 'munin_apc_uptime' => array(
  68. '#title' => t('APC Uptime'),
  69. '#info' => t('Uptime information for the Alternative PHP Cache.'),
  70. '#graph_vlabel' => t('Uptime in days'),
  71. '#graph_scale' => 'no',
  72. 'uptime' => $int + array(
  73. '#label' => t('Up-time of APC instance'),
  74. '#type' => MUNIN_API_GAUGE,
  75. '#info' => t('Days since last APC restart.'),
  76. '#draw' => MUNIN_API_DRAW_AREA,
  77. ),
  78. ),
  79. );
  80. return $ret;
  81. }
  82. /**
  83. * Implements hook_munin_api_fetch().
  84. *
  85. * The static cache is useless at this point, but will likely become useful
  86. * if module builds Munin multigraphs.
  87. */
  88. function munin_apc_munin_api_fetch($graph_name) {
  89. static $cache = array();
  90. if (empty($cache)) {
  91. $info = apc_sma_info();
  92. $ret = array();
  93. // SMA Info
  94. $total = $info['num_seg'] * $info['seg_size'];
  95. $cache['munin_apc']['total_size'] = (int) $total;
  96. $cache['munin_apc']['used_size'] = (int) ($total - $info['avail_mem']);
  97. // Cache info
  98. $info = apc_cache_info();
  99. $cache['munin_apc_uptime']['uptime'] = (time() - $info['start_time']) / 86400;
  100. foreach (array('num_hits', 'num_misses', 'num_inserts') as $field) {
  101. $cache['munin_apc'][$field] = $info[$field];
  102. }
  103. $cache['munin_apc']['cache_entries'] = count($info['cache_list']);
  104. $cache['munin_apc']['deleted_entries'] = count($info['deleted_list']);
  105. }
  106. $ret = $cache[$graph_name];
  107. return $ret;
  108. }