Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
distinguish between numeric and string values in statsd packets
  • Loading branch information
Jason Lunz committed Jan 13, 2016
commit b7853d17d8a1031d361905f11496810b2b33f243
4 changes: 4 additions & 0 deletions src/brubeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#define MAX_ADDR 256

typedef double value_t;
typedef union {
value_t n;
char *s;
} sample_value_t;
typedef uint64_t hash_t;

struct brubeck_server;
Expand Down
26 changes: 13 additions & 13 deletions src/metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ new_metric(struct brubeck_server *server, const char *key, size_t key_len, uint8
return metric;
}

typedef void (*mt_prototype_record)(struct brubeck_metric *, value_t);
typedef void (*mt_prototype_record)(struct brubeck_metric *, sample_value_t);
typedef void (*mt_prototype_sample)(struct brubeck_metric *, brubeck_sample_cb, void *);


Expand All @@ -32,11 +32,11 @@ typedef void (*mt_prototype_sample)(struct brubeck_metric *, brubeck_sample_cb,
* ALLOC: mt + 4 bytes
*********************************************/
static void
gauge__record(struct brubeck_metric *metric, value_t value)
gauge__record(struct brubeck_metric *metric, sample_value_t value)
{
pthread_spin_lock(&metric->lock);
{
metric->as.gauge.value = value;
metric->as.gauge.value = value.n;
}
pthread_spin_unlock(&metric->lock);
}
Expand All @@ -62,11 +62,11 @@ gauge__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
* ALLOC: mt + 4
*********************************************/
static void
meter__record(struct brubeck_metric *metric, value_t value)
meter__record(struct brubeck_metric *metric, sample_value_t value)
{
pthread_spin_lock(&metric->lock);
{
metric->as.meter.value += value;
metric->as.meter.value += value.n;
}
pthread_spin_unlock(&metric->lock);
}
Expand All @@ -93,19 +93,19 @@ meter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
* ALLOC: mt + 4 + 4 + 4
*********************************************/
static void
counter__record(struct brubeck_metric *metric, value_t value)
counter__record(struct brubeck_metric *metric, sample_value_t value)
{
pthread_spin_lock(&metric->lock);
{
if (metric->as.counter.previous > 0.0) {
value_t diff = (value >= metric->as.counter.previous) ?
(value - metric->as.counter.previous) :
(value);
value_t diff = (value.n >= metric->as.counter.previous) ?
(value.n - metric->as.counter.previous) :
(value.n);

metric->as.counter.value += diff;
}

metric->as.counter.previous = value;
metric->as.counter.previous = value.n;
}
pthread_spin_unlock(&metric->lock);
}
Expand All @@ -132,11 +132,11 @@ counter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *o
* ALLOC: mt + 16 + 4
*********************************************/
static void
histogram__record(struct brubeck_metric *metric, value_t value)
histogram__record(struct brubeck_metric *metric, sample_value_t value)
{
pthread_spin_lock(&metric->lock);
{
brubeck_histo_push(&metric->as.histogram, value);
brubeck_histo_push(&metric->as.histogram, value.n);
}
pthread_spin_unlock(&metric->lock);
}
Expand Down Expand Up @@ -252,7 +252,7 @@ void brubeck_metric_sample(struct brubeck_metric *metric, brubeck_sample_cb cb,
_prototypes[metric->type].sample(metric, cb, backend);
}

void brubeck_metric_record(struct brubeck_metric *metric, value_t value)
void brubeck_metric_record(struct brubeck_metric *metric, sample_value_t value)
{
_prototypes[metric->type].record(metric, value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef void (*brubeck_sample_cb)(
void *backend);

void brubeck_metric_sample(struct brubeck_metric *metric, brubeck_sample_cb cb, void *backend);
void brubeck_metric_record(struct brubeck_metric *metric, value_t value);
void brubeck_metric_record(struct brubeck_metric *metric, sample_value_t value);

struct brubeck_metric *brubeck_metric_new(struct brubeck_server *server, const char *, size_t, uint8_t);
struct brubeck_metric *brubeck_metric_find(struct brubeck_server *server, const char *, size_t, uint8_t);
Expand Down
2 changes: 1 addition & 1 deletion src/samplers/statsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct brubeck_statsd_msg {
char *key; /* The key of the message, NULL terminated */
uint16_t key_len; /* length of the key */
uint16_t type; /* type of the messaged, as a brubeck_mt_t */
value_t value; /* integer value of the message */
sample_value_t value; /* value of the message */
char *trail; /* Any data following the 'key:value|type' construct, NULL terminated*/
};

Expand Down