123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?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('Drupal core'),
- '#info' => t('Collect core information from a Drupal instance. All counters are integer-rounded.'),
- 'user_current' => $int + array(
- '#label' => t('Logged-in sessions'),
- '#type' => MUNIN_API_GAUGE,
- '#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.'),
- ),
- 'anon_current' => $int + array(
- '#label' => t('Anonymous sessions'),
- '#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.'),
- ),
- 'user_count' => $int + array(
- '#label' => t('Number of users'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('The total number of users, whatever their status'),
- ),
- 'user_active_count' => $int + array(
- '#label' => t('Number of active users'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('The number of users with status = 1'),
- ),
- 'user_blocked_count' => $int + array(
- '#label' => t('Number of blocked users'),
- '#type' => MUNIN_API_GAUGE,
- '#info' => t('The number of users with status = 0'),
- ),
- 'node_count' => $int + array(
- '#label' => t('Number of published nodes.'),
- '#type' => MUNIN_API_GAUGE,
- ),
- 'comment_count' => $int + array(
- '#label' => t('Number of published comments.'),
- '#type' => MUNIN_API_GAUGE,
- ),
- ),
- );
- return $ret;
- }
- /**
- * Implements hook_munin_api_fetch().
- *
- * Only one graph, so we can ignore the $graph_name parameter.
- */
- function munin_core_munin_api_fetch($graph_name) {
- $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];
- $ret['user_count'] = $users[0] + $users[1];
- $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));
- $sq = 'SELECT COUNT(*) cnt FROM {node} n WHERE n.status = 1';
- // No db_rewrite_sql(): this is an administrative mechanism
- $ret['node_count'] = db_result(db_query($sq));
- $sq = 'SELECT COUNT(*) cnt FROM {comments} c WHERE c.status = 0';
- // No db_rewrite_sql(): this is an administrative mechanism
- $ret['comment_count'] = db_result(db_query($sq));
- return $ret;
- }
|