-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
42 lines (33 loc) · 975 Bytes
/
rest.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
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
v1 "github.com/masif-upgrader/agent/v1"
"github.com/masif-upgrader/common"
log "github.com/sirupsen/logrus"
"net"
"os"
)
func startRestServer(sock string) (*iris.Application, error) {
log.WithFields(log.Fields{"socket": sock}).Info("Listening on *nix socket")
server, errLs := net.Listen("unix", sock)
if errLs != nil {
return nil, errLs
}
os.Chmod(sock, 0770)
app := iris.New()
app.Get("/v1/load", getV1Load)
go app.Run(iris.Listener(server), iris.WithoutStartupLog)
return app, nil
}
func getV1Load(context context.Context) {
context.JSON(&v1.Load{
queryStats.queryLoad(),
actionsStats[common.PkgMgrInstall].queryLoad(),
actionsStats[common.PkgMgrUpdate].queryLoad(),
actionsStats[common.PkgMgrConfigure].queryLoad(),
actionsStats[common.PkgMgrRemove].queryLoad(),
actionsStats[common.PkgMgrPurge].queryLoad(),
errorStats.queryLoad(),
})
}