-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmonitoringcenter.go
158 lines (136 loc) · 4.65 KB
/
monitoringcenter.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package oneandone
import (
"errors"
"net/http"
"time"
)
type MonServerUsageSummary struct {
Identity
Agent *monitoringAgent `json:"agent,omitempty"`
Alerts *monitoringAlerts `json:"alerts,omitempty"`
Status *monitoringStatus `json:"status,omitempty"`
ApiPtr
}
type MonServerUsageDetails struct {
Identity
Status *statusState `json:"status,omitempty"`
Agent *monitoringAgent `json:"agent,omitempty"`
Alerts *monitoringAlerts `json:"alerts,omitempty"`
CpuStatus *utilizationStatus `json:"cpu,omitempty"`
DiskStatus *utilizationStatus `json:"disk,omitempty"`
RamStatus *utilizationStatus `json:"ram,omitempty"`
PingStatus *pingStatus `json:"internal_ping,omitempty"`
TransferStatus *transferStatus `json:"transfer,omitempty"`
ApiPtr
}
type monitoringStatus struct {
State string `json:"state,omitempty"`
Cpu *statusState `json:"cpu,omitempty"`
Disk *statusState `json:"disk,omitempty"`
InternalPing *statusState `json:"internal_ping,omitempty"`
Ram *statusState `json:"ram,omitempty"`
Transfer *statusState `json:"transfer,omitempty"`
}
type utilizationStatus struct {
CriticalThreshold int `json:"critical,omitempty"`
WarningThreshold int `json:"warning,omitempty"`
Status string `json:"status,omitempty"`
Data []usageData `json:"data,omitempty"`
Unit *usageUnit `json:"unit,omitempty"`
}
type pingStatus struct {
CriticalThreshold int `json:"critical,omitempty"`
WarningThreshold int `json:"warning,omitempty"`
Status string `json:"status,omitempty"`
Data []pingData `json:"data,omitempty"`
Unit *pingUnit `json:"unit,omitempty"`
}
type transferStatus struct {
CriticalThreshold int `json:"critical,omitempty"`
WarningThreshold int `json:"warning,omitempty"`
Status string `json:"status,omitempty"`
Data []transferData `json:"data,omitempty"`
Unit *transferUnit `json:"unit,omitempty"`
}
type monitoringAgent struct {
AgentInstalled bool `json:"agent_installed"`
MissingAgentAlert bool `json:"missing_agent_alert"`
MonitoringNeedsAgent bool `json:"monitoring_needs_agent"`
}
type monitoringAlerts struct {
Ports *monitoringAlertInfo `json:"ports,omitempty"`
Process *monitoringAlertInfo `json:"process,omitempty"`
Resources *monitoringAlertInfo `json:"resources,omitempty"`
}
type monitoringAlertInfo struct {
Ok int `json:"ok"`
Warning int `json:"warning"`
Critical int `json:"critical"`
}
type usageData struct {
Date string `json:"date,omitempty"`
UsedPercent float32 `json:"used_percent"`
}
type usageUnit struct {
UsedPercent string `json:"used_percent,omitempty"`
}
type pingUnit struct {
PackagesLost string `json:"pl,omitempty"`
AccessTime string `json:"rta,omitempty"`
}
type pingData struct {
Date string `json:"date,omitempty"`
PackagesLost int `json:"pl"`
AccessTime float32 `json:"rta"`
}
type transferUnit struct {
Downstream string `json:"downstream,omitempty"`
Upstream string `json:"upstream,omitempty"`
}
type transferData struct {
Date string `json:"date,omitempty"`
Downstream int `json:"downstream"`
Upstream int `json:"upstream"`
}
// GET /monitoring_center
func (api *API) ListMonitoringServersUsages(args ...interface{}) ([]MonServerUsageSummary, error) {
url, err := processQueryParams(createUrl(api, monitorCenterPathSegment), args...)
if err != nil {
return nil, err
}
result := []MonServerUsageSummary{}
err = api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
for index, _ := range result {
result[index].api = api
}
return result, nil
}
// GET /monitoring_center/{server_id}
func (api *API) GetMonitoringServerUsage(ser_id string, period string, dates ...time.Time) (*MonServerUsageDetails, error) {
if period == "" {
return nil, errors.New("Time period must be provided.")
}
params := make(map[string]interface{}, len(dates)+1)
params["period"] = period
if len(dates) == 2 {
if dates[0].After(dates[1]) {
return nil, errors.New("Start date cannot be after end date.")
}
params["start_date"] = dates[0].Format(time.RFC3339)
params["end_date"] = dates[1].Format(time.RFC3339)
} else if len(dates) > 0 {
return nil, errors.New("Start and end dates must be provided.")
}
url := createUrl(api, monitorCenterPathSegment, ser_id)
url = appendQueryParams(url, params)
result := new(MonServerUsageDetails)
err := api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}