munin_apc.module 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 probes informations, index by probe name.
  18. */
  19. function munin_apc_munin_api_info() {
  20. $int = array(
  21. '#graph_printf' => '%d',
  22. );
  23. $ret = array(
  24. 'munin_apc' => array(
  25. '#title' => t('PHP APC'),
  26. '#info' => t('Collect cache information for the Alternative PHP Cache'),
  27. 'total_size' => $int + array(
  28. '#label' => t('Bytes allocated'),
  29. '#type' => MUNIN_API_GAUGE,
  30. '#info' => t('Number of bytes allocated to APC.')
  31. ),
  32. 'used_size' => $int + array(
  33. '#label' => t('Bytes in use'),
  34. '#type' => MUNIN_API_GAUGE,
  35. '#info' => t('Number of bytes actually used by APC, either cached or deleted'),
  36. ),
  37. 'uptime' => $int + array(
  38. '#label' => t('Up-time of APC instance'),
  39. '#type' => MUNIN_API_GAUGE,
  40. '#info' => t('Seconds since last APC restart.'),
  41. ),
  42. 'num_hits' => $int + array(
  43. '#label' => t('Hits since last restart'),
  44. '#type' => MUNIN_API_COUNTER,
  45. ),
  46. 'num_misses' => $int + array(
  47. '#label' => t('Misses since last restart'),
  48. '#type' => MUNIN_API_COUNTER,
  49. ),
  50. 'num_inserts' => $int + array(
  51. '#label' => t('Insertions since last restart'),
  52. '#type' => MUNIN_API_COUNTER,
  53. ),
  54. // 'hit_rate' => $int + array(
  55. // '#label' => t('Hit/miss ratio since last restart'),
  56. // '#type' => MUNIN_API_GAUGE,
  57. // ),
  58. 'cache_entries' => $int + array(
  59. '#label' => t('Number of cache entries'),
  60. '#type' => MUNIN_API_GAUGE,
  61. ),
  62. 'deleted_entries' => $int + array(
  63. '#label' => t('Number of deleted entries'),
  64. '#type' => MUNIN_API_GAUGE,
  65. '#info' => t('Deleted entries lingering until the garbage collection TTL elapses'),
  66. ),
  67. ),
  68. );
  69. return $ret;
  70. }
  71. /**
  72. * Implements hook_munin_api_fetch().
  73. */
  74. function munin_apc_munin_api_fetch() {
  75. $info = apc_sma_info();
  76. $ret = array();
  77. // SMA Info
  78. $total = $info['num_seg'] * $info['seg_size'];
  79. $ret['total_size'] = (int) $total;
  80. $ret['used_size'] = (int) ($total - $info['avail_mem']);
  81. // Cache info
  82. $info = apc_cache_info();
  83. $ret['uptime'] = time() - $info['start_time'];
  84. foreach (array('num_hits', 'num_misses', 'num_inserts') as $field) {
  85. $ret[$field] = $info[$field];
  86. }
  87. $ret['cache_entries'] = count($info['cache_list']);
  88. $ret['deleted_entries'] = count($info['deleted_list']);
  89. return $ret;
  90. }