munin_core.module 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Core Drupal 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_core_munin_api_info() {
  20. $int = array(
  21. '#graph_printf' => '%d',
  22. );
  23. $ret = array(
  24. '#title' => t('Drupal'),
  25. '#description' => t('Graphs about Drupal core'),
  26. 'munin_core' => array(
  27. '#title' => t('Drupal core'),
  28. '#info' => t('Collect core information from a Drupal instance. All counters are integer-rounded.'),
  29. 'user_current' => $int + array(
  30. '#label' => t('Logged-in sessions'),
  31. '#type' => MUNIN_API_GAUGE,
  32. '#info' => t('The number of logged-in sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
  33. ),
  34. 'anon_current' => $int + array(
  35. '#label' => t('Anonymous sessions'),
  36. '#type' => MUNIN_API_GAUGE,
  37. '#info' => t('The number of anonymous sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
  38. ),
  39. 'user_count' => $int + array(
  40. '#label' => t('Number of users'),
  41. '#type' => MUNIN_API_GAUGE,
  42. '#info' => t('The total number of users, whatever their status'),
  43. ),
  44. 'user_active_count' => $int + array(
  45. '#label' => t('Number of active users'),
  46. '#type' => MUNIN_API_GAUGE,
  47. '#info' => t('The number of users with status = 1'),
  48. ),
  49. 'user_blocked_count' => $int + array(
  50. '#label' => t('Number of blocked users'),
  51. '#type' => MUNIN_API_GAUGE,
  52. '#info' => t('The number of users with status = 0'),
  53. ),
  54. 'node_count' => $int + array(
  55. '#label' => t('Number of published nodes.'),
  56. '#type' => MUNIN_API_GAUGE,
  57. ),
  58. 'comment_count' => $int + array(
  59. '#label' => t('Number of published comments.'),
  60. '#type' => MUNIN_API_GAUGE,
  61. ),
  62. ),
  63. );
  64. return $ret;
  65. }
  66. /**
  67. * Implements hook_munin_api_fetch().
  68. *
  69. * Only one graph, so we can ignore the $graph_name parameter.
  70. */
  71. function munin_core_munin_api_fetch($graph_name) {
  72. $sq = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u GROUP BY 2';
  73. $result = db_query($sq);
  74. while ($row = db_fetch_object($result)) {
  75. $users[$row->status] = $row->cnt;
  76. }
  77. $ret['user_active_count'] = $users[1];
  78. $ret['user_blocked_count'] = $users[0];
  79. $ret['user_count'] = $users[0] + $users[1];
  80. $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid != 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
  81. $ret['user_current'] = db_result(db_query($sq));
  82. $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid = 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
  83. $ret['anon_current'] = db_result(db_query($sq));
  84. $sq = 'SELECT COUNT(*) cnt FROM {node} n WHERE n.status = 1';
  85. // No db_rewrite_sql(): this is an administrative mechanism
  86. $ret['node_count'] = db_result(db_query($sq));
  87. $sq = 'SELECT COUNT(*) cnt FROM {comments} c WHERE c.status = 0';
  88. // No db_rewrite_sql(): this is an administrative mechanism
  89. $ret['comment_count'] = db_result(db_query($sq));
  90. return $ret;
  91. }