@@ -15,7 +15,7 @@ new_metric(struct brubeck_server *server, const char *key, size_t key_len, uint8
1515 metric -> key [key_len ] = '\0' ;
1616 metric -> key_len = (uint16_t )key_len ;
1717
18- metric -> expire = BRUBECK_EXPIRE_ACTIVE ;
18+ metric -> state = BRUBECK_STATE_ACTIVE ;
1919 metric -> type = type ;
2020 pthread_spin_init (& metric -> lock , PTHREAD_PROCESS_PRIVATE );
2121
@@ -49,6 +49,7 @@ gauge__record(struct brubeck_metric *metric, value_t value, value_t sample_freq,
4949 } else {
5050 metric -> as .gauge .value = value ;
5151 }
52+ metric -> state = BRUBECK_STATE_ACTIVE ;
5253 }
5354 pthread_spin_unlock (& metric -> lock );
5455}
@@ -61,6 +62,7 @@ gauge__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
6162 pthread_spin_lock (& metric -> lock );
6263 {
6364 value = metric -> as .gauge .value ;
65+ metric -> state = BRUBECK_STATE_INACTIVE ;
6466 }
6567 pthread_spin_unlock (& metric -> lock );
6668
@@ -82,6 +84,7 @@ meter__record(struct brubeck_metric *metric, value_t value, value_t sample_freq,
8284 pthread_spin_lock (& metric -> lock );
8385 {
8486 metric -> as .meter .value += value ;
87+ metric -> state = BRUBECK_STATE_ACTIVE ;
8588 }
8689 pthread_spin_unlock (& metric -> lock );
8790}
@@ -95,6 +98,7 @@ meter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa
9598 {
9699 value = metric -> as .meter .value ;
97100 metric -> as .meter .value = 0.0 ;
101+ metric -> state = BRUBECK_STATE_INACTIVE ;
98102 }
99103 pthread_spin_unlock (& metric -> lock );
100104
@@ -124,6 +128,7 @@ counter__record(struct brubeck_metric *metric, value_t value, value_t sample_fre
124128 }
125129
126130 metric -> as .counter .previous = value ;
131+ metric -> state = BRUBECK_STATE_ACTIVE ;
127132 }
128133 pthread_spin_unlock (& metric -> lock );
129134}
@@ -137,6 +142,7 @@ counter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *o
137142 {
138143 value = metric -> as .counter .value ;
139144 metric -> as .counter .value = 0.0 ;
145+ metric -> state = BRUBECK_STATE_INACTIVE ;
140146 }
141147 pthread_spin_unlock (& metric -> lock );
142148
@@ -155,6 +161,7 @@ histogram__record(struct brubeck_metric *metric, value_t value, value_t sample_f
155161 pthread_spin_lock (& metric -> lock );
156162 {
157163 brubeck_histo_push (& metric -> as .histogram , value , sample_freq );
164+ metric -> state = BRUBECK_STATE_ACTIVE ;
158165 }
159166 pthread_spin_unlock (& metric -> lock );
160167}
@@ -168,6 +175,7 @@ histogram__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void
168175 pthread_spin_lock (& metric -> lock );
169176 {
170177 brubeck_histo_sample (& hsample , & metric -> as .histogram );
178+ metric -> state = BRUBECK_STATE_INACTIVE ;
171179 }
172180 pthread_spin_unlock (& metric -> lock );
173181
@@ -187,11 +195,6 @@ histogram__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void
187195 sample (key , hsample .count / (double )backend -> sample_freq , opaque );
188196 }
189197
190- /* if there have been no metrics during this sampling period,
191- * we don't need to report any of the histogram samples */
192- if (hsample .count == 0.0 )
193- return ;
194-
195198 WITH_SUFFIX (".min" ) {
196199 sample (key , hsample .min , opaque );
197200 }
@@ -333,6 +336,5 @@ brubeck_metric_find(struct brubeck_server *server, const char *key, size_t key_l
333336 brubeck_atomic_inc (& metric -> flow );
334337#endif
335338
336- metric -> expire = BRUBECK_EXPIRE_ACTIVE ;
337339 return metric ;
338340}
0 commit comments