munin_apc.module 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 memory yse'),
  27. 'munin_apc' => array(
  28. '#title' => t('APC Caching'),
  29. '#info' => t('Collect memory-level 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. ),
  42. 'munin_apc_entries' => array(
  43. '#title' => t('APC Entries'),
  44. '#info' => t('Collect entries-level information for the Alternative PHP Cache.'),
  45. '#graph_args'=> '--base 1000 --lower-limit 0',
  46. 'num_hits' => $int + array(
  47. '#label' => t('Hits since last restart'),
  48. '#type' => MUNIN_API_COUNTER,
  49. ),
  50. 'num_misses' => $int + array(
  51. '#label' => t('Misses since last restart'),
  52. '#type' => MUNIN_API_COUNTER,
  53. ),
  54. 'num_inserts' => $int + array(
  55. '#label' => t('Insertions since last restart'),
  56. '#type' => MUNIN_API_COUNTER,
  57. ),
  58. // 'hit_rate' => $int + array(
  59. // '#label' => t('Hit/miss ratio since last restart'),
  60. // '#type' => MUNIN_API_GAUGE,
  61. // ),
  62. 'cache_entries' => $int + array(
  63. '#label' => t('Number of cache entries'),
  64. '#type' => MUNIN_API_GAUGE,
  65. ),
  66. 'deleted_entries' => $int + array(
  67. '#label' => t('Number of deleted entries'),
  68. '#type' => MUNIN_API_GAUGE,
  69. '#info' => t('Deleted entries lingering until the garbage collection TTL elapses'),
  70. ),
  71. ),
  72. 'munin_apc_uptime' => array(
  73. '#title' => t('APC Uptime'),
  74. '#info' => t('Uptime information for the Alternative PHP Cache.'),
  75. '#graph_vlabel' => t('Uptime in days'),
  76. '#graph_scale' => 'no',
  77. 'uptime' => $int + array(
  78. '#label' => t('Up-time of APC instance'),
  79. '#type' => MUNIN_API_GAUGE,
  80. '#info' => t('Days since last APC restart.'),
  81. '#draw' => MUNIN_API_DRAW_AREA,
  82. ),
  83. ),
  84. );
  85. return $ret;
  86. }
  87. /**
  88. * Implements hook_munin_api_fetch().
  89. *
  90. * The static cache is useless at this point, but will likely become useful
  91. * if module builds Munin multigraphs.
  92. */
  93. function munin_apc_munin_api_fetch($graph_name) {
  94. static $cache = array();
  95. if (empty($cache)) {
  96. $info = apc_sma_info();
  97. $ret = array();
  98. // SMA Info
  99. $total = $info['num_seg'] * $info['seg_size'];
  100. $cache['munin_apc']['total_size'] = (int) $total;
  101. $cache['munin_apc']['used_size'] = (int) ($total - $info['avail_mem']);
  102. // Cache info
  103. $info = apc_cache_info();
  104. $cache['munin_apc_uptime']['uptime'] = (time() - $info['start_time']) / 86400;
  105. foreach (array('num_hits', 'num_misses', 'num_inserts') as $field) {
  106. $cache['munin_apc_entries'][$field] = $info[$field];
  107. }
  108. $cache['munin_apc_entries']['cache_entries'] = count($info['cache_list']);
  109. $cache['munin_apc_entries']['deleted_entries'] = count($info['deleted_list']);
  110. }
  111. $ret = $cache[$graph_name];
  112. return $ret;
  113. }