载入监控定时采集
This commit is contained in:
@@ -68,8 +68,9 @@ func LoadMonitor(w http.ResponseWriter, r *http.Request) {
|
|||||||
var backdatas []MonitorData
|
var backdatas []MonitorData
|
||||||
if bodyArgs.Param == "all" || bodyArgs.Param == "cpu" || bodyArgs.Param == "memory" || bodyArgs.Param == "load" {
|
if bodyArgs.Param == "all" || bodyArgs.Param == "cpu" || bodyArgs.Param == "memory" || bodyArgs.Param == "load" {
|
||||||
var bases []MonitorBase
|
var bases []MonitorBase
|
||||||
err := dborm.DbClient.XEngine.SQL("SELECT * FROM monitor_base").
|
err := dborm.DbClient.XEngine.Table("monitor_base").
|
||||||
Where("created_at > ? AND created_at < ?", bodyArgs.StartTime, bodyArgs.EndTime).
|
Where("created_at > ? AND created_at < ?", bodyArgs.StartTime, bodyArgs.EndTime).
|
||||||
|
Desc("created_at").
|
||||||
Find(&bases)
|
Find(&bases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||||
@@ -86,8 +87,9 @@ func LoadMonitor(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
if bodyArgs.Param == "all" || bodyArgs.Param == "io" {
|
if bodyArgs.Param == "all" || bodyArgs.Param == "io" {
|
||||||
var bases []MonitorIO
|
var bases []MonitorIO
|
||||||
err := dborm.DbClient.XEngine.SQL("SELECT * FROM monitor_io").
|
err := dborm.DbClient.XEngine.Table("monitor_io").
|
||||||
Where("created_at > ? AND created_at < ?", bodyArgs.StartTime, bodyArgs.EndTime).
|
Where("created_at > ? AND created_at < ?", bodyArgs.StartTime, bodyArgs.EndTime).
|
||||||
|
Desc("created_at").
|
||||||
Find(&bases)
|
Find(&bases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||||
@@ -104,8 +106,9 @@ func LoadMonitor(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
if bodyArgs.Param == "all" || bodyArgs.Param == "network" {
|
if bodyArgs.Param == "all" || bodyArgs.Param == "network" {
|
||||||
var bases []MonitorNetwork
|
var bases []MonitorNetwork
|
||||||
err := dborm.DbClient.XEngine.SQL("SELECT * FROM monitor_network").
|
err := dborm.DbClient.XEngine.Table("monitor_network").
|
||||||
Where("name = ? AND created_at > ? AND created_at < ?", bodyArgs.Info, bodyArgs.StartTime, bodyArgs.EndTime).
|
Where("name = ? AND created_at > ? AND created_at < ?", bodyArgs.Info, bodyArgs.StartTime, bodyArgs.EndTime).
|
||||||
|
Desc("created_at").
|
||||||
Find(&bases)
|
Find(&bases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||||
|
|||||||
@@ -186,11 +186,10 @@ func loadNetIO() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := dborm.DbClient.XEngine.Table("monitor_network").Insert(netList)
|
_, err := dborm.DbClient.XEngine.Table("monitor_network").Insert(netList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Insert network monitoring data failed, err: %v", err)
|
log.Errorf("Insert network monitoring data failed, err: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Println(rows, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var c *cron.Cron
|
var c *cron.Cron
|
||||||
@@ -198,6 +197,7 @@ var monitorCronID int
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
c = cron.New()
|
c = cron.New()
|
||||||
|
c.Start()
|
||||||
monitorCronID = 0
|
monitorCronID = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user