Class: CMetrics::Gauge
- Inherits:
-
Object
- Object
- CMetrics::Gauge
- Defined in:
- ext/cmetrics/cmetrics_gauge.c
Instance Method Summary collapse
-
#add(*args) ⇒ Boolean
Add value into counter.
-
#add_label(rb_key, rb_value) ⇒ Boolean
Set label into gauge.
-
#create(*args) ⇒ Object
Create gauge.
-
#dec(*args) ⇒ Boolean
Just decrement gauge.
-
#decrement(*args) ⇒ Boolean
Just decrement gauge.
- #get_value(*args) ⇒ Object
-
#inc(*args) ⇒ Boolean
Just increment gauge.
-
#increment(*args) ⇒ Boolean
Just increment gauge.
-
#initialize ⇒ Gauge
constructor
Initailize Gauge class.
-
#set(*args) ⇒ Boolean
Set value into gauge.
-
#sub(*args) ⇒ Boolean
Subtract value into counter.
- #to_influx ⇒ Object
- #to_msgpack ⇒ Object
- #to_prometheus ⇒ Object
- #to_s ⇒ Object
- #val(*args) ⇒ Object
-
#val=(*args) ⇒ Boolean
Set value into gauge.
- #value(*args) ⇒ Object
-
#value=(*args) ⇒ Boolean
Set value into gauge.
Constructor Details
#initialize ⇒ Gauge
Initailize Gauge class.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 86
static VALUE
rb_cmetrics_gauge_initialize(VALUE self)
{
struct CMetricsGauge* cmetricsGauge;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
cmt_initialize();
cmetricsGauge->instance = cmt_create();
cmetricsGauge->gauge = NULL;
return Qnil;
}
|
Instance Method Details
#add(*args) ⇒ Boolean
Add value into counter.
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 431
static VALUE
rb_cmetrics_gauge_add(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels, rb_num;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "11", &rb_num, &rb_labels);
switch(TYPE(rb_num)) {
case T_FLOAT:
case T_FIXNUM:
case T_BIGNUM:
case T_RATIONAL:
value = NUM2DBL(rb_num);
break;
default:
rb_raise(rb_eArgError, "CMetrics::Gauge#add can handle numerics values only.");
}
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_add(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_add(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_add(cmetricsGauge->gauge, ts, value,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_add(cmetricsGauge->gauge, ts, value,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#add_label(rb_key, rb_value) ⇒ Boolean
Set label into gauge.
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 707
static VALUE
rb_cmetrics_gauge_add_label(VALUE self, VALUE rb_key, VALUE rb_value)
{
struct CMetricsGauge* cmetricsGauge;
char *key, *value;
int ret = 0;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
switch(TYPE(rb_key)) {
case T_STRING:
key = StringValuePtr(rb_key);
break;
case T_SYMBOL:
key = RSTRING_PTR(rb_sym2str(rb_key));
break;
default:
rb_raise(rb_eArgError, "key should be String or Symbol class instance.");
}
switch(TYPE(rb_value)) {
case T_STRING:
value = StringValuePtr(rb_value);
break;
case T_SYMBOL:
value = RSTRING_PTR(rb_sym2str(rb_value));
break;
default:
rb_raise(rb_eArgError, "value should be String or Symbol class instance.");
}
ret = cmt_label_add(cmetricsGauge->instance, key, value);
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#create(*args) ⇒ Object
Create gauge.
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 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 106
static VALUE
rb_cmetrics_gauge_create(int argc, VALUE* argv, VALUE self)
{
VALUE rb_namespace, rb_subsystem, rb_name, rb_help, rb_labels;
struct CMetricsGauge* cmetricsGauge;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
rb_scan_args(argc, argv, "41", &rb_namespace, &rb_subsystem, &rb_name, &rb_help, &rb_labels);
Check_Type(rb_namespace, T_STRING);
Check_Type(rb_subsystem, T_STRING);
Check_Type(rb_name, T_STRING);
Check_Type(rb_help, T_STRING);
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
cmetricsGauge->gauge = cmt_gauge_create(cmetricsGauge->instance,
StringValuePtr(rb_namespace),
StringValuePtr(rb_subsystem),
StringValuePtr(rb_name),
StringValuePtr(rb_help),
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
cmetricsGauge->gauge = cmt_gauge_create(cmetricsGauge->instance,
StringValuePtr(rb_namespace),
StringValuePtr(rb_subsystem),
StringValuePtr(rb_name),
StringValuePtr(rb_help),
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
cmetricsGauge->gauge = cmt_gauge_create(cmetricsGauge->instance,
StringValuePtr(rb_namespace),
StringValuePtr(rb_subsystem),
StringValuePtr(rb_name),
StringValuePtr(rb_help),
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
cmetricsGauge->gauge = cmt_gauge_create(cmetricsGauge->instance,
StringValuePtr(rb_namespace),
StringValuePtr(rb_subsystem),
StringValuePtr(rb_name),
StringValuePtr(rb_help),
labels_count, labels);
}
return Qnil;
}
|
#dec(*args) ⇒ Boolean
Just decrement gauge.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 275
static VALUE
rb_cmetrics_gauge_decrement(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#decrement(*args) ⇒ Boolean
Just decrement gauge.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 275
static VALUE
rb_cmetrics_gauge_decrement(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_dec(cmetricsGauge->gauge, ts,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#get_value(*args) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 350
static VALUE
rb_cmetrics_gauge_get_value(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
}
if (ret == 0) {
return DBL2NUM(value);
} else {
return Qnil;
}
}
|
#inc(*args) ⇒ Boolean
Just increment gauge.
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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 194
static VALUE
rb_cmetrics_gauge_increment(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#increment(*args) ⇒ Boolean
Just increment gauge.
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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 194
static VALUE
rb_cmetrics_gauge_increment(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_inc(cmetricsGauge->gauge, ts,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#set(*args) ⇒ Boolean
Set value into gauge.
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 615
static VALUE
rb_cmetrics_gauge_set(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels, rb_num;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "11", &rb_num, &rb_labels);
switch(TYPE(rb_num)) {
case T_FLOAT:
case T_FIXNUM:
case T_BIGNUM:
case T_RATIONAL:
value = NUM2DBL(rb_num);
break;
default:
rb_raise(rb_eArgError, "CMetrics::Gauge#set can handle numerics values only.");
}
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#sub(*args) ⇒ Boolean
Subtract value into counter.
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 523
static VALUE
rb_cmetrics_gauge_sub(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels, rb_num;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "11", &rb_num, &rb_labels);
switch(TYPE(rb_num)) {
case T_FLOAT:
case T_FIXNUM:
case T_BIGNUM:
case T_RATIONAL:
value = NUM2DBL(rb_num);
break;
default:
rb_raise(rb_eArgError, "CMetrics::Gauge#add can handle numerics values only.");
}
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_sub(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_sub(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_sub(cmetricsGauge->gauge, ts, value,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_sub(cmetricsGauge->gauge, ts, value,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#to_influx ⇒ Object
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 752
static VALUE
rb_cmetrics_gauge_to_influx(VALUE self)
{
struct CMetricsGauge* cmetricsGauge;
cmt_sds_t prom;
VALUE str;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
prom = cmt_encode_influx_create(cmetricsGauge->instance);
str = rb_str_new2(prom);
cmt_encode_influx_destroy(prom);
return str;
}
|
#to_msgpack ⇒ Object
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 790
static VALUE
rb_cmetrics_gauge_to_msgpack(VALUE self)
{
struct CMetricsGauge* cmetricsGauge;
char *buffer;
size_t buffer_size;
int ret = 0;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
ret = cmt_encode_msgpack_create(cmetricsGauge->instance, &buffer, &buffer_size);
if (ret == 0) {
return rb_str_new(buffer, buffer_size);
} else {
return Qnil;
}
}
|
#to_prometheus ⇒ Object
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 771
static VALUE
rb_cmetrics_gauge_to_prometheus(VALUE self)
{
struct CMetricsGauge* cmetricsGauge;
cmt_sds_t prom;
VALUE str;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
prom = cmt_encode_prometheus_create(cmetricsGauge->instance, CMT_TRUE);
str = rb_str_new2(prom);
cmt_encode_prometheus_destroy(prom);
return str;
}
|
#to_s ⇒ Object
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 810
static VALUE
rb_cmetrics_gauge_to_text(VALUE self)
{
struct CMetricsGauge* cmetricsGauge;
cmt_sds_t buffer;
VALUE text;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
buffer = cmt_encode_text_create(cmetricsGauge->instance);
if (buffer == NULL) {
return Qnil;
}
text = rb_str_new2(buffer);
cmt_sds_destroy(buffer);
return text;
}
|
#val(*args) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 350
static VALUE
rb_cmetrics_gauge_get_value(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
}
if (ret == 0) {
return DBL2NUM(value);
} else {
return Qnil;
}
}
|
#val=(*args) ⇒ Boolean
Set value into gauge.
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 615
static VALUE
rb_cmetrics_gauge_set(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels, rb_num;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "11", &rb_num, &rb_labels);
switch(TYPE(rb_num)) {
case T_FLOAT:
case T_FIXNUM:
case T_BIGNUM:
case T_RATIONAL:
value = NUM2DBL(rb_num);
break;
default:
rb_raise(rb_eArgError, "CMetrics::Gauge#set can handle numerics values only.");
}
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#value(*args) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 350
static VALUE
rb_cmetrics_gauge_get_value(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels;
struct CMetricsGauge* cmetricsGauge;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "01", &rb_labels);
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_get_val(cmetricsGauge->gauge,
labels_count, labels, &value);
}
if (ret == 0) {
return DBL2NUM(value);
} else {
return Qnil;
}
}
|
#value=(*args) ⇒ Boolean
Set value into gauge.
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'ext/cmetrics/cmetrics_gauge.c', line 615
static VALUE
rb_cmetrics_gauge_set(int argc, VALUE* argv, VALUE self)
{
VALUE rb_labels, rb_num;
struct CMetricsGauge* cmetricsGauge;
uint64_t ts;
int ret = 0;
double value = 0;
char **labels = NULL;
int labels_count = 0;
VALUE tmp_label;
long i;
TypedData_Get_Struct(
self, struct CMetricsGauge, &rb_cmetrics_gauge_type, cmetricsGauge);
if (!cmetricsGauge->gauge) {
rb_raise(rb_eRuntimeError, "Create gauge with CMetrics::Gauge#create first.");
}
rb_scan_args(argc, argv, "11", &rb_num, &rb_labels);
switch(TYPE(rb_num)) {
case T_FLOAT:
case T_FIXNUM:
case T_BIGNUM:
case T_RATIONAL:
value = NUM2DBL(rb_num);
break;
default:
rb_raise(rb_eArgError, "CMetrics::Gauge#set can handle numerics values only.");
}
ts = cmt_time_now();
if (!NIL_P(rb_labels)) {
switch(TYPE(rb_labels)) {
case T_STRING:
labels = (char *[]) { StringValuePtr(rb_labels) };
labels_count = 1;
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_SYMBOL:
labels = (char *[]) { RSTRING_PTR(rb_sym2str(rb_labels)) };
labels_count = 1;
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
break;
case T_ARRAY:
labels_count = (int)RARRAY_LEN(rb_labels);
labels = ALLOCV_N(char *, tmp_label, labels_count);
for (i = 0; i < labels_count; i++) {
VALUE item = RARRAY_AREF(rb_labels, i);
switch(TYPE(item)) {
case T_SYMBOL:
labels[i] = RSTRING_PTR(rb_sym2str(item));
break;
case T_STRING:
labels[i] = StringValuePtr(item);
break;
default:
rb_raise(rb_eArgError, "labels must be Symbol/String");
}
}
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
ALLOCV_END(tmp_label);
break;
default:
rb_raise(rb_eArgError, "labels should be String, Symbol or Array class instance.");
}
} else {
ret = cmt_gauge_set(cmetricsGauge->gauge, ts, value,
labels_count, labels);
}
if (ret == 0) {
return Qtrue;
} else {
return Qfalse;
}
}
|