@@ -139,49 +139,61 @@ void StatsdClient::cleanup(string& key)
139
139
}
140
140
}
141
141
142
- int StatsdClient::dec (const string& key, float sample_rate)
142
+ int StatsdClient::dec (const string& key, float sample_rate, tags_t tags )
143
143
{
144
- return count (key, -1 , sample_rate);
144
+ return count (key, -1 , sample_rate, tags );
145
145
}
146
146
147
- int StatsdClient::inc (const string& key, float sample_rate)
147
+ int StatsdClient::inc (const string& key, float sample_rate, tags_t tags )
148
148
{
149
- return count (key, 1 , sample_rate);
149
+ return count (key, 1 , sample_rate, tags );
150
150
}
151
151
152
- int StatsdClient::count (const string& key, size_t value, float sample_rate)
152
+ int StatsdClient::count (const string& key, size_t value, float sample_rate, tags_t tags )
153
153
{
154
- return send (key, value, " c" , sample_rate);
154
+ return send (key, value, " c" , sample_rate, tags );
155
155
}
156
156
157
- int StatsdClient::gauge (const string& key, size_t value, float sample_rate)
157
+ int StatsdClient::gauge (const string& key, size_t value, float sample_rate, tags_t tags )
158
158
{
159
- return send (key, value, " g" , sample_rate);
159
+ return send (key, value, " g" , sample_rate, tags );
160
160
}
161
161
162
- int StatsdClient::timing (const string& key, size_t ms, float sample_rate)
162
+ int StatsdClient::timing (const string& key, size_t ms, float sample_rate, tags_t tags )
163
163
{
164
- return send (key, ms, " ms" , sample_rate);
164
+ return send (key, ms, " ms" , sample_rate, tags );
165
165
}
166
166
167
- int StatsdClient::send (string key, size_t value, const string &type, float sample_rate)
167
+ int StatsdClient::send (string key, size_t value, const string &type, float sample_rate, tags_t tags )
168
168
{
169
169
if (!should_send (this ->d , sample_rate)) {
170
170
return 0 ;
171
171
}
172
172
173
173
cleanup (key);
174
174
175
+ std::string tags_str;
176
+ if (!tags.empty ()) {
177
+ tags_str.reserve (256 );
178
+ tags_str += " |#" ;
179
+ for (std::size_t i = 0 , size = tags.size (); i < size; ++i) {
180
+ tags_str += tags[i];
181
+ if (i < size -1 ) {
182
+ tags_str += " ," ;
183
+ }
184
+ }
185
+ }
186
+
175
187
char buf[256 ];
176
188
if ( fequal ( sample_rate, 1.0 ) )
177
189
{
178
- snprintf (buf, sizeof (buf), " %s%s:%zd|%s" ,
179
- d->ns .c_str (), key.c_str (), value, type.c_str ());
190
+ snprintf (buf, sizeof (buf), " %s%s:%zd|%s%s " ,
191
+ d->ns .c_str (), key.c_str (), value, type.c_str (), tags_str. c_str () );
180
192
}
181
193
else
182
194
{
183
- snprintf (buf, sizeof (buf), " %s%s:%zd|%s|@%.2f" ,
184
- d->ns .c_str (), key.c_str (), value, type.c_str (), sample_rate);
195
+ snprintf (buf, sizeof (buf), " %s%s:%zd|%s|@%.2f%s " ,
196
+ d->ns .c_str (), key.c_str (), value, type.c_str (), sample_rate, tags_str. c_str () );
185
197
}
186
198
187
199
return send (buf);
0 commit comments