Skip to content

Commit

Permalink
ApMon: send multiple timed parameters (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Aug 25, 2017
1 parent f974016 commit 3eaadf9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/8-Multiple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ int main(int argc, char *argv[]) {
// configure monitoring (once per process), pass configuration path as parameter
Monitoring::Configure("file://" + GetConfigFromCmdLine(argc, argv));

Monitoring::Get().send("measurementName", {{10, "myMetricInt"}, {10.10, "myMetricFloat"}});
Monitoring::Get().send("measurementName", {{20, "myMetricIntMultiple"}, {20.30, "myMetricFloatMultple"}});
}
54 changes: 46 additions & 8 deletions src/Backends/ApMonBackend.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ ApMonBackend::ApMonBackend(const std::string& configurationFile)

inline int ApMonBackend::convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp)
{
return std::chrono::duration_cast <std::chrono::milliseconds>(
timestamp.time_since_epoch()
).count();
return static_cast<int>(std::chrono::system_clock::to_time_t(timestamp));
}

void ApMonBackend::addGlobalTag(std::string name, std::string value)
Expand All @@ -44,12 +42,52 @@ void ApMonBackend::addGlobalTag(std::string name, std::string value)

void ApMonBackend::sendMultiple(std::string measurement, std::vector<Metric>&& metrics)
{
for (auto& m : metrics) {
std::string tempName = m.getName();
m.setName(measurement + "-" + m.getName());
send(m);
m.setName(tempName);
int noMetrics = metrics.size();
char **paramNames, **paramValues;
int *valueTypes;
paramNames = (char **)std::malloc(noMetrics * sizeof(char *));
paramValues = (char **)std::malloc(noMetrics * sizeof(char *));
valueTypes = (int *)std::malloc(noMetrics * sizeof(int));
// the scope of values must be the same as sendTimedParameters method
int intValue;
double doubleValue;
std::string stringValue;

for (int i = 0; i < noMetrics; i++) {
paramNames[i] = const_cast<char*>(metrics[i].getName().c_str());
switch(metrics[i].getType()) {
case MetricType::INT :
{
valueTypes[i] = XDR_INT32;
intValue = boost::get<int>(metrics[i].getValue());
paramValues[i] = reinterpret_cast<char*>(&intValue);
}
break;

case MetricType::STRING :
{
valueTypes[i] = XDR_STRING;
stringValue = boost::get<std::string>(metrics[i].getValue());
paramValues[i] = const_cast<char*>(stringValue.c_str());
}
break;

case MetricType::DOUBLE :
{
valueTypes[i] = XDR_REAL64;
doubleValue = boost::get<double>(metrics[i].getValue());
paramValues[i] = reinterpret_cast<char*>(&doubleValue);
}
break;
}
}

mApMon->sendTimedParameters(const_cast<char*>(entity.c_str()), const_cast<char*>(entity.c_str()),
noMetrics, paramNames, valueTypes, paramValues, convertTimestamp(metrics[0].getTimestamp()));

std::free(paramNames);
std::free(paramValues);
std::free(valueTypes);
}

void ApMonBackend::send(const Metric& metric)
Expand Down
1 change: 0 additions & 1 deletion src/Backends/ApMonBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ApMonBackend final : public Backend
void send(const Metric& metric) override;

/// Sends multiple metric in single packet
/// Not supported by the backend therefore it falls back to sending metric one by one
/// \param name measurement name
/// \param metrics list of metrics
void sendMultiple(std::string measurement, std::vector<Metric>&& metrics) override;
Expand Down

0 comments on commit 3eaadf9

Please sign in to comment.