cmetrics 0.1.5 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 361bb2d812b12da260716172fe76c863c219262c499eedbbeba103b0c06f96df
4
- data.tar.gz: 037562a3edf92bb19db31b2642bc8907d6e99dd21cd61a812c754508f8dd21cd
3
+ metadata.gz: '039922256e09204e10d0e707fee425ecc22f835c9cf373ac6383666bb2a27517'
4
+ data.tar.gz: 62909440c1a9c8e347195fe4f11f7738b08e159dd22478ac49d794049f6bd275
5
5
  SHA512:
6
- metadata.gz: d2ac8990af70be9e24984402b5bda5e3ac34a84075fd9051564b5e79d35e24c678c1f413f6064f9df9c5c08df2bf62c8c9d1ab1197abd84d072aaae24d99290c
7
- data.tar.gz: 94dd6beaf0ef980bca11ec2b076582f14843560e8f737ee72cdda85de550d8bdf6506dde3d7a11768dac29fbcebc8a2c6a5ade527c03fe12c904a90af8b2b345
6
+ metadata.gz: 2519712adf54ab9dd3ad43e658c6fc504bb24224f21d7acf36ca4cc8bddfce06ac93412f24c963c7739a1d8de7e21d27610776e9f0149104971dfea676ad8e13
7
+ data.tar.gz: b00ed69d225f816d549b2b3078ed919d779be994e5fe25b955e2c2147c976f69d772574657bf1ff3c3c7f475c402fc2faae1da47e345653b87467cfd4e674ce4
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`.
@@ -36,4 +36,5 @@ void Init_cmetrics(void)
36
36
  Init_cmetrics_counter(rb_mCMetrics);
37
37
  Init_cmetrics_gauge(rb_mCMetrics);
38
38
  Init_cmetrics_serde(rb_mCMetrics);
39
+ Init_cmetrics_untyped(rb_mCMetrics);
39
40
  }
@@ -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
+ }
@@ -27,19 +27,19 @@ class BuildCMetrics
27
27
  @checkpoint = ".#{@recipe.name}-#{@recipe.version}.installed"
28
28
  @recipe.target = File.join(ROOT, "ports")
29
29
  @recipe.files << {
30
- url: "file://#{ROOT}/ext/#{@recipe.name}-#{@recipe.version}.tar.gz",
31
- sha256sum: "34df0842ee23e4c9440e787722fb79cf7204ebb3fed2dc3fb5e02f4c9c4807dc",
30
+ url: "https://codeload.github.com/calyptia/cmetrics/tar.gz/v#{version}",
31
+ sha256sum: "50f74147f8247dba434099e1075755097099c6bae77456da7322bb5ffb1f3f54",
32
32
  }
33
33
  end
34
34
 
35
35
  def build
36
36
  unless File.exist?(@checkpoint)
37
37
  @recipe.cook
38
- libcmetrics_path = File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/lib/libcmetrics.a")
38
+ libcmetrics_path = Dir.glob(File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/lib*/libcmetrics.a")).first
39
39
  FileUtils.cp(libcmetrics_path, File.join(ROOT, "ext", "cmetrics", "libcmetrics.a"))
40
- libmpack_path = File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/lib/libmpack.a")
40
+ libmpack_path = Dir.glob(File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/lib*/libmpack.a")).first
41
41
  FileUtils.cp(libmpack_path, File.join(ROOT, "ext", "cmetrics", "libmpack.a"))
42
- libxxhash_path = File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/lib/libxxhash.a")
42
+ libxxhash_path = Dir.glob(File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/lib*/libxxhash.a")).first
43
43
  FileUtils.cp(libxxhash_path, File.join(ROOT, "ext", "cmetrics", "libxxhash.a"))
44
44
  include_path = File.join(ROOT, "ports/#{@recipe.host}/cmetrics/#{@version}/include/")
45
45
  FileUtils.cp_r(Dir.glob(File.join(include_path, "*")), File.join(ROOT, "ext", "cmetrics"))
@@ -52,7 +52,7 @@ class BuildCMetrics
52
52
  end
53
53
  end
54
54
 
55
- cmetrics = BuildCMetrics.new
55
+ cmetrics = BuildCMetrics.new("0.1.4")
56
56
  cmetrics.build
57
57
 
58
58
  libdir = RbConfig::CONFIG["libdir"]
@@ -63,6 +63,8 @@ find_library("xxhash", nil, __dir__)
63
63
  find_library("mpack", nil, __dir__)
64
64
  find_library("cmetrics", nil, __dir__)
65
65
 
66
+ $CFLAGS << " -std=c99 "
67
+
66
68
  have_func("gmtime_s", "time.h")
67
69
 
68
70
  create_makefile("cmetrics/cmetrics")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CMetrics
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.9"
5
5
  end
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.5
4
+ version: 0.1.9
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-08 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,12 +99,12 @@ files:
99
99
  - bin/console
100
100
  - bin/setup
101
101
  - cmetrics-ruby.gemspec
102
- - ext/cmetrics-master.tar.gz
103
102
  - ext/cmetrics/cmetrics.c
104
103
  - ext/cmetrics/cmetrics_c.h
105
104
  - ext/cmetrics/cmetrics_counter.c
106
105
  - ext/cmetrics/cmetrics_gauge.c
107
106
  - ext/cmetrics/cmetrics_serde.c
107
+ - ext/cmetrics/cmetrics_untyped.c
108
108
  - ext/cmetrics/extconf.rb
109
109
  - lib/cmetrics.rb
110
110
  - lib/cmetrics/version.rb
Binary file