munin_apc.module 3.6 KB

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