-
Notifications
You must be signed in to change notification settings - Fork 50
/
status.go
47 lines (37 loc) · 1.34 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" yaml:"server"`
Database databaseStatus `json:"database" yaml:"database"`
}
type serverStatus struct {
TotalRequests int `json:"total_requests" yaml:"total_requests"`
ConnectionsActive int `json:"connections_active" yaml:"connections_active"`
ConnectionsAccepted int `json:"connections_accepted" yaml:"connections_accepted"`
ConnectionsHandled int `json:"connections_handled" yaml:"connections_handled"`
ConnectionsReading int `json:"connections_reading" yaml:"connections_reading"`
ConnectionsWriting int `json:"connections_writing" yaml:"connections_writing"`
ConnectionsWaiting int `json:"connections_waiting" yaml:"connections_waiting"`
}
type databaseStatus struct {
Reachable bool `json:"reachable" yaml:"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
}