forked from linode/linode_api4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
228 lines (179 loc) · 5.26 KB
/
monitor.py
File metadata and controls
228 lines (179 loc) · 5.26 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
__all__ = [
"MonitorDashboard",
"MonitorMetricsDefinition",
"MonitorService",
"MonitorServiceToken",
"AggregateFunction",
]
from dataclasses import dataclass, field
from typing import List, Optional
from linode_api4.objects.base import Base, Property
from linode_api4.objects.serializable import JSONObject, StrEnum
class AggregateFunction(StrEnum):
"""
Enum for supported aggregate functions.
"""
min = "min"
max = "max"
avg = "avg"
sum = "sum"
count = "count"
rate = "rate"
increase = "increase"
last = "last"
class ChartType(StrEnum):
"""
Enum for supported chart types.
"""
line = "line"
area = "area"
class ServiceType(StrEnum):
"""
Enum for supported service types.
"""
dbaas = "dbaas"
linode = "linode"
lke = "lke"
vpc = "vpc"
nodebalancer = "nodebalancer"
firewall = "firewall"
object_storage = "object_storage"
aclb = "aclb"
net_load_balancer = "netloadbalancer"
class MetricType(StrEnum):
"""
Enum for supported metric type
"""
gauge = "gauge"
counter = "counter"
histogram = "histogram"
summary = "summary"
class MetricUnit(StrEnum):
"""
Enum for supported metric units.
"""
COUNT = "count"
PERCENT = "percent"
BYTE = "byte"
SECOND = "second"
BITS_PER_SECOND = "bits_per_second"
MILLISECOND = "millisecond"
KB = "KB"
MB = "MB"
GB = "GB"
RATE = "rate"
BYTES_PER_SECOND = "bytes_per_second"
PERCENTILE = "percentile"
RATIO = "ratio"
OPS_PER_SECOND = "ops_per_second"
IOPS = "iops"
KILO_BYTES_PER_SECOND = "kilo_bytes_per_second"
SESSIONS_PER_SECOND = "sessions_per_second"
PACKETS_PER_SECOND = "packets_per_second"
KILO_BITS_PER_SECOND = "kilo_bits_per_second"
class DashboardType(StrEnum):
"""
Enum for supported dashboard types.
"""
standard = "standard"
custom = "custom"
@dataclass
class Filter(JSONObject):
"""
Represents a filter in the filters list of a dashboard widget.
"""
dimension_label: str = ""
operator: str = ""
value: str = ""
@dataclass
class DashboardWidget(JSONObject):
"""
Represents a single widget in the widgets list.
"""
metric: str = ""
unit: MetricUnit = ""
label: str = ""
color: str = ""
size: int = 0
chart_type: ChartType = ""
y_label: str = ""
aggregate_function: AggregateFunction = ""
group_by: Optional[List[str]] = None
_filters: Optional[List[Filter]] = field(
default=None, metadata={"json_key": "filters"}
)
def __getattribute__(self, name):
"""Override to handle the filters attribute specifically to avoid metaclass conflict."""
if name == "filters":
return object.__getattribute__(self, "_filters")
return object.__getattribute__(self, name)
def __setattr__(self, name, value):
"""Override to handle setting the filters attribute."""
if name == "filters":
object.__setattr__(self, "_filters", value)
else:
object.__setattr__(self, name, value)
@dataclass
class ServiceAlert(JSONObject):
"""
Represents alert configuration options for a monitor service.
"""
polling_interval_seconds: Optional[List[int]] = None
evaluation_period_seconds: Optional[List[int]] = None
scope: Optional[List[str]] = None
@dataclass
class Dimension(JSONObject):
"""
Represents a single dimension in the dimensions list.
"""
dimension_label: Optional[str] = None
label: Optional[str] = None
values: Optional[List[str]] = None
@dataclass
class MonitorMetricsDefinition(JSONObject):
"""
Represents a single metric definition in the metrics definition list.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-information
"""
metric: str = ""
label: str = ""
metric_type: MetricType = ""
unit: MetricUnit = ""
scrape_interval: int = 0
is_alertable: bool = False
dimensions: Optional[List[Dimension]] = None
available_aggregate_functions: Optional[List[AggregateFunction]] = None
class MonitorDashboard(Base):
"""
Dashboard details.
List dashboards: https://techdocs.akamai.com/linode-api/get-dashboards-all
"""
api_endpoint = "/monitor/dashboards/{id}"
properties = {
"id": Property(identifier=True),
"created": Property(is_datetime=True),
"label": Property(),
"service_type": Property(ServiceType),
"type": Property(DashboardType),
"widgets": Property(json_object=DashboardWidget),
"updated": Property(is_datetime=True),
}
class MonitorService(Base):
"""
Represents a single service type.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-monitor-services
"""
api_endpoint = "/monitor/services/{service_type}"
id_attribute = "service_type"
properties = {
"service_type": Property(ServiceType),
"label": Property(),
"alert": Property(json_object=ServiceAlert),
}
@dataclass
class MonitorServiceToken(JSONObject):
"""
A token for the requested service_type.
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-get-token
"""
token: str = ""