12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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(
- '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('Currently logged-in users'),
- '#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.'),
- ),
- '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().
- */
- function munin_core_munin_api_fetch() {
- $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.timestamp >= UNIX_TIMESTAMP() - 5*60';
- $ret['user_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;
- }
|