122 lines
3.7 KiB
PHP
122 lines
3.7 KiB
PHP
<?php
|
|
date_default_timezone_set("Europe/Amsterdam");
|
|
|
|
$load = sys_getloadavg();
|
|
|
|
$l = array('loadavg' => $load[1]);
|
|
$out = '';
|
|
exec("grep '" . date('d/M/Y:H:i:', time() - 60) . "' /var/www/diweb/logs/mtinfo.dualinventive.com.access.log | wc -l", $out);
|
|
|
|
$l['reqs'] = intval(reset($out));
|
|
|
|
|
|
session_start();
|
|
require_once("support.inc.php");
|
|
require_once("../include/db.php");
|
|
require_once("../include/db_cust.php");
|
|
$database = 'di_zkl';
|
|
|
|
$db_info = read_database(DBCONFIG_DIR, 'di_zkl');
|
|
|
|
$db_data_handle = mysql_connect($db_info['host'], $db_info['user'], $db_info['passwd']);
|
|
if ($db_data_handle === FALSE) {
|
|
echo mysql_error();
|
|
exit(1);
|
|
}
|
|
|
|
mysql_select_db($db_info['database'], $db_data_handle);
|
|
if ($db_info['main']) {
|
|
$db_main_info = read_database(DBCONFIG_DIR, $db_info['main']);
|
|
$db_main_handle = mysql_connect($db_main_info['host'], $db_main_info['user'], $db_main_info['passwd'], true);
|
|
if ($db_main_handle === FALSE) {
|
|
echo mysql_error();
|
|
exit(1);
|
|
}
|
|
mysql_select_db($db_main_info['database'], $db_main_handle);
|
|
} else {
|
|
$db_main_handle = $db_data_handle;
|
|
$db_main_info = $db_info;
|
|
}
|
|
$i = 0;
|
|
$j = 0;
|
|
// Initial values
|
|
$sessions = array();
|
|
$user_info = array();
|
|
$valid_customers = array();
|
|
|
|
// Get all company down the pyramid
|
|
$customers = db_search_customers();
|
|
|
|
// Get all ids
|
|
if (is_array($customers)) {
|
|
foreach($customers as $customer) {
|
|
array_push($valid_customers, $customer['id']);
|
|
}
|
|
}
|
|
|
|
// Read session file content from database
|
|
$session_info = db_fetch_data("SELECT * FROM session WHERE expiration > UNIX_TIMESTAMP(NOW())");
|
|
$ids = array();
|
|
$appIds = array();
|
|
|
|
foreach($session_info as $session) {
|
|
// Find non-session char
|
|
if (stristr($session['id'], "_") === FALSE) {
|
|
// Decode session file content => Puts it in $_SESSION
|
|
session_decode($session['data']);
|
|
foreach ($_SESSION as $info => $val) {
|
|
if (isset($val['last_access']) && ($val['last_access'] > time()-60)) {
|
|
if (isset($val["preload_images"])) {
|
|
if (!in_array($info, $appIds)) {
|
|
$appIds[] = $info;
|
|
$j++;
|
|
}
|
|
} else {
|
|
if (!in_array($info, $ids)) {
|
|
$ids[] = $info;
|
|
$i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$l['onlineusers'] = $i;
|
|
$l['onlineappusers'] = $j;
|
|
|
|
$switchedProjects = db_fetch_data("SELECT
|
|
count(DISTINCT `pz`.`zkl`) as `num_lances`,
|
|
count(DISTINCT `s`.`id`) as `switch_tries_per_5min`,
|
|
(count(DISTINCT `pz`.`zkl`) * count(DISTINCT `s`.`id`)) as `total_switches`,
|
|
CONCAT(`p2`.`naam`, ', periode: ', `p`.`naam`) as `project_name_plus_period_name`,
|
|
`c`.`bedrijfsnaam` as `customer`,
|
|
`s`.`tijd` as `time`
|
|
FROM
|
|
`log_secure` `s`,
|
|
`mtinfo_main`.`project` `p`,
|
|
`mtinfo_main`.`klant` `c`,
|
|
`mtinfo_main`.`project` `p2`,
|
|
`mtinfo_main`.`project_zkl` `pz`
|
|
WHERE
|
|
`p`.`id` = `s`.`project` AND
|
|
`pz`.`project` = `s`.`project` AND
|
|
`p2`.`id` = `p`.`parent` AND
|
|
`c`.`id` = `p2`.`klant` AND
|
|
`s`.`reden`='inschakelen' AND
|
|
`s`.`tijd` > FROM_UNIXTIME(UNIX_TIMESTAMP()-60)
|
|
GROUP BY CONCAT(`s`.`project`, ' ', (UNIX_TIMESTAMP(`s`.`tijd`) DIV 300)) ORDER BY `s`.`tijd` ASC;");
|
|
|
|
$totalSwitches = 0;
|
|
if (is_array($switchedProjects)) {
|
|
foreach ($switchedProjects as $k => $v) {
|
|
$totalSwitches += $v['total_switches'];
|
|
}
|
|
}
|
|
$l['switches'] = $totalSwitches;
|
|
|
|
$l['released_rc'] = count(db_fetch("project", '*', "sstatus='vrijgegeven' AND type='RC' AND parent IS NULL"));
|
|
$l['released_regular'] = count(db_fetch("project", '*', "pstatus='gereed' AND type='normaal' and parent IS NULL and status not like '%afgesloten%'"));
|
|
|
|
echo json_encode($l);
|