"'%d'", ]; /* Ignore anon and auth roles: no user carries them in users_roles anyway. */ $sq = << 2 ORDER BY 2 SQL; $q = db_query($sq); $roles = []; foreach ($q as $o) { $roles[$o->rid] = $o->name; } $ret = [ '#title' => t('Drupal'), '#description' => t('Graphs about Drupal core'), 'munin_core' => [ '#title' => t('Core user-related statistics'), '#info' => t('Core statistics regarding users and sessions.'), '#graph_vlabel' => t('Anon/blocked (-) vs Logged/Active (+)'), 'anon_current' => $int + [ '#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 + [ '#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 display as negative.'), '#negative' => 'anon_current', ], 'user_blocked_count' => $int + [ '#label' => t('Users, blocked'), '#type' => MUNIN_API_GAUGE, '#info' => t('The number of users with status = 0'), '#graph' => 'no', ], 'user_active_count' => $int + [ '#label' => t('Users'), '#type' => MUNIN_API_GAUGE, '#info' => t('The number of users. Blocked users display as negative.'), '#negative' => 'user_blocked_count', ], ], 'munin_core_roles' => [ '#title' => t('Core role statistics'), '#info' => t('Information about users roles.'), '#graph_vlabel' => t('Users by roles'), ], 'munin_core_content' => [ '#title' => t('Core content statistics'), '#info' => t('Information about nodes, comments and terms.'), '#graph_vlabel' => t('Entries unpub(-)/pub(+)'), 'node_count_unpub' => $int + [ '#label' => t('Nodes, unpublished'), '#type' => MUNIN_API_GAUGE, '#graph' => 'no', ], 'node_count' => $int + [ '#label' => t('Nodes'), '#info' => t('Unpublished nodes display as negative.'), '#type' => MUNIN_API_GAUGE, '#negative' => 'node_count_unpub', ], 'comment_count_unpub' => $int + [ '#label' => t('Comments, unpublished'), '#type' => MUNIN_API_GAUGE, '#graph' => 'no', ], 'comment_count' => $int + [ '#label' => t('Comments'), '#info' => t('Unpublished comments display as negative.'), '#type' => MUNIN_API_GAUGE, '#negative' => 'comment_count_unpub', ], ], 'munin_core_taxonomy' => [ '#title' => t('Core taxonomy statistics'), '#info' => t('Core statistics regarding taxonomy.'), '#graph_vlabel' => t('Vocabularies (-)/Terms (+)'), 'vocab_count' => $int + [ '#label' => t('Vocabularies'), '#info' => t('Vocabularies'), '#type' => MUNIN_API_GAUGE, ], 'term_count' => $int + [ '#label' => t('Terms'), '#info' => t('Total terms across all vocabularies'), '#type' => MUNIN_API_GAUGE, ], ], ]; foreach ($roles as $role) { $machine_name = str_replace(' ', '_', $role); $ret['munin_core_roles']['role_' . $machine_name] = $int + [ '#label' => $role, '#info' => t('Number of users with the @role role', ['@role' => $role]), '#type' => MUNIN_API_GAUGE, ]; } variable_set('munin_core_roles', $roles); 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 = << 0 GROUP BY 2 SQL; $result = db_query($sq); $users = [0 => 0, 1 => 0]; foreach ($result as $row) { $users[$row->status] = $row->cnt; } $ret['user_active_count'] = $users[1]; $ret['user_blocked_count'] = $users[0]; $sq = << 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60 SQL; $ret['user_current'] = db_query($sq) ->fetchField(); $sq = <<= UNIX_TIMESTAMP() - 5*60 SQL; $ret['anon_current'] = db_query($sq) ->fetchField(); break; case 'munin_core_roles': $roles = variable_get('munin_core_roles', []); $sq = << array_keys($roles)]); foreach ($q as $o) { $name = str_replace(' ', '_', $o->name); // Can be NULL. $ret['role_' . $name] = empty($o->cnt) ? 0 : $o->cnt; } break; case 'munin_core_content': $ret = array( 'node_count_unpub' => 0, 'node_count' => 0, 'comment_count_unpub' => 0, 'comment_count' => 0, ); $sq = <<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); } } // Unlike node, comment may be disabled. if (module_exists('comment')) { $sq = <<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); } } } break; case 'munin_core_taxonomy': if (!module_exists('taxonomy')) { $ret['term_count'] = 0; $ret['vocab_count'] = 0; } else { $sq = 'SELECT COUNT(*) FROM {taxonomy_term_data}'; $ret['term_count'] = db_query($sq)->fetchField(); $sq = 'SELECT COUNT(*) FROM {taxonomy_vocabulary}'; $ret['vocab_count'] = db_query($sq)->fetchField(); } break; } return $ret; }