7 #include "artdaq-utilities/Plugins/MetricMacros.hh"
8 #include "fhiclcpp/ParameterSet.h"
15 #include <sys/types.h>
27 std::chrono::steady_clock::time_point last_report_time_;
29 std::map<std::string, std::string> metrics_;
31 std::mutex report_mutex_;
43 , last_report_time_(std::chrono::steady_clock::now())
61 std::string
getLibName()
const override {
return "report"; }
69 void sendMetric_(
const std::string& name,
const std::string& value,
const std::string& unit)
override
73 metrics_[name] = value +
" " + unit;
74 writeReportMessage_(
false);
84 void sendMetric_(
const std::string& name,
const int& value,
const std::string& unit)
override
95 void sendMetric_(
const std::string& name,
const double& value,
const std::string& unit)
override
106 void sendMetric_(
const std::string& name,
const float& value,
const std::string& unit)
override
117 void sendMetric_(
const std::string& name,
const unsigned long int& value,
const std::string& unit)
override
134 writeReportMessage_(
true);
139 void writeReportMessage_(
bool force)
141 std::unique_lock<std::mutex> lk(report_mutex_);
142 if(force || std::chrono::duration_cast<std::chrono::duration<
double, std::ratio<1>>>(std::chrono::steady_clock::now() - last_report_time_).count() >=
accumulationTime_)
144 if(metrics_.size() == 0)
return;
145 last_report_time_ = std::chrono::steady_clock::now();
146 std::ostringstream str;
149 int live_metrics = 0;
150 for(
auto& metric : metrics_)
152 if(count != 0) str <<
"," << std::endl;
153 str <<
"\t" << metric.first <<
": " << metric.second;
154 if(metric.second !=
"NOT REPORTED") live_metrics++;
155 metric.second =
"NOT REPORTED";
158 if(live_metrics > 0) TLOG_INFO(
app_name_) <<
"Periodic report: " << live_metrics <<
" active metrics:" << std::endl << str.str();
159 else TLOG_INFO(
app_name_) <<
"Periodic report: No active metrics in last reporting interval!";
void sendMetric_(const std::string &name, const double &value, const std::string &unit) override
Write metric data to a file.
virtual ~PeriodicReportMetric()
PeriodicReportMetric Destructor. Calls stopMetrics and then closes the file.
PeriodicReportMetric(fhicl::ParameterSet const &config, std::string const &app_name)
PeriodicReportMetric Constructor.
std::string app_name_
Name of the application which is sending metrics to this plugin.
std::string getLibName() const override
Get the library name for the PeriodicReport metric.
void sendMetric_(const std::string &name, const int &value, const std::string &unit) override
Write metric data to a file.
void sendMetric_(const std::string &name, const float &value, const std::string &unit) override
Write metric data to a file.
PeriodicReportMetric writes metric data to a file on disk.
void startMetrics_() override
Perform startup actions.
void stopMetrics_() override
Perform shutdown actions.
void sendMetric_(const std::string &name, const unsigned long int &value, const std::string &unit) override
Write metric data to a file.
void sendMetric_(const std::string &name, const std::string &value, const std::string &unit) override
Write metric data to a file.
bool inhibit_
Whether to inhibit all metric sending.