123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- // $Id$
- /**
- * @file
- * Core Drupal instrumentation for Munin
- *
- * @author Frederic G. MARAND
- *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
- *
- * Licensed under the General Public License version 2 or later.
- */
- /**
- * Implements hook_munin_api_info().
- *
- * @return
- * An array of Munin probes informations, index by probe name.
- */
- function munin_core_munin_api_info() {
- $int = array(
- '#graph_printf' => "'%d'",
- );
- $ret = array(
- '#title' => t('Drupal'),
- '#description' => t('Graphs about Drupal core'),
- 'munin_core' => array(
- '#title' => t('Core user-related statistics'),
- '#info' => t('Core statistics regarding users and sessions.'),
- 'anon_current' => $int + array(
- '#label' => t('Sessions, anon'),
- '#type' => MUNIN_API_GAUGE,
- '#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.'),
- '#graph' => 'no',
- ),
- 'user_current' => $int + array(
- '#label' => t('Sessions'),
- '#type' => MUNIN_API_GAUGE,
- '#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. Anonymous sessions dispaly as negative.'),
- '#negative' => 'anon_current',
- ),
- 'user_blocked_count' => $int + array(
- '#label' => t('Users, blocked'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('The number of users with status = 0'),
- '#graph' => 'no',
- ),
- 'user_active_count' => $int + array(
- '#label' => t('Users'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('The number of users. Blocked users display as negative.'),
- '#negative' => 'user_blocked_count',
- ),
- ),
- 'munin_core_content' => array(
- '#title' => t('Core content statistics'),
- '#info' => t('Information about nodes, comments and terms.'),
- '#graph_vlabel' => t('Number of entries'),
- 'node_count_unpub' => $int + array(
- '#label' => t('Nodes, unpublished'),
- '#type' => MUNIN_API_GAUGE,
- '#graph' => 'no',
- ),
- 'node_count' => $int + array(
- '#label' => t('Nodes'),
- '#info' => t('Unpublished nodes display as negative.'),
- '#type' => MUNIN_API_GAUGE,
- '#negative' => 'node_count_unpub',
- ),
- 'comment_count_unpub' => $int + array(
- '#label' => t('Comments, unpublished'),
- '#type' => MUNIN_API_GAUGE,
- '#graph' => 'no',
- ),
- 'comment_count' => $int + array(
- '#label' => t('Comments'),
- '#info' => t('Unpublished comments display as negative.'),
- '#type' => MUNIN_API_GAUGE,
- '#negative' => 'comment_count_unpub',
- ),
- 'term_count' => $int + array(
- '#label' => t('Terms'),
- '#type' => MUNIN_API_GAUGE,
- ),
- ),
- );
- return $ret;
- }
- /**
- * Implements hook_munin_api_fetch().
- *
- * TODO Reduce the number of queries by integrating the filters.
- */
- function munin_core_munin_api_fetch($graph_name) {
- switch ($graph_name) {
- case 'munin_core':
- $sq = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u GROUP BY 2';
- $result = db_query($sq);
- while ($row = db_fetch_object($result)) {
- $users[$row->status] = $row->cnt;
- }
- $ret['user_active_count'] = $users[1];
- $ret['user_blocked_count'] = $users[0];
- $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid != 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
- $ret['user_current'] = db_result(db_query($sq));
- $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid = 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
- $ret['anon_current'] = db_result(db_query($sq));
- break;
- case 'munin_core_content':
- $ret = array(
- 'node_count_unpub' => 0,
- 'node_count' => 0,
- 'comment_count_unpub' => 0,
- 'comment_count' => 0,
- );
- $sq = 'SELECT COUNT(*) cnt, n.status FROM {node} n GROUP BY n.status';
- // No db_rewrite_sql(): this is an administrative mechanism
- $q = db_query($sq);
- while ($o = db_fetch_object($q)) {
- switch ($o->status) {
- case 0:
- $ret['node_count_unpub'] = $o->cnt;
- break;
- case 1:
- $ret['node_count'] = $o->cnt;
- break;
- default:
- watchdog('munin_core', 'Nodes with status @status reported: @count', array(
- '@status' => $o->status,
- '@count' => $o->cnt,
- ), WATCHDOG_NOTICE);
- }
- }
- $sq = 'SELECT COUNT(*) cnt, c.status FROM {comments} c GROUP BY c.status';
- $q = db_query($sq);
- // No db_rewrite_sql(): this is an administrative mechanism
- while ($o = db_fetch_object($q)) {
- switch ($o->status) {
- case 1:
- $ret['comment_count_unpub'] = $o->cnt;
- break;
- case 0:
- $ret['comment_count'] = $o->cnt;
- break;
- default:
- watchdog('munin_core', 'Comments with status @status reported: @count', array(
- '@status' => $o->status,
- '@count' => $o->cnt,
- ), WATCHDOG_NOTICE);
- }
- }
- $sq = 'SELECT COUNT(*) FROM {term_data}';
- $ret['term_count'] = db_result(db_query($sq));
- }
- return $ret;
- }
|