@@ -31,9 +31,7 @@ ApMonBackend::ApMonBackend(const std::string& configurationFile)
3131
3232inline int ApMonBackend::convertTimestamp (const std::chrono::time_point<std::chrono::system_clock>& timestamp)
3333{
34- return std::chrono::duration_cast <std::chrono::milliseconds>(
35- timestamp.time_since_epoch ()
36- ).count ();
34+ return static_cast <int >(std::chrono::system_clock::to_time_t (timestamp));
3735}
3836
3937void ApMonBackend::addGlobalTag (std::string name, std::string value)
@@ -44,12 +42,52 @@ void ApMonBackend::addGlobalTag(std::string name, std::string value)
4442
4543void ApMonBackend::sendMultiple (std::string measurement, std::vector<Metric>&& metrics)
4644{
47- for (auto & m : metrics) {
48- std::string tempName = m.getName ();
49- m.setName (measurement + " -" + m.getName ());
50- send (m);
51- m.setName (tempName);
45+ int noMetrics = metrics.size ();
46+ char **paramNames, **paramValues;
47+ int *valueTypes;
48+ paramNames = (char **)std::malloc (noMetrics * sizeof (char *));
49+ paramValues = (char **)std::malloc (noMetrics * sizeof (char *));
50+ valueTypes = (int *)std::malloc (noMetrics * sizeof (int ));
51+ // the scope of values must be the same as sendTimedParameters method
52+ int intValue;
53+ double doubleValue;
54+ std::string stringValue;
55+
56+ for (int i = 0 ; i < noMetrics; i++) {
57+ paramNames[i] = const_cast <char *>(metrics[i].getName ().c_str ());
58+ switch (metrics[i].getType ()) {
59+ case MetricType::INT :
60+ {
61+ valueTypes[i] = XDR_INT32;
62+ intValue = boost::get<int >(metrics[i].getValue ());
63+ paramValues[i] = reinterpret_cast <char *>(&intValue);
64+ }
65+ break ;
66+
67+ case MetricType::STRING :
68+ {
69+ valueTypes[i] = XDR_STRING;
70+ stringValue = boost::get<std::string>(metrics[i].getValue ());
71+ paramValues[i] = const_cast <char *>(stringValue.c_str ());
72+ }
73+ break ;
74+
75+ case MetricType::DOUBLE :
76+ {
77+ valueTypes[i] = XDR_REAL64;
78+ doubleValue = boost::get<double >(metrics[i].getValue ());
79+ paramValues[i] = reinterpret_cast <char *>(&doubleValue);
80+ }
81+ break ;
82+ }
5283 }
84+
85+ mApMon ->sendTimedParameters (const_cast <char *>(entity.c_str ()), const_cast <char *>(entity.c_str ()),
86+ noMetrics, paramNames, valueTypes, paramValues, convertTimestamp (metrics[0 ].getTimestamp ()));
87+
88+ std::free (paramNames);
89+ std::free (paramValues);
90+ std::free (valueTypes);
5391}
5492
5593void ApMonBackend::send (const Metric& metric)
0 commit comments