DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OpMonManager.cpp
Go to the documentation of this file.
1
8
9#include <chrono>
10
11#include "logging/Logging.hpp"
13
14using namespace dunedaq::opmonlib;
15
16OpMonManager::OpMonManager(std::string session, std::string name, facility_ptr_t f_ptr)
18{
19
20 m_facility.store(f_ptr);
21}
22
23void
25{
26
27 if (!m_cfg)
28 throw MissingConfiguration(ERS_HERE);
29
30 TLOG() << "Starting a new monitoring thread with interval " << m_cfg.load()->get_interval().count()
31 << " seconds, at level " << get_opmon_level();
32
33 auto running_function = std::bind(&OpMonManager::run, this, std::placeholders::_1);
34 m_thread = std::jthread(running_function);
35 auto handle = m_thread.native_handle();
36 auto thread_name = "opmon";
37 auto rc = pthread_setname_np(handle, thread_name);
38 if (rc != 0) {
39 ers::warning(ThreadNameTooLong(ERS_HERE, thread_name));
40 }
41}
42
43void
45{
46
47 TLOG() << "Gracefully requesting the monitoring thread to stop";
48
49 m_thread.request_stop();
50 m_thread.join();
51}
52
53void
54OpMonManager::run(std::stop_token stoken)
55{
56
57 TLOG() << "Monitoring thread started";
58
59 auto sleep_interval = std::chrono::milliseconds(100);
60 auto reporting_interval = m_cfg.load()->get_interval();
61 auto last_collection_time = std::chrono::steady_clock::now();
62
63 while (!stoken.stop_requested()) {
64
65 std::this_thread::sleep_for(sleep_interval);
66 auto time_span =
67 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - last_collection_time);
68
69 if (time_span < reporting_interval)
70 continue;
71
72 if (stoken.stop_requested())
73 break;
74
75 last_collection_time = std::chrono::steady_clock::now();
77 // there is no catch here because collect is supposed to catch all possible exceptions
78 // In this way we should garantee the collection of metrics on the system
79 }
80
81 TLOG() << "Exiting the monitoring thread";
82}
#define ERS_HERE
std::shared_ptr< opmonlib::OpMonFacility > facility_ptr_t
opmon::MonitoringTreeInfo collect() noexcept
std::atomic< facility_ptr_t > m_facility
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
MonitorableObject(const MonitorableObject &)=delete
std::atomic< const confmodel::OpMonConf * > m_cfg
auto get_opmon_level() const noexcept
OpMonManager(std::string session, std::string name, std::string opmon_facility_uri="stdout")
#define TLOG(...)
Definition macro.hpp:21
void warning(const Issue &issue)
Definition ers.hpp:150