munin_apc.module 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 'uptime' => $int + array(
  72. '#label' => t('Up-time of APC instance'),
  73. '#type' => MUNIN_API_GAUGE,
  74. '#info' => t('Days since last APC restart.'),
  75. '#draw' => MUNIN_API_DRAW_AREA,
  76. ),
  77. ),
  78. );
  79. return $ret;
  80. }
  81. /**
  82. * Implements hook_munin_api_fetch().
  83. *
  84. * The static cache is useless at this point, but will likely become useful
  85. * if module builds Munin multigraphs.
  86. */
  87. function munin_apc_munin_api_fetch($graph_name) {
  88. static $cache = array();
  89. if (empty($cache)) {
  90. $info = apc_sma_info();
  91. $ret = array();
  92. // SMA Info
  93. $total = $info['num_seg'] * $info['seg_size'];
  94. $cache['munin_apc']['total_size'] = (int) $total;
  95. $cache['munin_apc']['used_size'] = (int) ($total - $info['avail_mem']);
  96. // Cache info
  97. $info = apc_cache_info();
  98. $cache['munin_apc_uptime']['uptime'] = (time() - $info['start_time']) / 86400;
  99. foreach (array('num_hits', 'num_misses', 'num_inserts') as $field) {
  100. $cache['munin_apc'][$field] = $info[$field];
  101. }
  102. $cache['munin_apc']['cache_entries'] = count($info['cache_list']);
  103. $cache['munin_apc']['deleted_entries'] = count($info['deleted_list']);
  104. }
  105. $ret = $cache[$graph_name];
  106. return $ret;
  107. }