-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstatus.go
108 lines (97 loc) · 3.28 KB
/
status.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"context"
"net/http"
"github.com/julienschmidt/httprouter"
"github.com/pkg/errors"
)
func addStatusHandlers(router *httprouter.Router) {
router.GET("/status/users", makeRequestHandlerWithContext(handleUsers))
router.GET("/status/configs", makeRequestHandlerWithContext(handleConfigs))
router.GET("/status/databases", makeRequestHandlerWithContext(handleDatabases))
router.GET("/status/pools", makeRequestHandlerWithContext(handlePools))
router.GET("/status/clients", makeRequestHandlerWithContext(handleClients))
router.GET("/status/servers", makeRequestHandlerWithContext(handleServers))
router.GET("/status/memory", makeRequestHandlerWithContext(handleMems))
router.GET("/status/stats", makeRequestHandlerWithContext(handleStats))
}
func handleUsers(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
users, err := getUsers(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching users from PGBouncer")
}
return returnJSON(w, users)
}
func handleConfigs(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
configs, err := getConfigs(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching configs from PGBouncer")
}
return returnJSON(w, configs)
}
func handleDatabases(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
databases, err := getDatabases(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching databases from PGBouncer")
}
return returnJSON(w, databases)
}
func handlePools(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
pools, err := getPools(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching pools from PGBouncer")
}
return returnJSON(w, pools)
}
func handleClients(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
clients, err := getClients(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching clients from PGBouncer")
}
return returnJSON(w, clients)
}
func handleServers(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
servers, err := getServers(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching servers from PGBouncer")
}
return returnJSON(w, servers)
}
func handleMems(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
mems, err := getMems(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching mems from PGBouncer")
}
return returnJSON(w, mems)
}
func handleStats(ctx context.Context, w http.ResponseWriter, _ httprouter.Params) error {
if db == nil {
return errors.New("PGBouncer Database is not connected")
}
stats, err := getStats(ctx, db)
if err != nil {
return errors.Wrap(err, "Error fetching stats from PGBouncer")
}
return returnJSON(w, stats)
}