mirror of https://github.com/cppla/ServerStatus
三网延迟丢包率计算算法bug修复
parent
338becb971
commit
bbd077b321
|
@ -19,9 +19,7 @@ go build .
|
|||
```
|
||||
|
||||
### TODO
|
||||
- 外网连接状态
|
||||
- 三网丢包计算
|
||||
- 三网延迟计算
|
||||
- IPV4 和 IPV6 状态
|
||||
- 其他算法优化
|
||||
|
||||
### 鸣谢
|
||||
|
|
|
@ -4,7 +4,7 @@ package main
|
|||
* Author: chn-student & cppla
|
||||
* 依赖于 gopstil 跨平台库
|
||||
* 编译版本:go 1.15.5
|
||||
* 时间: 20201202 (未完工)
|
||||
* 时间: 20201211
|
||||
* 说明: 默认情况下修改server和user就可以了。丢包率监测方向可以自定义,例如:CU = "www.facebook.com"。
|
||||
****************************/
|
||||
|
||||
|
@ -54,9 +54,9 @@ type ClientInfo struct {
|
|||
Ping10010 float64 `json:"ping_10010"`
|
||||
Ping10086 float64 `json:"ping_10086"`
|
||||
Ping189 float64 `json:"ping_189"`
|
||||
Time10010 float64 `json:"time_10010"`
|
||||
Time10086 float64 `json:"time_10086"`
|
||||
Time189 float64 `json:"time_189"`
|
||||
Time10010 uint64 `json:"time_10010"`
|
||||
Time10086 uint64 `json:"time_10086"`
|
||||
Time189 uint64 `json:"time_189"`
|
||||
TCP uint64 `json:"tcp"`
|
||||
UDP uint64 `json:"udp"`
|
||||
CPU float64 `json:"cpu"`
|
||||
|
@ -85,9 +85,9 @@ func NewDefaultClientInfo() ClientInfo {
|
|||
Ping10010: 0.0,
|
||||
Ping10086: 0.0,
|
||||
Ping189: 0.0,
|
||||
Time10010: 0.0,
|
||||
Time10086: 0.0,
|
||||
Time189: 0.0,
|
||||
Time10010: 0,
|
||||
Time10086: 0,
|
||||
Time189: 0,
|
||||
TCP: 0,
|
||||
UDP: 0,
|
||||
CPU: 0.0,
|
||||
|
@ -217,6 +217,7 @@ func getNetworkStatus() {
|
|||
} else {
|
||||
clientInfo.IpStatus = true
|
||||
}
|
||||
count = 0
|
||||
}
|
||||
|
||||
func str2bytes(s string) []byte {
|
||||
|
@ -303,9 +304,9 @@ func main() {
|
|||
pingValueCU := NewPingValue()
|
||||
pingValueCT := NewPingValue()
|
||||
pingValueCM := NewPingValue()
|
||||
pingValueCU.Get()
|
||||
pingValueCT.Get()
|
||||
pingValueCM.Get()
|
||||
pingValueCU.RunCU()
|
||||
pingValueCT.RunCT()
|
||||
pingValueCM.RunCM()
|
||||
netSpeed.Run()
|
||||
for {
|
||||
clientInfo.MemoryTotal = ram.Info().Total / 1024 // 需要转单位
|
||||
|
@ -326,7 +327,6 @@ func main() {
|
|||
clientInfo.Ping10086, clientInfo.Time10086 = pingValueCM.Get()
|
||||
clientInfo.Ping189, clientInfo.Time189 = pingValueCT.Get()
|
||||
clientInfo.Ping10010, clientInfo.Time10010 = pingValueCU.Get()
|
||||
//TODO:三网延迟和丢包率算法存在问题
|
||||
//fmt.Println(clientInfo.Time10086)
|
||||
//结构体转json字符串
|
||||
data, err := jsoniter.MarshalToString(&clientInfo)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
type PingValue struct {
|
||||
ping float64
|
||||
ping uint64
|
||||
lostRate float64
|
||||
stop chan struct{}
|
||||
mtx sync.Mutex
|
||||
|
@ -36,6 +36,7 @@ func (pingValue *PingValue) RunCU() {
|
|||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
pingValue.mtx.Lock()
|
||||
t := time.Now()
|
||||
conn , err := net.DialTimeout("tcp",CU_ADDR,defaulttimeout)
|
||||
defer conn.Close()
|
||||
|
@ -53,7 +54,7 @@ func (pingValue *PingValue) RunCU() {
|
|||
if allPacket > 100 {
|
||||
pingValue.lostRate = float64(lostPacket/allPacket)
|
||||
}
|
||||
pingValue.ping = float64(diffTime * time.Second)
|
||||
pingValue.ping = uint64(diffTime/time.Millisecond)
|
||||
resetTime := uint64(time.Since(startTime) * time.Second)
|
||||
if resetTime > 3600 {
|
||||
lostPacket = 0
|
||||
|
@ -80,6 +81,7 @@ func (pingValue *PingValue) RunCT() {
|
|||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
pingValue.mtx.Lock()
|
||||
t := time.Now()
|
||||
conn , err := net.DialTimeout("tcp",CT_ADDR,defaulttimeout)
|
||||
defer conn.Close()
|
||||
|
@ -95,7 +97,7 @@ func (pingValue *PingValue) RunCT() {
|
|||
if allPacket > 100 {
|
||||
pingValue.lostRate = float64(lostPacket/allPacket)
|
||||
}
|
||||
pingValue.ping = float64(diffTime * time.Second)
|
||||
pingValue.ping = uint64(diffTime/time.Millisecond)
|
||||
resetTime := uint64(time.Since(startTime) * time.Second)
|
||||
if resetTime > 3600 {
|
||||
lostPacket = 0
|
||||
|
@ -122,6 +124,7 @@ func (pingValue *PingValue) RunCM() {
|
|||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
pingValue.mtx.Lock()
|
||||
t := time.Now()
|
||||
conn , err := net.DialTimeout("tcp",CT_ADDR,defaulttimeout)
|
||||
defer conn.Close()
|
||||
|
@ -137,7 +140,7 @@ func (pingValue *PingValue) RunCM() {
|
|||
if allPacket > 100 {
|
||||
pingValue.lostRate = float64(lostPacket/allPacket)
|
||||
}
|
||||
pingValue.ping = float64(diffTime * time.Second)
|
||||
pingValue.ping = uint64(diffTime/time.Millisecond)
|
||||
resetTime := uint64(time.Since(startTime) * time.Second)
|
||||
if resetTime > 3600 {
|
||||
lostPacket = 0
|
||||
|
@ -154,7 +157,7 @@ func (pingValue *PingValue) Stop() {
|
|||
close(pingValue.stop)
|
||||
}
|
||||
|
||||
func (pingValue *PingValue) Get() (float64,float64) {
|
||||
func (pingValue *PingValue) Get() (float64,uint64) {
|
||||
pingValue.mtx.Lock()
|
||||
defer pingValue.mtx.Unlock()
|
||||
return pingValue.lostRate,pingValue.ping
|
||||
|
|
|
@ -86,6 +86,7 @@ function uptime() {
|
|||
$("#servers").append(
|
||||
"<tr id=\"r" + i + "\" data-toggle=\"collapse\" data-target=\"#rt" + i + "\" class=\"accordion-toggle " + hack + "\">" +
|
||||
"<td id=\"online4\"><div class=\"progress\"><div style=\"width: 100%;\" class=\"progress-bar progress-bar-warning\"><small>加载中</small></div></div></td>" +
|
||||
"<td id=\"host\">加载中</td>" +
|
||||
"<td id=\"ip_status\"><div class=\"progress\"><div style=\"width: 100%;\" class=\"progress-bar progress-bar-warning\"><small>加载中</small></div></div></td>" +
|
||||
"<td id=\"name\">加载中</td>" +
|
||||
"<td id=\"type\">加载中</td>" +
|
||||
|
@ -146,10 +147,10 @@ function uptime() {
|
|||
// mh361 or mh370, mourn mh370, 2014-03-08 01:20 lost from all over the world.
|
||||
if (result.servers[i].ip_status) {
|
||||
TableRow.children["ip_status"].children[0].children[0].className = "progress-bar progress-bar-success";
|
||||
TableRow.children["ip_status"].children[0].children[0].innerHTML = "<small>MH361</small>";
|
||||
TableRow.children["ip_status"].children[0].children[0].innerHTML = "<small>Normal</small>";
|
||||
} else {
|
||||
TableRow.children["ip_status"].children[0].children[0].className = "progress-bar progress-bar-danger";
|
||||
TableRow.children["ip_status"].children[0].children[0].innerHTML = "<small>MH370</small>";
|
||||
TableRow.children["ip_status"].children[0].children[0].innerHTML = "<small>Lost</small>";
|
||||
}
|
||||
|
||||
// Name
|
||||
|
@ -158,6 +159,9 @@ function uptime() {
|
|||
// Type
|
||||
TableRow.children["type"].innerHTML = result.servers[i].type;
|
||||
|
||||
//Host
|
||||
TableRow.children["host"].innerHTML = result.servers[i].host;
|
||||
|
||||
// Location
|
||||
TableRow.children["location"].innerHTML = result.servers[i].location;
|
||||
if (!result.servers[i].online4 && !result.servers[i].online6) {
|
||||
|
@ -425,3 +429,77 @@ window.onunload = function(e) {
|
|||
var cookie = readCookie("style");
|
||||
var title = cookie ? cookie : getPreferredStyleSheet();
|
||||
setActiveStyleSheet(title);
|
||||
|
||||
// Excel 报表导出,参考https://www.cnblogs.com/zhenggaowei/p/11732170.html
|
||||
var fileName = '';
|
||||
|
||||
|
||||
function json2Excel() {
|
||||
var wopts = {
|
||||
bookType: 'xlsx',
|
||||
bookSST: false,
|
||||
type: 'binary'
|
||||
};
|
||||
var workBook = {
|
||||
SheetNames: ['Sheet1'],
|
||||
Sheets: {},
|
||||
Props: {}
|
||||
};
|
||||
/**
|
||||
TODO:
|
||||
多余信息现在隐藏不导出,后期再优化
|
||||
Author:CHN-STUDENT <chn-student@outlook.com> 2020.12.01
|
||||
*/
|
||||
|
||||
var elements1 = document.getElementsByClassName("expandRow even");
|
||||
var elements2 =document.getElementsByClassName("expandRow odd");
|
||||
console.log(elements2)
|
||||
Array.prototype.forEach.call(elements1, function (element) {
|
||||
element.style.display = 'none';
|
||||
});
|
||||
Array.prototype.forEach.call(elements2, function (element) {
|
||||
element.style.display = 'none';
|
||||
});
|
||||
workBook.Sheets['Sheet1'] = XLSX.utils.table_to_sheet(document.getElementById('info'),{display:true});
|
||||
|
||||
//3、XLSX.write() 开始编写Excel表格
|
||||
//4、changeData() 将数据处理成需要输出的格式
|
||||
saveAs(new Blob([changeData(XLSX.write(workBook, wopts))], { type: 'application/octet-stream' }))
|
||||
Array.prototype.forEach.call(elements1, function (element) {
|
||||
element.style = '';
|
||||
});
|
||||
Array.prototype.forEach.call(elements2, function (element) {
|
||||
element.style = '';
|
||||
});
|
||||
}
|
||||
function changeData(s) {
|
||||
//如果存在ArrayBuffer对象(es6) 最好采用该对象
|
||||
if (typeof ArrayBuffer !== 'undefined') {
|
||||
|
||||
//1、创建一个字节长度为s.length的内存区域
|
||||
var buf = new ArrayBuffer(s.length);
|
||||
|
||||
//2、创建一个指向buf的Unit8视图,开始于字节0,直到缓冲区的末尾
|
||||
var view = new Uint8Array(buf);
|
||||
|
||||
//3、返回指定位置的字符的Unicode编码
|
||||
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
|
||||
return buf;
|
||||
|
||||
} else {
|
||||
var buf = new Array(s.length);
|
||||
for (var i = 0; i != s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
function saveAs(obj, fileName) {//当然可以自定义简单的下载文件实现方式
|
||||
var tmpa = document.createElement("a");
|
||||
tmpa.download = fileName ? fileName + '.xlsx' : new Date().getTime() + '.xlsx';
|
||||
tmpa.href = URL.createObjectURL(obj); //绑定a标签
|
||||
tmpa.click(); //模拟点击实现下载
|
||||
|
||||
setTimeout(function () { //延时释放
|
||||
URL.revokeObjectURL(obj); //用URL.revokeObjectURL()来释放这个object URL
|
||||
}, 100);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue