DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OpMonManager.cpp
Go to the documentation of this file.
1
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
42void OpMonManager::run(std::stop_token stoken ) {
43
44 auto sleep_interval = std::chrono::milliseconds(100);
45 auto reporting_interval = m_cfg.load()->get_interval();
46 auto last_collection_time = std::chrono::steady_clock::now();
47
48 while( ! stoken.stop_requested() ) {
49
50 std::this_thread::sleep_for(sleep_interval);
51 auto time_span = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::steady_clock::now() - last_collection_time);
52
53 if ( time_span >= reporting_interval ) {
54 last_collection_time = std::chrono::steady_clock::now();
55 publish( collect() );
56 // there is no catch here because collect is supposed to catch all possible exceptions
57 // In this way we should garantee the collection of metrics on the system
58 }
59 }
60
61 TLOG() << "Exiting the monitoring thread";
62}
63
64
#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
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:115