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
|
from libcpp cimport bool
from util.system.types cimport ui32, ui64, i64
from library.python.monlib.metric cimport (
TGauge, TCounter, TRate, TIntGauge, THistogram,
IHistogramCollectorPtr)
cdef class Gauge:
"""
Represents a floating point absolute value
"""
@staticmethod
cdef Gauge from_ptr(TGauge* native):
cdef Gauge wrapper = Gauge.__new__(Gauge)
wrapper.__wrapped = native
return wrapper
def set(self, double value):
"""
Set metric to the specified value
:param value: metric value
"""
self.__wrapped.Set(value)
def get(self):
"""
Get metric value.
:param value: metric value
"""
return self.__wrapped.Get()
def add(self, double value):
"""
Add value to metric.
:param value: metric value
"""
return self.__wrapped.Add(value)
cdef class IntGauge:
"""
Represents an integer absolute value
"""
@staticmethod
cdef IntGauge from_ptr(TIntGauge* native):
cdef IntGauge wrapper = IntGauge.__new__(IntGauge)
wrapper.__wrapped = native
return wrapper
def set(self, i64 value):
"""
Set metric to the specified value
:param value: metric value
"""
self.__wrapped.Set(value)
def get(self):
"""
Get metric value
:param value: metric value
"""
return self.__wrapped.Get()
def add(self, i64 value):
"""
Add value to metric.
:param value: metric value
"""
return self.__wrapped.Add(value)
def inc(self):
"""
Add 1 to metric.
"""
return self.__wrapped.Inc()
def dec(self):
"""
Add -1 to metric.
"""
return self.__wrapped.Dec()
cdef class Counter:
"""
Represents a counter value
"""
@staticmethod
cdef Counter from_ptr(TCounter* native):
cdef Counter wrapper = Counter.__new__(Counter)
wrapper.__wrapped = native
return wrapper
def get(self):
return self.__wrapped.Get()
def inc(self):
"""
Increment metric value
"""
return self.__wrapped.Inc()
def reset(self):
"""
Reset metric value to zero
"""
return self.__wrapped.Reset()
cdef class Rate:
"""
Represents a time derivative
"""
@staticmethod
cdef Rate from_ptr(TRate* native):
cdef Rate wrapper = Rate.__new__(Rate)
wrapper.__wrapped = native
return wrapper
def get(self):
return self.__wrapped.Get()
def inc(self):
"""
Increment metric value
"""
return self.__wrapped.Inc()
def add(self, ui64 value):
"""
Add the value to metric
:param value: value to add to metric
"""
return self.__wrapped.Add(value)
cdef class Histogram:
"""
Represents some value distribution
"""
@staticmethod
cdef Histogram from_ptr(THistogram* native):
cdef Histogram wrapper = Histogram.__new__(Histogram, 0)
wrapper.__is_owner = False
wrapper.__wrapped = native
return wrapper
def __dealloc__(self):
if self.__is_owner:
del self.__wrapped
def collect(self, double value, ui32 count=1):
"""
Add a few points with same value to the distribution
:param value: points' value
:param value: point count
"""
return self.__wrapped.Record(value, count)
|