@@ -30,7 +30,7 @@ new_metric(struct brubeck_server *server, const char *key, size_t key_len, uint8
3030 return metric ;
3131}
3232
33- typedef void (* mt_prototype_record )(struct brubeck_metric * , value_t );
33+ typedef void (* mt_prototype_record )(struct brubeck_metric * , value_t , value_t );
3434typedef void (* mt_prototype_sample )(struct brubeck_metric * , brubeck_sample_cb , void * );
3535
3636
@@ -40,7 +40,7 @@ typedef void (*mt_prototype_sample)(struct brubeck_metric *, brubeck_sample_cb,
4040 * ALLOC: mt + 4 bytes
4141 *********************************************/
4242static void
43- gauge__record (struct brubeck_metric * metric , value_t value )
43+ gauge__record (struct brubeck_metric * metric , value_t value , value_t sample_rate )
4444{
4545 pthread_spin_lock (& metric -> lock );
4646 {
@@ -70,8 +70,11 @@ gauge__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
7070 * ALLOC: mt + 4
7171 *********************************************/
7272static void
73- meter__record (struct brubeck_metric * metric , value_t value )
73+ meter__record (struct brubeck_metric * metric , value_t value , value_t sample_rate )
7474{
75+ /* upsample */
76+ value *= (1.0 / sample_rate );
77+
7578 pthread_spin_lock (& metric -> lock );
7679 {
7780 metric -> as .meter .value += value ;
@@ -101,8 +104,11 @@ meter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
101104 * ALLOC: mt + 4 + 4 + 4
102105 *********************************************/
103106static void
104- counter__record (struct brubeck_metric * metric , value_t value )
107+ counter__record (struct brubeck_metric * metric , value_t value , value_t sample_rate )
105108{
109+ /* upsample */
110+ value *= (1.0 / sample_rate );
111+
106112 pthread_spin_lock (& metric -> lock );
107113 {
108114 if (metric -> as .counter .previous > 0.0 ) {
@@ -140,11 +146,11 @@ counter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *o
140146 * ALLOC: mt + 16 + 4
141147 *********************************************/
142148static void
143- histogram__record (struct brubeck_metric * metric , value_t value )
149+ histogram__record (struct brubeck_metric * metric , value_t value , value_t sample_rate )
144150{
145151 pthread_spin_lock (& metric -> lock );
146152 {
147- brubeck_histo_push (& metric -> as .histogram , value );
153+ brubeck_histo_push (& metric -> as .histogram , value , sample_rate );
148154 }
149155 pthread_spin_unlock (& metric -> lock );
150156}
@@ -260,9 +266,9 @@ void brubeck_metric_sample(struct brubeck_metric *metric, brubeck_sample_cb cb,
260266 _prototypes [metric -> type ].sample (metric , cb , backend );
261267}
262268
263- void brubeck_metric_record (struct brubeck_metric * metric , value_t value )
269+ void brubeck_metric_record (struct brubeck_metric * metric , value_t value , value_t sample_rate )
264270{
265- _prototypes [metric -> type ].record (metric , value );
271+ _prototypes [metric -> type ].record (metric , value , sample_rate );
266272}
267273
268274struct brubeck_metric *
0 commit comments