-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphCheck.php
265 lines (238 loc) · 6.53 KB
/
graphCheck.php
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
include("inc/startup.php");
if(!isLoggedIn())
{
header('HTTP/1.0 401 Unauthorized');
die;
}
//checkToken();
if(!is_numeric($_GET['cid']))
{
die;
}
else
{
$check = returnServiceCheck($_GET['cid']);
if($check)
{
if(!accessToCheck($check->id))
{
display_error("Access Denied","You have no access to this service check");
die;
}
}
else
{
display_error("Not Found","check not found");
}
}
global $m;
$dbname = MONGO_DB_CHECKS;
$dbm = $m->$dbname;
$cid = $_GET['cid'];
$user_id = $check->user_id;
$colname = $user_id."cid".$cid;
$collection = $dbm->$colname;
// check if we have data at all
$res = $collection->find(array('cid' => new MongoInt32($cid)))->limit(1);
if($res->count() < 1)
{
echo '<br />';
display_info("Propagation in Progress", "There is no data available yet for this check. Please check back in a few minutes");
die;
}
if(!is_numeric($_GET['timeframe']))
{
$start = time() - 86400;
$tlabel = "24 hours";
}
else
{
$start = time() - $_GET['timeframe'];
$tlabel = formatSeconds($_GET['timeframe']);
}
$end = time() - 60;
if($_GET['day'])
{
$_GET['day'] = str_replace("/",".",$_GET['day']);
$start = strtotime($_GET['day']);
$end = strtotime('+1 day', $start);
$tlabel = htmlspecialchars($_GET['day']);
}
$ytitle = "Response Time";
$hnum = 3;
$ymax = 20;
if($check->check_type == 1)
{
$label = "rta";
$labelh = "ms";
$cut = -3;
$ymax = 10000;
$setymax = false;
}
elseif($check->check_type == 5)
{
$ytitle = "Days to expire";
$label = "days";
$labelh = " days";
$cut = -3;
$ymax = 10000;
$setymax = false;
}
else
{
$label = "time";
$labelh = "s";
$cut = -4;
$ymax = 12;
$setymax = false;
}
$res = $collection->find(array('cid' => new MongoInt32($cid), 'time' => array('$gt' => new MongoInt32($start), '$lt' => new MongoInt32($end))))->sort(array('time' => 1));
$res = returnAverageMedianFrom($res,$label,$check->cinterval);
$graphdata = "";
foreach($res as $avg)
{
$time = $avg['time'] * 1000;
if($avg['avg'] != -10)
{
$graphdata.= '['.$time.','.number_format_global($avg['avg']).'],';
}
}
$graphdata = substr($graphdata,0,-1);
$multigraph = false;
?>
<script type="application/javascript">
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
<?php include("js/charttheme.js"); ?>
$(function () {
$('#graph').highcharts({
chart: {
zoomType: 'x',
spacingRight: 20,
animation: false,
shadow: false
},
credits: {
enabled: false
},
title: {
text: '<?php echo htmlspecialchars($check->check_name)?> <?php echo $check->check_desc?>',
x: -20 //center
},
plotOptions: {
line: {
marker: {
enabled: false
},
lineWidth: 0.8
},
series: {
turboThreshold: 0
},
area: {
lineWidth: 0.8,
marker: {
enabled: false
},
shadow: false,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
exporting: {
enabled: true,
sourceWidth: 1280,
sourceHeight: 400,
filename: '<?php echo htmlspecialchars($check->check_name)."_".$check->check_desc?>'
},
tooltip: {
formatter: function() {
if(this.point.customTooltip == 1)
{
return Highcharts.dateFormat('%d.%m.%y %H:%M', this.x) + '<br/> DOWNTIME REPORTED';
}
else
{
if(this.series.type == "flags")
{
return Highcharts.dateFormat('%d.%m.%y %H:%M', this.x) + '<br/> DOWNTIME REPORTED';
}
else
{
return Highcharts.dateFormat('%d.%m.%y %H:%M', this.x) + '<br/><b>'+this.series.name+'</b>: ' + Highcharts.numberFormat(this.y, <?php echo $hnum?>) + '<?php echo $labelh?>';
}
}
}
},
subtitle: {
text: 'Results from: <?php echo $tlabel?>',
x: -20
},
xAxis: {
type: 'datetime',
tickPixelInterval: 100,
ordinal: false,
labels: {
format: '{value:%d.%m.%y %H:%M} ',
align: 'right',
rotation: -70
},
<?php renderDowntimes($check->id); ?>
events:{
setExtremes: function(e) {
var xMin = e.min;
var xMax = e.max;
var from = Math.round(xMin/ 1000);
var to = Math.round(xMax/ 1000);
console.log("from: " + from + " to: " + to);
reRenderTables(from,to);
}
}
},
yAxis: {
<?php if( $setymax ) { ?>
max: <?php echo $ymax?>,
<?php } ?>
min: 0,
title: {
text: '<?php echo $ytitle?>'
}
},
series: [
<?php if(!$multigraph) { ?>
{
type: 'area',
name: '<?php echo $ytitle?>',
dataGrouping: {
enabled: true,
smoothed: false
},
fillColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
data: [<?php echo $graphdata?>],
tooltip: {
valueSuffix: '<?php echo $labelh?>'
}
},
<?php } else { echo $multigraph_series; }?>
]
});
});
})
console.log("start: <?php echo $start?> end: <?php echo $end?> ");
reRenderCheckTable(<?php echo $start ?>,<?php echo $end?>);
</script>