@@ -31,12 +31,12 @@ std::string Flume::metricToJson(const Metric& metric)
3131 boost::property_tree::ptree header = globalHeader;
3232 header.put <std::string>(" timestamp" , std::to_string (convertTimestamp (metric.getTimestamp ())));
3333 header.put <std::string>(" name" , metric.getName ());
34- header.put <std::string>(" value " , boost::lexical_cast<std::string>(metric.getValue ()));
34+ header.put <std::string>(" value_value " , boost::lexical_cast<std::string>(metric.getValue ()));
3535 for (const auto & tag : metric.getTags ()) {
36- header.put <std::string>(tag.name , tag.value );
36+ header.put <std::string>(" tag_ " + tag.name , tag.value );
3737 }
3838 event.push_back (std::make_pair (" headers" , header));
39- event.put <std::string>(" body" , boost::lexical_cast<std::string>(metric. getValue ()) );
39+ event.put <std::string>(" body" , " " );
4040 std::stringstream ss;
4141 write_json (ss, event);
4242 std::string s = ss.str ();
@@ -45,14 +45,41 @@ std::string Flume::metricToJson(const Metric& metric)
4545 return s;
4646}
4747
48+ void Flume::send (std::vector<Metric>&& metrics)
49+ {
50+ std::string flumeMetrics = " " ;
51+ for (auto & metric : metrics) {
52+ flumeMetrics += metricToJson (metric);
53+ flumeMetrics += " \n " ;
54+ }
55+ mTransport ->send (std::move (flumeMetrics));
56+ }
57+
4858void Flume::sendMultiple (std::string measurement, std::vector<Metric>&& metrics)
4959{
50- for (auto & m : metrics) {
51- std::string tempName = m.getName ();
52- m.setName (measurement + " -" + m.getName ());
53- send (m);
54- m.setName (tempName);
60+ mTransport ->send (metricsToJson (measurement, std::move (metrics)));
61+ }
62+
63+ std::string Flume::metricsToJson (std::string measurement, std::vector<Metric>&& metrics)
64+ {
65+ boost::property_tree::ptree event;
66+ boost::property_tree::ptree header = globalHeader;
67+ header.put <std::string>(" timestamp" , std::to_string (convertTimestamp (metrics.front ().getTimestamp ())));
68+ header.put <std::string>(" name" , measurement);
69+ for (const auto & tag : metrics.front ().getTags ()) {
70+ header.put <std::string>(" tag_" + tag.name , tag.value );
71+ }
72+ for (auto & metric : metrics) {
73+ header.put <std::string>(" value_" + metric.getName (), boost::lexical_cast<std::string>(metric.getValue ()));
5574 }
75+ event.push_back (std::make_pair (" headers" , header));
76+ event.put <std::string>(" body" , " " );
77+ std::stringstream ss;
78+ write_json (ss, event);
79+ std::string s = ss.str ();
80+ s.erase (std::remove_if ( s.begin (), s.end (),
81+ [](char c){ return (c ==' \r ' || c ==' \t ' || c == ' ' || c == ' \n ' );}), s.end () );
82+ return s;
5683}
5784
5885void Flume::send (const Metric& metric)
0 commit comments