@@ -25,16 +25,17 @@ namespace monitoring
2525Metric DerivedMetrics::rate (Metric& metric)
2626{
2727 // disallow string
28- std::string name = metric.getName ();
28+ auto tags = metric.getTags ();
29+ std::string key = metric.getName () + std::string (tags.begin (), tags.end ());
2930 if (metric.getType () == MetricType::STRING) {
3031 throw MonitoringException (" DerivedMetrics/ProcessMetric" , " Not able to process string values" );
3132 }
3233
3334 // search for previous value
34- auto search = mStorage .find (name );
35+ auto search = mStorage .find (key );
3536 if (search == mStorage .end ()) {
36- mStorage .insert (std::make_pair (name , metric));
37- return Metric{(double ) 0.0 , name + " Rate" };
37+ mStorage .insert (std::make_pair (key , metric));
38+ return Metric{(double ) 0.0 , metric. getName () + " Rate" }. addTags ( std::move (tags)) ;
3839 }
3940
4041 auto timestampDifference = std::chrono::duration_cast<std::chrono::milliseconds>(
@@ -52,25 +53,25 @@ Metric DerivedMetrics::rate(Metric& metric)
5253 auto rate = boost::apply_visitor (VariantVisitorRate (timestampCount), current, previous);
5354
5455 // swap metrics
55- mStorage .erase (name);
56- mStorage .insert (std::make_pair (name, metric));
57-
58- return Metric{rate, name + " Rate" };
56+ mStorage .erase (key);
57+ mStorage .insert (std::make_pair (key, metric));
58+ return Metric{rate, metric.getName () + " Rate" }.addTags (std::move (tags));
5959}
6060
6161Metric DerivedMetrics::increment (Metric& metric) {
62- std::string name = metric.getName ();
63- auto search = mStorage .find (name);
62+ auto tags = metric.getTags ();
63+ std::string key = metric.getName () + std::string (tags.begin (), tags.end ());
64+ auto search = mStorage .find (key);
6465 if (search != mStorage .end ()) {
6566 auto currentValue = metric.getValue ();
6667 auto storedValue = search->second .getValue ();
6768 auto value = boost::apply_visitor (VariantVisitorAdd (), currentValue, storedValue);
6869 mStorage .erase (search);
69- Metric result = Metric{value, name} ;
70- mStorage .insert (std::make_pair (name , result));
70+ Metric result = Metric{value, metric. getName ()}. addTags ( std::move (tags)) ;
71+ mStorage .insert (std::make_pair (key , result));
7172 return result;
7273 }
73- mStorage .insert (std::make_pair (name , metric));
74+ mStorage .insert (std::make_pair (key , metric));
7475 return metric;
7576}
7677
0 commit comments