Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions src/sendMetric.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,37 @@ void print_usage()
printf("\nExample: o2-monitoring-send -u influxdb-stdout:// -m test.metric -i 12345\n");
}


int main(int argc, char** argv)
{

bool verbose = 0; // if set, prints detailed messages
bool verbose = false; // if set, prints detailed messages

std::unique_ptr<Monitoring> monitoringCollector;
char option;
int option;

bool isOk = 1;
const char *monitoringURI = nullptr;
const char *monitoringValue = nullptr;
const char *monitoringMetric = nullptr;
bool isOk = true;
const char* monitoringURI = nullptr;
const char* monitoringValue = nullptr;
const char* monitoringMetric = nullptr;

// read options
while ((option = getopt(argc, argv, "hvu:i:m:")) != -1) {
switch (option) {

case 'u': {
monitoringURI = optarg;
} break;

case 'i': {
monitoringValue = optarg;
} break;

case 'm': {
monitoringMetric = optarg;
} break;

case 'v': {
verbose = 1;
verbose = true;
} break;

case 'h':
Expand All @@ -76,19 +75,19 @@ int main(int argc, char** argv)

if (monitoringURI == nullptr) {
printf("Unspecified monitoring URI.\n");
isOk = 0;
isOk = false;
}

if (monitoringMetric == nullptr) {
printf("Unspecified monitoring metric.\n");
isOk = 0;
isOk = false;
}

if (monitoringValue == nullptr) {
printf("Unspecified monitoring value.\n");
isOk = 0;
isOk = false;
}

if (!isOk) {
printf("Failed to send metric: bad parameters.\n\n\n");
print_usage();
Expand All @@ -98,7 +97,7 @@ int main(int argc, char** argv)
// conversions
int monitoringValueI = atoi(monitoringValue);

// disable logs from monitoring lib
// disable logs from monitoring lib
setenv("O2_INFOLOGGER_MODE", "none", 1);

if (verbose) {
Expand All @@ -109,19 +108,17 @@ int main(int argc, char** argv)
printf("\n");
}

isOk = 0;
isOk = false;
try {
monitoringCollector = MonitoringFactory::Get(monitoringURI);
monitoringCollector->send({ monitoringValueI, monitoringMetric });
isOk = 1;
}
catch (const std::exception &exc) {
monitoringCollector->send({monitoringValueI, monitoringMetric});
isOk = true;
} catch (const std::exception& exc) {
printf("Exception: %s\n", exc.what());
}
catch (...) {
} catch (...) {
printf("Undefined exception\n");
}

if (!isOk) {
printf("Failed to send metric\n");
return -1;
Expand All @@ -132,4 +129,3 @@ int main(int argc, char** argv)
}
return 0;
}

Loading