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
12#include "logging/Logging.hpp"
13
14using namespace dunedaq::opmonlib;
15
17 std::string name,
18 facility_ptr_t f_ptr)
19 : MonitorableObject( name, session) {
20
21 m_facility.store(f_ptr);
22
23}
24
26
27 if ( ! m_cfg )
29
30 TLOG() << "Starting a new monitoring thread with interval " << m_cfg.load()->get_interval().count() << " seconds, at level " << get_opmon_level();
31
32 auto running_function = std::bind( & OpMonManager::run, this, std::placeholders::_1);
33 m_thread = std::jthread( running_function );
34 auto handle = m_thread.native_handle();
35 auto thread_name = "opmon";
36 auto rc = pthread_setname_np(handle, thread_name);
37 if (rc != 0) {
38 ers::warning(ThreadNameTooLong(ERS_HERE, thread_name));
39 }
40}
41
42
44
45 TLOG() << "Gracefully requesting the monitoring thread to stop";
46
47 m_thread.request_stop();
48 m_thread.join();
49}
50
51void OpMonManager::run(std::stop_token stoken ) {
52
53 TLOG() << "Monitoring thread started";
54
55 auto sleep_interval = std::chrono::milliseconds(100);
56 auto reporting_interval = m_cfg.load()->get_interval();
57 auto last_collection_time = std::chrono::steady_clock::now();
58
59 while( ! stoken.stop_requested() ) {
60
61 std::this_thread::sleep_for(sleep_interval);
62 auto time_span = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::steady_clock::now() - last_collection_time);
63
64 if ( time_span < reporting_interval ) continue;
65
66 if ( stoken.stop_requested() ) break;
67
68 last_collection_time = std::chrono::steady_clock::now();
69 publish( collect() );
70 // there is no catch here because collect is supposed to catch all possible exceptions
71 // In this way we should garantee the collection of metrics on the system
72
73 }
74
75 TLOG() << "Exiting the monitoring thread";
76}
77
78
#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:22
Monitoring thread not ERS_EMPTY MissingConfiguration
void warning(const Issue &issue)
Definition ers.hpp:126