munin_core.module 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. 'munin_core' => array(
  25. '#title' => t('Drupal core'),
  26. '#info' => t('Collect core information from a Drupal instance. All counters are integer-rounded.'),
  27. 'user_current' => $int + array(
  28. '#label' => t('Currently logged-in users'),
  29. '#type' => MUNIN_API_GAUGE,
  30. '#info' => t('The number of sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
  31. ),
  32. 'user_count' => $int + array(
  33. '#label' => t('Number of users'),
  34. '#type' => MUNIN_API_GAUGE,
  35. '#info' => t('The total number of users, whatever their status'),
  36. ),
  37. 'user_active_count' => $int + array(
  38. '#label' => t('Number of active users'),
  39. '#type' => MUNIN_API_GAUGE,
  40. '#info' => t('The number of users with status = 1'),
  41. ),
  42. 'user_blocked_count' => $int + array(
  43. '#label' => t('Number of blocked users'),
  44. '#type' => MUNIN_API_GAUGE,
  45. '#info' => t('The number of users with status = 0'),
  46. ),
  47. 'node_count' => $int + array(
  48. '#label' => t('Number of published nodes.'),
  49. '#type' => MUNIN_API_GAUGE,
  50. ),
  51. 'comment_count' => $int + array(
  52. '#label' => t('Number of published comments.'),
  53. '#type' => MUNIN_API_GAUGE,
  54. ),
  55. ),
  56. );
  57. return $ret;
  58. }
  59. /**
  60. * Implements hook_munin_api_fetch().
  61. */
  62. function munin_core_munin_api_fetch() {
  63. $sq = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u GROUP BY 2';
  64. $result = db_query($sq);
  65. while ($row = db_fetch_object($result)) {
  66. $users[$row->status] = $row->cnt;
  67. }
  68. $ret['user_active_count'] = $users[1];
  69. $ret['user_blocked_count'] = $users[0];
  70. $ret['user_count'] = $users[0] + $users[1];
  71. $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.timestamp >= UNIX_TIMESTAMP() - 5*60';
  72. $ret['user_current'] = db_result(db_query($sq));
  73. $sq = 'SELECT COUNT(*) cnt FROM {node} n WHERE n.status = 1';
  74. // No db_rewrite_sql(): this is an administrative mechanism
  75. $ret['node_count'] = db_result(db_query($sq));
  76. $sq = 'SELECT COUNT(*) cnt FROM {comments} c WHERE c.status = 0';
  77. // No db_rewrite_sql(): this is an administrative mechanism
  78. $ret['comment_count'] = db_result(db_query($sq));
  79. return $ret;
  80. }