forked from kevholditch/gokong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
47 lines (37 loc) · 1.12 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
package gokong
import (
"encoding/json"
"errors"
"fmt"
)
type StatusClient struct {
config *Config
}
type Status struct {
Server serverStatus `json:"server"`
Database databaseStatus `json:"database"`
}
type serverStatus struct {
TotalRequests int `json:"total_requests"`
ConnectionsActive int `json:"connections_active"`
ConnectionsAccepted int `json:"connections_accepted"`
ConnectionsHandled int `json:"connections_handled"`
ConnectionsReading int `json:"connections_reading"`
ConnectionsWriting int `json:"connections_writing"`
ConnectionsWaiting int `json:"connections_waiting"`
}
type databaseStatus struct {
Reachable bool `json:"reachable"`
}
func (statusClient *StatusClient) Get() (*Status, error) {
_, body, errs := newGet(statusClient.config, statusClient.config.HostAddress+"/status").End()
if errs != nil {
return nil, errors.New(fmt.Sprintf("Could not call get status, error: %v", errs))
}
status := &Status{}
err := json.Unmarshal([]byte(body), status)
if err != nil {
return nil, errors.New(fmt.Sprintf("Could not parse status response, error: %v", err))
}
return status, nil
}