cmetrics 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/ext/cmetrics-master.tar.gz +0 -0
- data/ext/cmetrics/cmetrics.c +1 -0
- data/ext/cmetrics/cmetrics_c.h +7 -0
- data/ext/cmetrics/cmetrics_counter.c +3 -3
- data/ext/cmetrics/cmetrics_gauge.c +3 -3
- data/ext/cmetrics/cmetrics_untyped.c +488 -0
- data/ext/cmetrics/extconf.rb +1 -1
- data/lib/cmetrics/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ab76eb9253339b05455e7424e0f440bec6a9dd612ef61224066650151755683
|
4
|
+
data.tar.gz: '056618e48e0bb0d6c50a325797096824d8c970b48f26d24c9f224608f48f513d'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 157c179195aa7273939807fa10ac06b2b660cd52ef459ffe733dafe11109eccc8b9c48d4f2cb384ecd250909fe4327321ab3382b83ff77e4432ca76641178059
|
7
|
+
data.tar.gz: 6937cbb0e2ab74b51683d3d3ad5d440b9bd571663a4cae06dd0385b7b3f74bb223c6bf3e4fb9a04e29e13ed480daa928e059323d28eecefe4cdb8af9d086ee70
|
data/README.md
CHANGED
@@ -30,13 +30,13 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
+
### Counter
|
34
|
+
|
33
35
|
`CMetrics::Counter` is a cumulative metric that can only increase monotonically and reset to zero at restart.
|
34
36
|
This class should be used for counting the total amount of record size or something like monotonic increasing values.
|
35
37
|
|
36
38
|
ref: [Metric Types -- Counter | Prometheus documentation](https://prometheus.io/docs/concepts/metric_types/#counter)
|
37
39
|
|
38
|
-
### Counter
|
39
|
-
|
40
40
|
```ruby
|
41
41
|
require 'cmetrics'
|
42
42
|
|
@@ -94,6 +94,35 @@ require 'cmetrics'
|
|
94
94
|
@gauge.val(["localhost", "test"]) #=> 7.5
|
95
95
|
```
|
96
96
|
|
97
|
+
### Untyped
|
98
|
+
|
99
|
+
`CMetrics::Untyped` is a metric that can only set a value via `#set` and reset to zero at restart.
|
100
|
+
This class should be used for storing the increasing but discontinuous values.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
require 'cmetrics'
|
104
|
+
|
105
|
+
@untyped = CMetrics::Untyped.new
|
106
|
+
@untyped.create("kubernetes", "network", "load", "Network load", ["hostname", "app"])
|
107
|
+
|
108
|
+
@untyped.val #=> nil
|
109
|
+
|
110
|
+
@untyped.set 3.0 #=> true
|
111
|
+
@untyped.val #=> 3.0
|
112
|
+
|
113
|
+
# Multiple labels
|
114
|
+
@untyped.set(1.0, ["localhost", "cmetrics"]) #=> true
|
115
|
+
@untyped.val(["localhost", "cmetrics"]) #=> 1.0
|
116
|
+
|
117
|
+
@untyped.set(10.55, ["localhost", "test"]) #=> true
|
118
|
+
@untyped.val(["localhost", "test"]) #=> 10.55
|
119
|
+
|
120
|
+
#CMetrics::Untyped can set greater value than stored.
|
121
|
+
@untyped.set(12.15, ["localhost", "test"]) #=> true
|
122
|
+
#CMetrics::Untyped cannot set smaller value than stored.
|
123
|
+
@untyped.set(1, ["localhost", "test"]) #=> false
|
124
|
+
```
|
125
|
+
|
97
126
|
### Serde
|
98
127
|
|
99
128
|
`CMetrics::Serde` is for a decoding (and encoding to some format stuffs) from msgpacked buffers that are created by `CMetrics::Counter#to_msgpack` or `CMetrics::Gauge#to_msgpack`.
|
data/ext/cmetrics-master.tar.gz
CHANGED
Binary file
|
data/ext/cmetrics/cmetrics.c
CHANGED
data/ext/cmetrics/cmetrics_c.h
CHANGED
@@ -34,6 +34,7 @@
|
|
34
34
|
#include <cmetrics/cmetrics.h>
|
35
35
|
#include <cmetrics/cmt_counter.h>
|
36
36
|
#include <cmetrics/cmt_gauge.h>
|
37
|
+
#include <cmetrics/cmt_untyped.h>
|
37
38
|
#include <cmetrics/cmt_encode_influx.h>
|
38
39
|
#include <cmetrics/cmt_encode_prometheus.h>
|
39
40
|
#include <cmetrics/cmt_encode_msgpack.h>
|
@@ -55,8 +56,14 @@ struct CMetricsSerde {
|
|
55
56
|
size_t unpack_msgpack_offset;
|
56
57
|
};
|
57
58
|
|
59
|
+
struct CMetricsUntyped {
|
60
|
+
struct cmt *instance;
|
61
|
+
struct cmt_untyped *untyped;
|
62
|
+
};
|
63
|
+
|
58
64
|
void Init_cmetrics_counter(VALUE rb_mCMetrics);
|
59
65
|
void Init_cmetrics_gauge(VALUE rb_mCMetrics);
|
60
66
|
void Init_cmetrics_serde(VALUE rb_mCMetrics);
|
67
|
+
void Init_cmetrics_untyped(VALUE rb_mCMetrics);
|
61
68
|
|
62
69
|
#endif // _CMETRICS_C_H
|
@@ -40,12 +40,12 @@ counter_free(void* ptr)
|
|
40
40
|
struct CMetricsCounter* cmetricsCounter = (struct CMetricsCounter*)ptr;
|
41
41
|
|
42
42
|
if (!cmetricsCounter) {
|
43
|
-
if (!cmetricsCounter->instance) {
|
44
|
-
cmt_destroy(cmetricsCounter->instance);
|
45
|
-
}
|
46
43
|
if (!cmetricsCounter->counter) {
|
47
44
|
cmt_counter_destroy(cmetricsCounter->counter);
|
48
45
|
}
|
46
|
+
if (!cmetricsCounter->instance) {
|
47
|
+
cmt_destroy(cmetricsCounter->instance);
|
48
|
+
}
|
49
49
|
}
|
50
50
|
|
51
51
|
xfree(ptr);
|
@@ -40,12 +40,12 @@ gauge_free(void* ptr)
|
|
40
40
|
struct CMetricsGauge* cmetricsGauge = (struct CMetricsGauge*)ptr;
|
41
41
|
|
42
42
|
if (!cmetricsGauge) {
|
43
|
-
if (!cmetricsGauge->instance) {
|
44
|
-
cmt_destroy(cmetricsGauge->instance);
|
45
|
-
}
|
46
43
|
if (!cmetricsGauge->gauge) {
|
47
44
|
cmt_gauge_destroy(cmetricsGauge->gauge);
|
48
45
|
}
|
46
|
+
if (!cmetricsGauge->instance) {
|
47
|
+
cmt_destroy(cmetricsGauge->instance);
|
48
|
+
}
|
49
49
|
}
|
50
50
|
|
51
51
|
xfree(ptr);
|
@@ -0,0 +1,488 @@
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2
|
+
|
3
|
+
/* CMetrics-Ruby
|
4
|
+
* =============
|
5
|
+
* Copyright 2021 Hiroshi Hatake <hatake@calyptia.com>
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*/
|
19
|
+
|
20
|
+
#include "cmetrics_c.h"
|
21
|
+
|
22
|
+
VALUE rb_cUntyped;
|
23
|
+
|
24
|
+
static void untyped_free(void* ptr);
|
25
|
+
|
26
|
+
static const rb_data_type_t rb_cmetrics_untyped_type = { "cmetrics/untyped",
|
27
|
+
{
|
28
|
+
0,
|
29
|
+
untyped_free,
|
30
|
+
0,
|
31
|
+
},
|
32
|
+
NULL,
|
33
|
+
NULL,
|
34
|
+
RUBY_TYPED_FREE_IMMEDIATELY };
|
35
|
+
|
36
|
+
|
37
|
+
static void
|
38
|
+
untyped_free(void* ptr)
|
39
|
+
{
|
40
|
+
struct CMetricsUntyped* cmetricsUntyped = (struct CMetricsUntyped*)ptr;
|
41
|
+
|
42
|
+
if (!cmetricsUntyped) {
|
43
|
+
if (!cmetricsUntyped->untyped) {
|
44
|
+
cmt_untyped_destroy(cmetricsUntyped->untyped);
|
45
|
+
}
|
46
|
+
if (!cmetricsUntyped->instance) {
|
47
|
+
cmt_destroy(cmetricsUntyped->instance);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
xfree(ptr);
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE
|
55
|
+
rb_cmetrics_untyped_alloc(VALUE klass)
|
56
|
+
{
|
57
|
+
VALUE obj;
|
58
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
59
|
+
obj = TypedData_Make_Struct(
|
60
|
+
klass, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
61
|
+
return obj;
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* Initailize Untyped class.
|
66
|
+
*
|
67
|
+
* @return [Untyped]
|
68
|
+
*
|
69
|
+
*/
|
70
|
+
static VALUE
|
71
|
+
rb_cmetrics_untyped_initialize(VALUE self)
|
72
|
+
{
|
73
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
74
|
+
|
75
|
+
TypedData_Get_Struct(
|
76
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
77
|
+
|
78
|
+
cmt_initialize();
|
79
|
+
|
80
|
+
cmetricsUntyped->instance = cmt_create();
|
81
|
+
cmetricsUntyped->untyped = NULL;
|
82
|
+
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* Create untyped.
|
88
|
+
*
|
89
|
+
*/
|
90
|
+
static VALUE
|
91
|
+
rb_cmetrics_untyped_create(int argc, VALUE* argv, VALUE self)
|
92
|
+
{
|
93
|
+
VALUE rb_namespace, rb_subsystem, rb_name, rb_help, rb_labels;
|
94
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
95
|
+
char **labels = NULL;
|
96
|
+
int labels_count = 0;
|
97
|
+
VALUE tmp_label;
|
98
|
+
long i;
|
99
|
+
|
100
|
+
TypedData_Get_Struct(
|
101
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
102
|
+
|
103
|
+
rb_scan_args(argc, argv, "41", &rb_namespace, &rb_subsystem, &rb_name, &rb_help, &rb_labels);
|
104
|
+
|
105
|
+
Check_Type(rb_namespace, T_STRING);
|
106
|
+
Check_Type(rb_subsystem, T_STRING);
|
107
|
+
Check_Type(rb_name, T_STRING);
|
108
|
+
Check_Type(rb_help, T_STRING);
|
109
|
+
|
110
|
+
if (!NIL_P(rb_labels)) {
|
111
|
+
switch(TYPE(rb_labels)) {
|
112
|
+
case T_STRING:
|
113
|
+
labels = (char *[]) { StringValuePtr(rb_labels) };
|
114
|
+
labels_count = 1;
|
115
|
+
cmetricsUntyped->untyped = cmt_untyped_create(cmetricsUntyped->instance,
|
116
|
+
StringValuePtr(rb_namespace),
|
117
|
+
StringValuePtr(rb_subsystem),
|
118
|
+
StringValuePtr(rb_name),
|
119
|
+
StringValuePtr(rb_help),
|
120
|
+
labels_count, labels);
|
121
|
+
break;
|
122
|
+
case T_SYMBOL:
|
123
|
+
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
|
124
|
+
labels_count = 1;
|
125
|
+
cmetricsUntyped->untyped = cmt_untyped_create(cmetricsUntyped->instance,
|
126
|
+
StringValuePtr(rb_namespace),
|
127
|
+
StringValuePtr(rb_subsystem),
|
128
|
+
StringValuePtr(rb_name),
|
129
|
+
StringValuePtr(rb_help),
|
130
|
+
labels_count, labels);
|
131
|
+
break;
|
132
|
+
case T_ARRAY:
|
133
|
+
labels_count = (int)RARRAY_LEN(rb_labels);
|
134
|
+
labels = ALLOCV_N(char *, tmp_label, labels_count);
|
135
|
+
for (i = 0; i < labels_count; i++) {
|
136
|
+
VALUE item = RARRAY_AREF(rb_labels, i);
|
137
|
+
switch(TYPE(item)) {
|
138
|
+
case T_SYMBOL:
|
139
|
+
labels[i] = RSTRING_PTR(rb_sym2str(item));
|
140
|
+
break;
|
141
|
+
case T_STRING:
|
142
|
+
labels[i] = StringValuePtr(item);
|
143
|
+
break;
|
144
|
+
default:
|
145
|
+
rb_raise(rb_eArgError, "labels must be Symbol/String");
|
146
|
+
}
|
147
|
+
}
|
148
|
+
cmetricsUntyped->untyped = cmt_untyped_create(cmetricsUntyped->instance,
|
149
|
+
StringValuePtr(rb_namespace),
|
150
|
+
StringValuePtr(rb_subsystem),
|
151
|
+
StringValuePtr(rb_name),
|
152
|
+
StringValuePtr(rb_help),
|
153
|
+
labels_count, labels);
|
154
|
+
|
155
|
+
ALLOCV_END(tmp_label);
|
156
|
+
break;
|
157
|
+
default:
|
158
|
+
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
|
159
|
+
}
|
160
|
+
} else {
|
161
|
+
cmetricsUntyped->untyped = cmt_untyped_create(cmetricsUntyped->instance,
|
162
|
+
StringValuePtr(rb_namespace),
|
163
|
+
StringValuePtr(rb_subsystem),
|
164
|
+
StringValuePtr(rb_name),
|
165
|
+
StringValuePtr(rb_help),
|
166
|
+
labels_count, labels);
|
167
|
+
}
|
168
|
+
|
169
|
+
return Qnil;
|
170
|
+
}
|
171
|
+
|
172
|
+
static VALUE
|
173
|
+
rb_cmetrics_untyped_get_value(int argc, VALUE* argv, VALUE self)
|
174
|
+
{
|
175
|
+
VALUE rb_labels;
|
176
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
177
|
+
int ret = 0;
|
178
|
+
double value = 0;
|
179
|
+
char **labels = NULL;
|
180
|
+
int labels_count = 0;
|
181
|
+
VALUE tmp_label;
|
182
|
+
long i;
|
183
|
+
|
184
|
+
TypedData_Get_Struct(
|
185
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
186
|
+
|
187
|
+
if (!cmetricsUntyped->untyped) {
|
188
|
+
rb_raise(rb_eRuntimeError, "Create untyped with CMetrics::Untyped#create first.");
|
189
|
+
}
|
190
|
+
|
191
|
+
rb_scan_args(argc, argv, "01", &rb_labels);
|
192
|
+
|
193
|
+
if (!NIL_P(rb_labels)) {
|
194
|
+
switch(TYPE(rb_labels)) {
|
195
|
+
case T_STRING:
|
196
|
+
labels = (char *[]) { StringValuePtr(rb_labels) };
|
197
|
+
labels_count = 1;
|
198
|
+
|
199
|
+
ret = cmt_untyped_get_val(cmetricsUntyped->untyped,
|
200
|
+
labels_count, labels, &value);
|
201
|
+
break;
|
202
|
+
case T_SYMBOL:
|
203
|
+
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
|
204
|
+
labels_count = 1;
|
205
|
+
|
206
|
+
ret = cmt_untyped_get_val(cmetricsUntyped->untyped,
|
207
|
+
labels_count, labels, &value);
|
208
|
+
break;
|
209
|
+
case T_ARRAY:
|
210
|
+
labels_count = (int)RARRAY_LEN(rb_labels);
|
211
|
+
labels = ALLOCV_N(char *, tmp_label, labels_count);
|
212
|
+
for (i = 0; i < labels_count; i++) {
|
213
|
+
VALUE item = RARRAY_AREF(rb_labels, i);
|
214
|
+
switch(TYPE(item)) {
|
215
|
+
case T_SYMBOL:
|
216
|
+
labels[i] = RSTRING_PTR(rb_sym2str(item));
|
217
|
+
break;
|
218
|
+
case T_STRING:
|
219
|
+
labels[i] = StringValuePtr(item);
|
220
|
+
break;
|
221
|
+
default:
|
222
|
+
rb_raise(rb_eArgError, "labels must be Symbol/String");
|
223
|
+
}
|
224
|
+
}
|
225
|
+
|
226
|
+
ret = cmt_untyped_get_val(cmetricsUntyped->untyped,
|
227
|
+
labels_count, labels, &value);
|
228
|
+
|
229
|
+
ALLOCV_END(tmp_label);
|
230
|
+
|
231
|
+
break;
|
232
|
+
default:
|
233
|
+
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
|
234
|
+
}
|
235
|
+
} else {
|
236
|
+
ret = cmt_untyped_get_val(cmetricsUntyped->untyped,
|
237
|
+
labels_count, labels, &value);
|
238
|
+
}
|
239
|
+
|
240
|
+
if (ret == 0) {
|
241
|
+
return DBL2NUM(value);
|
242
|
+
} else {
|
243
|
+
return Qnil;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
/*
|
248
|
+
* Set value into untyped.
|
249
|
+
*
|
250
|
+
* @return [Boolean]
|
251
|
+
*
|
252
|
+
*/
|
253
|
+
static VALUE
|
254
|
+
rb_cmetrics_untyped_set(int argc, VALUE* argv, VALUE self)
|
255
|
+
{
|
256
|
+
VALUE rb_labels, rb_num;
|
257
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
258
|
+
uint64_t ts;
|
259
|
+
int ret = 0;
|
260
|
+
double value = 0;
|
261
|
+
char **labels = NULL;
|
262
|
+
int labels_count = 0;
|
263
|
+
VALUE tmp_label;
|
264
|
+
long i;
|
265
|
+
|
266
|
+
TypedData_Get_Struct(
|
267
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
268
|
+
|
269
|
+
if (!cmetricsUntyped->untyped) {
|
270
|
+
rb_raise(rb_eRuntimeError, "Create untyped with CMetrics::Untyped#create first.");
|
271
|
+
}
|
272
|
+
|
273
|
+
rb_scan_args(argc, argv, "11", &rb_num, &rb_labels);
|
274
|
+
|
275
|
+
switch(TYPE(rb_num)) {
|
276
|
+
case T_FLOAT:
|
277
|
+
case T_FIXNUM:
|
278
|
+
case T_BIGNUM:
|
279
|
+
case T_RATIONAL:
|
280
|
+
value = NUM2DBL(rb_num);
|
281
|
+
break;
|
282
|
+
default:
|
283
|
+
rb_raise(rb_eArgError, "CMetrics::Untyped#set can handle numerics values only.");
|
284
|
+
}
|
285
|
+
|
286
|
+
ts = cmt_time_now();
|
287
|
+
if (!NIL_P(rb_labels)) {
|
288
|
+
switch(TYPE(rb_labels)) {
|
289
|
+
case T_STRING:
|
290
|
+
labels = (char *[]) { StringValuePtr(rb_labels) };
|
291
|
+
labels_count = 1;
|
292
|
+
ret = cmt_untyped_set(cmetricsUntyped->untyped, ts, value,
|
293
|
+
labels_count, labels);
|
294
|
+
break;
|
295
|
+
case T_SYMBOL:
|
296
|
+
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
|
297
|
+
labels_count = 1;
|
298
|
+
ret = cmt_untyped_set(cmetricsUntyped->untyped, ts, value,
|
299
|
+
labels_count, labels);
|
300
|
+
break;
|
301
|
+
case T_ARRAY:
|
302
|
+
labels_count = (int)RARRAY_LEN(rb_labels);
|
303
|
+
labels = ALLOCV_N(char *, tmp_label, labels_count);
|
304
|
+
for (i = 0; i < labels_count; i++) {
|
305
|
+
VALUE item = RARRAY_AREF(rb_labels, i);
|
306
|
+
switch(TYPE(item)) {
|
307
|
+
case T_SYMBOL:
|
308
|
+
labels[i] = RSTRING_PTR(rb_sym2str(item));
|
309
|
+
break;
|
310
|
+
case T_STRING:
|
311
|
+
labels[i] = StringValuePtr(item);
|
312
|
+
break;
|
313
|
+
default:
|
314
|
+
rb_raise(rb_eArgError, "labels must be Symbol/String");
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
ret = cmt_untyped_set(cmetricsUntyped->untyped, ts, value,
|
319
|
+
labels_count, labels);
|
320
|
+
|
321
|
+
ALLOCV_END(tmp_label);
|
322
|
+
|
323
|
+
break;
|
324
|
+
default:
|
325
|
+
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
|
326
|
+
}
|
327
|
+
} else {
|
328
|
+
ret = cmt_untyped_set(cmetricsUntyped->untyped, ts, value,
|
329
|
+
labels_count, labels);
|
330
|
+
}
|
331
|
+
|
332
|
+
if (ret == 0) {
|
333
|
+
return Qtrue;
|
334
|
+
} else {
|
335
|
+
return Qfalse;
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
/*
|
340
|
+
* Set label into untyped.
|
341
|
+
*
|
342
|
+
* @return [Boolean]
|
343
|
+
*/
|
344
|
+
|
345
|
+
static VALUE
|
346
|
+
rb_cmetrics_untyped_add_label(VALUE self, VALUE rb_key, VALUE rb_value)
|
347
|
+
{
|
348
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
349
|
+
char *key, *value;
|
350
|
+
int ret = 0;
|
351
|
+
|
352
|
+
TypedData_Get_Struct(
|
353
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
354
|
+
|
355
|
+
if (!cmetricsUntyped->untyped) {
|
356
|
+
rb_raise(rb_eRuntimeError, "Create untyped with CMetrics::Untyped#create first.");
|
357
|
+
}
|
358
|
+
|
359
|
+
switch(TYPE(rb_key)) {
|
360
|
+
case T_STRING:
|
361
|
+
key = StringValuePtr(rb_key);
|
362
|
+
break;
|
363
|
+
case T_SYMBOL:
|
364
|
+
key = RSTRING_PTR(rb_sym2str(rb_key));
|
365
|
+
break;
|
366
|
+
default:
|
367
|
+
rb_raise(rb_eArgError, "key should be String or Symbol class instance.");
|
368
|
+
}
|
369
|
+
|
370
|
+
switch(TYPE(rb_value)) {
|
371
|
+
case T_STRING:
|
372
|
+
value = StringValuePtr(rb_value);
|
373
|
+
break;
|
374
|
+
case T_SYMBOL:
|
375
|
+
value = RSTRING_PTR(rb_sym2str(rb_value));
|
376
|
+
break;
|
377
|
+
default:
|
378
|
+
rb_raise(rb_eArgError, "value should be String or Symbol class instance.");
|
379
|
+
}
|
380
|
+
ret = cmt_label_add(cmetricsUntyped->instance, key, value);
|
381
|
+
|
382
|
+
if (ret == 0) {
|
383
|
+
return Qtrue;
|
384
|
+
} else {
|
385
|
+
return Qfalse;
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
static VALUE
|
390
|
+
rb_cmetrics_untyped_to_prometheus(VALUE self)
|
391
|
+
{
|
392
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
393
|
+
cmt_sds_t prom;
|
394
|
+
VALUE str;
|
395
|
+
|
396
|
+
TypedData_Get_Struct(
|
397
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
398
|
+
|
399
|
+
prom = cmt_encode_prometheus_create(cmetricsUntyped->instance, CMT_TRUE);
|
400
|
+
|
401
|
+
str = rb_str_new2(prom);
|
402
|
+
|
403
|
+
cmt_encode_prometheus_destroy(prom);
|
404
|
+
|
405
|
+
return str;
|
406
|
+
}
|
407
|
+
|
408
|
+
static VALUE
|
409
|
+
rb_cmetrics_untyped_to_influx(VALUE self)
|
410
|
+
{
|
411
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
412
|
+
cmt_sds_t prom;
|
413
|
+
VALUE str;
|
414
|
+
|
415
|
+
TypedData_Get_Struct(
|
416
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
417
|
+
|
418
|
+
prom = cmt_encode_influx_create(cmetricsUntyped->instance);
|
419
|
+
|
420
|
+
str = rb_str_new2(prom);
|
421
|
+
|
422
|
+
cmt_encode_influx_destroy(prom);
|
423
|
+
|
424
|
+
return str;
|
425
|
+
}
|
426
|
+
|
427
|
+
static VALUE
|
428
|
+
rb_cmetrics_untyped_to_msgpack(VALUE self)
|
429
|
+
{
|
430
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
431
|
+
char *buffer;
|
432
|
+
size_t buffer_size;
|
433
|
+
int ret = 0;
|
434
|
+
|
435
|
+
TypedData_Get_Struct(
|
436
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
437
|
+
|
438
|
+
ret = cmt_encode_msgpack_create(cmetricsUntyped->instance, &buffer, &buffer_size);
|
439
|
+
|
440
|
+
if (ret == 0) {
|
441
|
+
return rb_str_new(buffer, buffer_size);
|
442
|
+
} else {
|
443
|
+
return Qnil;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
static VALUE
|
448
|
+
rb_cmetrics_untyped_to_text(VALUE self)
|
449
|
+
{
|
450
|
+
struct CMetricsUntyped* cmetricsUntyped;
|
451
|
+
cmt_sds_t buffer;
|
452
|
+
VALUE text;
|
453
|
+
|
454
|
+
TypedData_Get_Struct(
|
455
|
+
self, struct CMetricsUntyped, &rb_cmetrics_untyped_type, cmetricsUntyped);
|
456
|
+
|
457
|
+
buffer = cmt_encode_text_create(cmetricsUntyped->instance);
|
458
|
+
if (buffer == NULL) {
|
459
|
+
return Qnil;
|
460
|
+
}
|
461
|
+
|
462
|
+
text = rb_str_new2(buffer);
|
463
|
+
|
464
|
+
cmt_sds_destroy(buffer);
|
465
|
+
|
466
|
+
return text;
|
467
|
+
}
|
468
|
+
|
469
|
+
void Init_cmetrics_untyped(VALUE rb_mCMetrics)
|
470
|
+
{
|
471
|
+
rb_cUntyped = rb_define_class_under(rb_mCMetrics, "Untyped", rb_cObject);
|
472
|
+
|
473
|
+
rb_define_alloc_func(rb_cUntyped, rb_cmetrics_untyped_alloc);
|
474
|
+
|
475
|
+
rb_define_method(rb_cUntyped, "initialize", rb_cmetrics_untyped_initialize, 0);
|
476
|
+
rb_define_method(rb_cUntyped, "create", rb_cmetrics_untyped_create, -1);
|
477
|
+
rb_define_method(rb_cUntyped, "get_value", rb_cmetrics_untyped_get_value, -1);
|
478
|
+
rb_define_method(rb_cUntyped, "value", rb_cmetrics_untyped_get_value, -1);
|
479
|
+
rb_define_method(rb_cUntyped, "val", rb_cmetrics_untyped_get_value, -1);
|
480
|
+
rb_define_method(rb_cUntyped, "set", rb_cmetrics_untyped_set, -1);
|
481
|
+
rb_define_method(rb_cUntyped, "val=", rb_cmetrics_untyped_set, -1);
|
482
|
+
rb_define_method(rb_cUntyped, "value=", rb_cmetrics_untyped_set, -1);
|
483
|
+
rb_define_method(rb_cUntyped, "add_label", rb_cmetrics_untyped_add_label, 2);
|
484
|
+
rb_define_method(rb_cUntyped, "to_influx", rb_cmetrics_untyped_to_influx, 0);
|
485
|
+
rb_define_method(rb_cUntyped, "to_prometheus", rb_cmetrics_untyped_to_prometheus, 0);
|
486
|
+
rb_define_method(rb_cUntyped, "to_msgpack", rb_cmetrics_untyped_to_msgpack, 0);
|
487
|
+
rb_define_method(rb_cUntyped, "to_s", rb_cmetrics_untyped_to_text, 0);
|
488
|
+
}
|
data/ext/cmetrics/extconf.rb
CHANGED
@@ -28,7 +28,7 @@ class BuildCMetrics
|
|
28
28
|
@recipe.target = File.join(ROOT, "ports")
|
29
29
|
@recipe.files << {
|
30
30
|
url: "file://#{ROOT}/ext/#{@recipe.name}-#{@recipe.version}.tar.gz",
|
31
|
-
sha256sum: "
|
31
|
+
sha256sum: "5ba909df989bf7f3404000d9e04702eaa47cbfd51bb8ec161ca19011f95bc360",
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
data/lib/cmetrics/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmetrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Hatake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- ext/cmetrics/cmetrics_counter.c
|
106
106
|
- ext/cmetrics/cmetrics_gauge.c
|
107
107
|
- ext/cmetrics/cmetrics_serde.c
|
108
|
+
- ext/cmetrics/cmetrics_untyped.c
|
108
109
|
- ext/cmetrics/extconf.rb
|
109
110
|
- lib/cmetrics.rb
|
110
111
|
- lib/cmetrics/version.rb
|