-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcollect.php
More file actions
84 lines (64 loc) · 2.46 KB
/
collect.php
File metadata and controls
84 lines (64 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
require_once './vendor/autoload.php';
require_once 'conf.php';
require_once 'lib.php';
date_default_timezone_set($timezone);
$data = getCurrentData();
$day = date('Y-m-d');
$time = date('H:i');
$timestamp = "$day $time:00";
/*
$exec_loads = sys_getloadavg();
$exec_cores = trim(shell_exec("grep -P '^processor' /proc/cpuinfo|wc -l"));
$cpu = round($exec_loads[1]/($exec_cores + 1)*100, 0);
$exec_free = explode("\n", trim(shell_exec('free')));
$get_mem = preg_split("/[\s]+/", $exec_free[1]);
$mem = round($get_mem[2]/$get_mem[1]*100, 0);
*/
if ($db_name != "")
{
// put data into database
$conn = new mysqli($db_server, $db_user, $db_password, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "CREATE TABLE IF NOT EXISTS bbb_usage_data (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
ts TIMESTAMP NOT NULL,
server_count SMALLINT,
server VARCHAR(255),
meeting_count SMALLINT UNSIGNED,
participant_count SMALLINT UNSIGNED,
voice_participant_count SMALLINT UNSIGNED,
video_count SMALLINT UNSIGNED,
breakout_count SMALLINT UNSIGNED,
cpu SMALLINT UNSIGNED,
mem SMALLINT UNSIGNED,
netout INT (11) UNSIGNED,
netin INT (11) UNSIGNED,
INDEX ts_index (ts)
)";
$ressql = $conn->query($sql);
$server_count = count ($data);
if ($server_count == 0)
{
$sql = "INSERT INTO bbb_usage_data (ts, server_count)
VALUES ('$timestamp', 0)";
$ressql = $conn->query($sql);
}
else
{
foreach ($data as $server => $stats)
{
$mc = $stats['meeting_count'];
$pc = $stats['participant_count'];
$vpc = $stats['voice_participant_count'];
$vc = $stats['video_count'];
$bc = $stats['breakout_count'];
$sql = "INSERT INTO bbb_usage_data (ts, server_count, server, meeting_count, participant_count, voice_participant_count, video_count, breakout_count)
VALUES ('$timestamp', $server_count, '$server', $mc, $pc, $vpc, $vc, $bc)";
$ressql = $conn->query($sql);
}
}
$conn->close();
}