diff --git a/cmd/agent/main.go b/cmd/agent/main.go
index 9424ed6..486ee84 100644
--- a/cmd/agent/main.go
+++ b/cmd/agent/main.go
@@ -267,12 +267,14 @@ func doTask(task *pb.Task) {
func reportState() {
var lastReportHostInfo time.Time
var err error
+ var now time.Time
defer println("reportState exit", time.Now(), "=>", err)
for {
+ now = time.Now()
if client != nil {
monitor.TrackNetworkSpeed()
timeOutCtx, cancel := context.WithTimeout(context.Background(), networkTimeOut)
- _, err = client.ReportSystemState(timeOutCtx, monitor.GetState(dao.ReportDelay).PB())
+ _, err = client.ReportSystemState(timeOutCtx, monitor.GetState().PB())
cancel()
if err != nil {
println("reportState error", err)
@@ -283,6 +285,7 @@ func reportState() {
client.ReportSystemInfo(context.Background(), monitor.GetHost().PB())
}
}
+ time.Sleep(time.Until(now.Add(time.Second)))
}
}
diff --git a/cmd/agent/monitor/monitor.go b/cmd/agent/monitor/monitor.go
index 3d4dc88..74832e0 100644
--- a/cmd/agent/monitor/monitor.go
+++ b/cmd/agent/monitor/monitor.go
@@ -63,12 +63,12 @@ func GetHost() *model.Host {
}
}
-func GetState(delay int64) *model.HostState {
+func GetState() *model.HostState {
hi, _ := host.Info()
mv, _ := mem.VirtualMemory()
ms, _ := mem.SwapMemory()
var cpuPercent float64
- cp, err := cpu.Percent(time.Second*time.Duration(delay), false)
+ cp, err := cpu.Percent(0, false)
if err == nil {
cpuPercent = cp[0]
}
diff --git a/model/alertrule.go b/model/alertrule.go
index 61e0919..b752df6 100644
--- a/model/alertrule.go
+++ b/model/alertrule.go
@@ -41,7 +41,7 @@ func (r *AlertRule) Check(points [][]interface{}) (int, bool) {
for i := 0; i < len(r.Rules); i++ {
total := 0.0
fail := 0.0
- num := int(r.Rules[i].Duration / 2) // SnapshotDelay
+ num := int(r.Rules[i].Duration)
if num > max {
max = num
}
diff --git a/resource/static/main.js b/resource/static/main.js
index 356142c..6f286b6 100644
--- a/resource/static/main.js
+++ b/resource/static/main.js
@@ -1,7 +1,10 @@
function readableBytes(bytes) {
+ if (!bytes) {
+ return '0B'
+ }
var i = Math.floor(Math.log(bytes) / Math.log(1024)),
sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
- return (bytes / Math.pow(1024, i)).toFixed(0) + " " + sizes[i];
+ return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + sizes[i];
}
const confirmBtn = $(".mini.confirm.modal .positive.button");
diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html
index c91610e..4376a45 100644
--- a/resource/template/common/footer.html
+++ b/resource/template/common/footer.html
@@ -9,7 +9,7 @@
-
+