forked from open-falcon/falcon-plus
/
memory.go
38 lines (32 loc) · 854 Bytes
/
memory.go
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
package http
import (
"github.com/toolkits/nux"
"net/http"
)
func configMemoryRoutes() {
http.HandleFunc("/page/memory", func(w http.ResponseWriter, r *http.Request) {
mem, err := nux.MemInfo()
if err != nil {
RenderMsgJson(w, err.Error())
return
}
memFree := mem.MemFree + mem.Buffers + mem.Cached
memUsed := mem.MemTotal - memFree
var t uint64 = 1024 * 1024
RenderDataJson(w, []interface{}{mem.MemTotal / t, memUsed / t, memFree / t})
})
http.HandleFunc("/proc/memory", func(w http.ResponseWriter, r *http.Request) {
mem, err := nux.MemInfo()
if err != nil {
RenderMsgJson(w, err.Error())
return
}
memFree := mem.MemFree + mem.Buffers + mem.Cached
memUsed := mem.MemTotal - memFree
RenderDataJson(w, map[string]interface{}{
"total": mem.MemTotal,
"free": memFree,
"used": memUsed,
})
})
}