cmetrics 0.1.4 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: caa39014510bd34dc658bb6e8f1fa555e792d113d0fee18024e387595a6a4b84
4
- data.tar.gz: 9af18715cb13b236b05c3210bbadc211a569ad4abef8fcd923af55621a2a7e4f
3
+ metadata.gz: f1dbbff3db2b8ab48525d50430ae0996558ecb1ece4f939a91a22b883b37e996
4
+ data.tar.gz: 1b940e1b8d6b008b7eac4bedd2ea7bc0607b3d7d000e10eaddb772e69fdc4be0
5
5
  SHA512:
6
- metadata.gz: c4caa6d06d460e756761607d73c23fb50a881a9522c8f9e4bebcac444ba3e432f0bf101c70098a2f3d03bf29f8dbdb355194a68422339bee9220cf976289ee88
7
- data.tar.gz: 36679c7e06d428936ddfc345e7cbb1ec9a923571a19443e54df53bd2aa37467ebd21e3a5bd67c571431e6be5851dff73e05a977a2c5fa492a72527105732ad1a
6
+ metadata.gz: fa5335b809cd35aed0ece8c7b551b016d62ab5af6739124e4fd151dfa79ab1593326c27813311828cd92950e02cc41d4924e9f4da380459f9dc8ee828044a3fb
7
+ data.tar.gz: a395971b303280ca1586fab5f190f55857eaa9b1ece6650fc92c003a7231c4af926dcfab7c887e4f39241950a7163bde82ba248164340e465aeab4ccf1b4cf87
data/README.md CHANGED
@@ -6,6 +6,12 @@
6
6
 
7
7
  A Ruby binding for [cmetrics](https://github.com/calyptia/cmetrics).
8
8
 
9
+ ## Prerequisites
10
+
11
+ * Ruby 2.4 or later with its headers
12
+ * CMake 3.13 or later due to different directory TARGETS for bundled cmetrics installation
13
+ * gcc or clang or some equivalents toolchain
14
+
9
15
  ## Installation
10
16
 
11
17
  Add this line to your application's Gemfile:
@@ -24,13 +30,13 @@ Or install it yourself as:
24
30
 
25
31
  ## Usage
26
32
 
33
+ ### Counter
34
+
27
35
  `CMetrics::Counter` is a cumulative metric that can only increase monotonically and reset to zero at restart.
28
36
  This class should be used for counting the total amount of record size or something like monotonic increasing values.
29
37
 
30
38
  ref: [Metric Types -- Counter | Prometheus documentation](https://prometheus.io/docs/concepts/metric_types/#counter)
31
39
 
32
- ### Counter
33
-
34
40
  ```ruby
35
41
  require 'cmetrics'
36
42
 
@@ -88,6 +94,35 @@ require 'cmetrics'
88
94
  @gauge.val(["localhost", "test"]) #=> 7.5
89
95
  ```
90
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
+
91
126
  ### Serde
92
127
 
93
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`.
@@ -151,6 +186,7 @@ require 'cmetrics'
151
186
  @wired_buffer = @gauge.to_msgpack + @counter.to_msgpack + @counter2.to_msgpack
152
187
  @serde = CMetrics::Serde.new
153
188
 
189
+ puts "-----Decode with procedural style-----"
154
190
  # Decode for the context 1
155
191
  @serde.from_msgpack(@wired_buffer)
156
192
  puts @serde.to_prometheus
@@ -160,6 +196,12 @@ puts @serde.to_prometheus
160
196
  # Decode for the context 3
161
197
  @serde.from_msgpack(@wired_buffer)
162
198
  puts @serde.to_prometheus
199
+
200
+ puts "-----Decode with streaming style-----"
201
+ # Or, use streaming style API
202
+ @serde.feed_each(@wired_buffer) do |serde|
203
+ puts serde.to_prometheus
204
+ end
163
205
  ```
164
206
 
165
207
  ## Development
Binary file
@@ -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);
@@ -548,7 +548,7 @@ rb_cmetrics_counter_add_label(VALUE self, VALUE rb_key, VALUE rb_value)
548
548
  value = RSTRING_PTR(rb_sym2str(rb_value));
549
549
  break;
550
550
  default:
551
- rb_raise(rb_eArgError, "key should be String or Symbol class instance.");
551
+ rb_raise(rb_eArgError, "value should be String or Symbol class instance.");
552
552
  }
553
553
  ret = cmt_label_add(cmetricsCounter->instance, key, value);
554
554
 
@@ -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);
@@ -721,7 +721,7 @@ rb_cmetrics_gauge_add_label(VALUE self, VALUE rb_key, VALUE rb_value)
721
721
  value = RSTRING_PTR(rb_sym2str(rb_value));
722
722
  break;
723
723
  default:
724
- rb_raise(rb_eArgError, "key should be String or Symbol class instance.");
724
+ rb_raise(rb_eArgError, "value should be String or Symbol class instance.");
725
725
  }
726
726
 
727
727
  ret = cmt_label_add(cmetricsGauge->instance, key, value);
@@ -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
+ }
@@ -28,18 +28,18 @@ 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: "34df0842ee23e4c9440e787722fb79cf7204ebb3fed2dc3fb5e02f4c9c4807dc",
31
+ sha256sum: "3375ac1073b0bbea44ee9986601977ef04b119a74a7c663e2486a3ed31953203",
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"))
@@ -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.4"
4
+ VERSION = "0.1.8"
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.4
4
+ version: 0.1.8
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-07 00:00:00.000000000 Z
11
+ date: 2021-07-13 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