You are here

function nagios_session_count in Nagios Monitoring 8

Counts how many users are active on the site.

Counts how many users have sessions which have been active since the specified time. Can count either anonymous sessions or authenticated sessions.

@todo There are mostly no anonymous sessions anymore. Split this into a separate module providing proper user statistics.

Parameters

int $timestamp: A Unix timestamp. Users who have been active since this time will be counted. The default is 0, which counts all existing sessions.

bool $anonymous: TRUE counts only anonymous users. FALSE counts only authenticated users.

Return value

int The number of users with sessions.

2 calls to nagios_session_count()
nagios_check_session_anon in ./nagios.module
Report the number of anonymous sessions.
nagios_check_session_auth in ./nagios.module
Report the number of logged in sessions.

File

./nagios.module, line 864
Main file for Nagios service monitoring.

Code

function nagios_session_count($timestamp = 0, $anonymous = TRUE) {
  $conn = Drupal::database();
  $query = $conn
    ->select('sessions');
  $query
    ->addExpression('COUNT(sid)', 'count');
  $query
    ->condition('timestamp', $timestamp, '>=');
  $query
    ->condition('uid', 0, $anonymous ? '=' : '>');
  return (int) $query
    ->execute()
    ->fetchField();
}