7 #include "artdaq-utilities/Plugins/MetricMacros.hh"
8 #include "fhiclcpp/ParameterSet.h"
10 #include <sys/types.h>
26 std::chrono::steady_clock::time_point last_report_time_;
28 std::map<std::string, std::string> metrics_;
30 std::mutex report_mutex_;
44 , last_report_time_(std::chrono::steady_clock::now())
62 std::string
getLibName()
const override {
return "report"; }
70 void sendMetric_(
const std::string& name,
const std::string& value,
const std::string& unit)
override
74 metrics_[name] = value +
" " + unit;
75 writeReportMessage_(
false);
85 void sendMetric_(
const std::string& name,
const int& value,
const std::string& unit)
override
96 void sendMetric_(
const std::string& name,
const double& value,
const std::string& unit)
override
107 void sendMetric_(
const std::string& name,
const float& value,
const std::string& unit)
override
118 void sendMetric_(
const std::string& name,
const unsigned long int& value,
const std::string& unit)
override
135 writeReportMessage_(
true);
140 void writeReportMessage_(
bool force)
142 std::unique_lock<std::mutex> lk(report_mutex_);
143 if (force || std::chrono::duration_cast<std::chrono::duration<
double, std::ratio<1>>>(std::chrono::steady_clock::now() - last_report_time_).count() >=
accumulationTime_)
145 if (metrics_.size() == 0)
return;
146 last_report_time_ = std::chrono::steady_clock::now();
147 std::ostringstream str;
150 int live_metrics = 0;
151 for (
auto& metric : metrics_)
153 if (count != 0) str <<
"," << std::endl;
154 str <<
"\t" << metric.first <<
": " << metric.second;
155 if (metric.second !=
"NOT REPORTED") live_metrics++;
156 metric.second =
"NOT REPORTED";
159 if (live_metrics > 0)
160 TLOG_INFO(
app_name_) <<
"Periodic report: " << live_metrics <<
" active metrics:" << std::endl
163 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.
The MetricPlugin class defines the interface that MetricManager uses to send metric data to the vario...
void startMetrics()
Perform startup actions. Simply calls the virtual startMetrics_ function.
virtual ~PeriodicReportMetric()
PeriodicReportMetric Destructor. Calls stopMetrics and then closes the file.
PeriodicReportMetric(fhicl::ParameterSet const &config, std::string const &app_name)
PeriodicReportMetric Constructor.
void stopMetrics()
Perform shutdown actions. Zeroes out all accumulators, and sends zeros for each metric. Calls stopMetrics_() for any plugin-defined shutdown actions.
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.
double accumulationTime_
The amount of time to average metric values; except for accumulate=false metrics, will be the interva...
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_
Flag to indicate that the MetricPlugin is being stopped, and any metric back-ends which do not have a...