/
processlist.go
56 lines (50 loc) · 1.19 KB
/
processlist.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* NeoDB
*
* Copyright 2018 The Radon Authors.
* Copyright 2021-2030 The NeoDB Authors.
* Code is licensed under the GPLv3.
*
*/
package v1
import (
"github.com/sealdb/neodb/proxy"
"github.com/ant0ine/go-json-rest/rest"
"github.com/sealdb/mysqlstack/xlog"
)
// ProcesslistHandler impl.
func ProcesslistHandler(log *xlog.Log, proxy *proxy.Proxy) rest.HandlerFunc {
f := func(w rest.ResponseWriter, r *rest.Request) {
processlistHandler(log, proxy, w, r)
}
return f
}
func processlistHandler(log *xlog.Log, proxy *proxy.Proxy, w rest.ResponseWriter, r *rest.Request) {
type processlist struct {
ID uint32 `json:"id"`
User string `json:"user"`
Host string `json:"host"`
DB string `json:"db"`
Command string `json:"command"`
Time uint32 `json:"time"`
State string `json:"state"`
Info string `json:"info"`
}
var rsp []processlist
sessions := proxy.Sessions()
rows := sessions.Snapshot()
for _, sr := range rows {
r := processlist{
ID: sr.ID,
User: sr.User,
Host: sr.Host,
DB: sr.DB,
Command: sr.Command,
Time: sr.Time,
State: sr.State,
Info: sr.Info,
}
rsp = append(rsp, r)
}
w.WriteJson(rsp)
}