-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor-chart.php
181 lines (171 loc) · 5.69 KB
/
monitor-chart.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
<?php
/**
* web监控php-fpm status数据
* @author Cqiu
* @date 2018-1-5
*/
if (isset($_REQUEST['data'])) {
$url = 'http://xxx.com/status';
$r = [
'listen_queue' => 0,
//'max_listen_queue' => 0,
//'listen_queue_len' => 0,
'idle_processes' => 0,
'active_processes' => 0,
//'total_processes' => 0,
//'max_active_processes' => 0,
//'max_children_reached' => 0
];
$result = json_decode(file_get_contents($url . '?json'), 1);
foreach ($result as $k => $v) {
$k = strtr($k, ' ', '_');
isset($r[$k]) && $r[$k] = $v;
}
echo json_encode($r);
exit;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>php-fpm status监控</title>
<link rel="shortcut icon" href="https://tool.lu/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* css 代码 */
</style>
<!-- <script src="https://img.hcharts.cn/jquery/jquery-1.8.3.min.js"></script> -->
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/highstock/6.0.3/highstock.js"></script>
<!-- <script src="https://img.hcharts.cn/highstock/highstock.js"></script> -->
<!-- <script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script> -->
<!-- <script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script> -->
</head>
<body>
<div id="container" style="min-width:400px;height:400px"></div>
<input type="button" id="on_off" value="start"/>
<script>
var dataQueue = [];
Highcharts.setOptions({
global: {
useUTC: false
}
});
// 填充初始值,才能有宽度
var fillData = []
, time = (new Date()).getTime()
, i;
for (i = -60; i <= 0; i += 1) {
fillData.push([time + i * 1000, 0]);
}
function activeLastPointToolip(chart) {
var points = chart.series[0].points;
chart.tooltip.refresh(points[points.length - 1]);
}
var chart = Highcharts.chart('container', {
chart: {
type: 'spline',
marginRight: 10,
events: {
load: function () {
var chart = this, series = this.series;
activeLastPointToolip(chart);
setInterval(function () {
var result = dataQueue.shift();
var time = (new Date()).getTime();
//如果没有数据,时间线会拉得很长,点不可看
if (!result) {
for (var i in series) {
series[i].addPoint([time, 0], true, true);
}
return;
}
var k = 0;
for (var i in result) {
if (i !== 'start_time') {
//console.log(i, result[i] * 1);
series[k].addPoint([
time,
result[i] * 1
], true, true);//, true
k++;
}
}
//activeLastPointToolip(chart);
}, 1000);
/*
var series = this.series[0],
chart = this;
activeLastPointToolip(chart);
setInterval(function () {
var x = (new Date()).getTime(), // 当前时间
y = Math.random(); // 随机值
series.addPoint([x, y], true, true);
activeLastPointToolip(chart);
}, 1000);
*/
}
}
},
title: {
text: 'php-fpm status实时数据'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: null
}
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
series: [{
"name": "listen_queue",
"data": fillData
}, {
"name": "idle_processes",
"data": fillData
}, {
"name": "active_processes",
"data": fillData
}]
});
var timer = null;
$.ajaxSetup({
timeout: 2000, // 2s
complete: function (XMLHttpRequest, textStatus) {
if (textStatus == 'timeout') {
console.log('timeout')
}
}
});
$('#on_off').click(function () {
var o = $(this);
if (o.val() == 'stop') {
o.val('start');
clearInterval(timer);
} else {
o.val('stop');
timer = setInterval(function () {
$.getJSON('?data=' + Math.random(), function (result) {
dataQueue.push(result);
});
}, 1000);
}
});
</script>
</body>
</html>