实现后台首页图表(用户在线数、网络吞量量、CPU、内存)

This commit is contained in:
lanrenwo
2022-09-14 19:55:03 +08:00
parent 091dc69f1d
commit 5b220838d9
11 changed files with 680 additions and 49 deletions

View File

@@ -0,0 +1,33 @@
package admin
import (
"errors"
"net/http"
"github.com/bjdgyc/anylink/dbdata"
)
func StatsInfoList(w http.ResponseWriter, r *http.Request) {
var ok bool
_ = r.ParseForm()
action := r.FormValue("action")
scope := r.FormValue("scope")
ok = dbdata.StatsInfoIns.ValidAction(action)
if !ok {
RespError(w, RespParamErr, errors.New("不存在的图表类别"))
return
}
ok = dbdata.StatsInfoIns.ValidScope(scope)
if !ok {
RespError(w, RespParamErr, errors.New("不存在的日期范围"))
return
}
datas, err := dbdata.StatsInfoIns.GetData(action, scope)
if err != nil {
RespError(w, RespInternalErr, err)
return
}
data := make(map[string]interface{})
data["datas"] = datas
RespSucess(w, data)
}

View File

@@ -8,6 +8,7 @@ import (
"net/http/pprof"
"github.com/bjdgyc/anylink/base"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
@@ -18,6 +19,7 @@ func StartAdmin() {
r := mux.NewRouter()
r.Use(authMiddleware)
r.Use(handlers.CompressHandler)
// 监控检测
r.HandleFunc("/status.html", func(w http.ResponseWriter, r *http.Request) {
@@ -64,6 +66,8 @@ func StartAdmin() {
r.HandleFunc("/group/set", GroupSet)
r.HandleFunc("/group/del", GroupDel)
r.HandleFunc("/statsinfo/list", StatsInfoList)
// pprof
if base.Cfg.Pprof {
r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline).Name("debug")