This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
status.blade.php
executable file
·231 lines (223 loc) · 8.37 KB
/
status.blade.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
<!doctype html>
<html lang="zh-cn">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/yeti/bootstrap.min.css">
<title>一言 - 状态统计</title>
<style>
.lead {
color: #6f6f6f;
margin-bottom: 21px;
font-size: 22.5px;
font-weight: 300;
line-height: 1.4;
}
footer {
background-color: #333;
text-align: center;
padding-top: 0.5em;
padding-bottom: 0.5em;
position: absolute;
width: 100%;
color: #fff;
}
</style>
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-106578243-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments)
};
gtag('js', new Date());
gtag('config', 'UA-106578243-1');
</script>
</head>
<body style="position: relative;">
<div class="container">
<div class="row mt-5">
<div class="col-lg-12">
<h1>一言状态统计</h1>
<p class="lead">
为了采集使用状况, 一言会记录接口请求的详细信息。出于透明互联网的共同目的, 我们在此将信息公开。
</p>
<p class="alert alert-info">
由于目前统计存在一些问题,暂时无法稳定对外展示,故暂时关闭,敬请谅解。
</p>
<!--
<p class="alert alert-info">
当前服务器时间: <i id="server_time"></i>
</p>
-->
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div id="index" data-chart="index"></div>
<p>
<strong>请求统计</strong><br />
记录接口请求数, 并分时段绘制统计图表。
</p>
</div>
</div>
<div class="row mt-5">
<div class="col-lg-7">
<div id="pastFiveMinute" data-chart="pastFiveMinute"></div>
<p>
<strong>实时请求</strong><br />
通过展现过去 5 分钟的请求数目, 以达到动态展现请求变化的目的。
</div>
<div class="col-lg-4 offset-lg-1">
<div class="card">
<div class="card-header">
总数统计
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">总数: <i id="total"></i></li>
<li class="list-group-item">过去一分钟: <i id="pastMinute"></i></li>
<li class="list-group-item">过去一小时: <i id="pastHour"></i></li>
<li class="list-group-item">过去一天: <i id="pastDay"></i></li>
</ul>
</div>
</div>
</div>
</div>
<div class="mt-3">
<footer>© 2018 Moecraft All Rights Reserved. API Powered by Teng-koa.</footer>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@antv/[email protected]/dist/g2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@antv/[email protected]/dist/data-set.min.js"></script>
<!--[if IE]>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/promise.umd.min.js"></script>
<![endif]-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/fetch.js" integrity="sha256-VpQSBEw4wr6j5/6GsK33LrAE6Eq6+/Tq3JUbcCak6XY=" crossorigin="anonymous"></script>
<script>
var chart = {};
chart.index = new G2.Chart({
container: 'index',
forceFit: true,
height: 400,
padding: ["auto", "auto", "auto", "auto"]
});
chart.online = new G2.Chart({
container: 'pastFiveMinute',
forceFit: true,
height: 320,
padding: ["auto", "auto", "auto", "auto"]
})
var maps = [];
var ds = new DataSet();
var index_dv = ds.createView().source(maps);
index_dv.transform({
type: 'fold',
fields: ['all', 'v1.hitokoto.cn', 'api.hitokoto.cn', 'sslapi.hitokoto.cn'],
key: 'API',
value: 'requests'
});
var online_dv = ds.createView().source(maps);
online_dv.transform({
type: 'fold',
fields: ['请求数'],
key: 'API',
value: 'requests'
})
chart.index.changeData(index_dv, {
time: {
range: [0, 1]
}
});
chart.index.tooltip({
crosshairs: {
type: 'line'
}
});
chart.online.changeData(online_dv, {
time: {
range: [0, 1]
}
});
chart.online.tooltip({
crosshairs: {
type: 'line'
}
});
chart.index.axis('requests');
chart.index.line().position('time*requests').color('API').shape('smooth');
chart.index.point().position('time*requests').color('API').size(4).shape('circle').style({
stroke: '#fff',
lineWidth: 1
});
chart.index.render();
chart.online.axis('oneline');
chart.online.line().position('time*requests').color('API').shape('smooth');
chart.online.point().position('time*requests').color('API').size(4).shape('circle').style({
stroke: '#fff',
lineWidth: 1
});
chart.online.render();
function fetchStatus() {
fetch("https://v1.hitokoto.cn/status")
.then(function(response) {
return response.json();
})
.then(function(data) {
// Update Count
$('#total').text(data.requests.all.total || '暂无数据');
$('#pastMinute').text(data.requests.all.pastMinute || '暂无数据');
$('#pastHour').text(data.requests.all.pastHour || '暂无数据');
$('#pastDay').text(data.requests.all.pastDay || '暂无数据');
var hour = new Date(data.ts);
$("#server_time").text(hour.toISOString());
maps = [];
for (var x = 23, tmp, mer; x >=0; x--) {
tmp = new Date(hour.getTime() - (x * 1000 * 60 * 60)).getHours();
maps.push({
time: tmp + ':00',
all: data.requests.all.dayMap[x] || 0,
"v1.hitokoto.cn": data.requests.hosts["v1.hitokoto.cn"].dayMap[x] || 0,
"api.hitokoto.cn": data.requests.hosts["api.hitokoto.cn"].dayMap[x] || 0,
"sslapi.hitokoto.cn": data.requests.hosts["sslapi.hitokoto.cn"].dayMap[x] || 0
});
}
online = [];
for (var x=4, tmp, mer; x>= 0; x--) {
tmp = new Date(hour.getTime() - (x * 1000 * 60))
online.push({
time: tmp.getHours() + ':' + (tmp.getMinutes().toString().length === 1 ? '0' + tmp.getMinutes() : tmp.getMinutes()),
"请求数": data.requests.all.FiveMinuteMap[x] || 0
})
}
console.log(online)
var ds = new DataSet();
var index_dv = ds.createView().source(maps);
index_dv.transform({
type: 'fold',
fields: ['all', 'v1.hitokoto.cn', 'api.hitokoto.cn', 'sslapi.hitokoto.cn'],
key: 'API',
value: 'requests'
});
chart.index.changeData(index_dv);
var online_dv = ds.createView().source(online);
online_dv.transform({
type: 'fold',
fields: ['请求数'],
key: 'API',
value: 'requests'
});
chart.online.changeData(online_dv);
window.setTimeout(fetchStatus, 5000);
});
}
fetchStatus();
</script>
</body>
</html>