DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
opmonlib
src
OpMonManager.cpp
Go to the documentation of this file.
1
8
9
#include <chrono>
10
11
#include <
opmonlib/OpMonManager.hpp
>
12
#include "
logging/Logging.hpp
"
13
14
using namespace
dunedaq::opmonlib
;
15
16
OpMonManager::OpMonManager
( std::string
session
,
17
std::string name,
18
facility_ptr_t
f_ptr)
19
:
MonitorableObject
( name,
session
) {
20
21
m_facility
.store(f_ptr);
22
23
}
24
25
void
OpMonManager::start_monitoring
() {
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() <<
" 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
43
void
OpMonManager::stop_monitoring
() {
44
45
TLOG
() <<
"Gracefully requesting the monitoring thread to stop"
;
46
47
m_thread
.request_stop();
48
m_thread
.join();
49
}
50
51
void
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
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
OpMonManager.hpp
dunedaq::opmonlib::MonitorableObject::facility_ptr_t
std::shared_ptr< opmonlib::OpMonFacility > facility_ptr_t
Definition
MonitorableObject.hpp:170
dunedaq::opmonlib::MonitorableObject::collect
opmon::MonitoringTreeInfo collect() noexcept
Definition
MonitorableObject.cpp:101
dunedaq::opmonlib::MonitorableObject::m_facility
std::atomic< facility_ptr_t > m_facility
Definition
MonitorableObject.hpp:171
dunedaq::opmonlib::MonitorableObject::publish
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
Definition
MonitorableObject.cpp:58
dunedaq::opmonlib::MonitorableObject::MonitorableObject
MonitorableObject(const MonitorableObject &)=delete
dunedaq::opmonlib::OpMonManager::m_cfg
std::atomic< const confmodel::OpMonConf * > m_cfg
Definition
OpMonManager.hpp:101
dunedaq::opmonlib::OpMonManager::get_opmon_level
auto get_opmon_level() const noexcept
Definition
MonitorableObject.hpp:95
dunedaq::opmonlib::OpMonManager::run
void run(std::stop_token)
Definition
OpMonManager.cpp:51
dunedaq::opmonlib::OpMonManager::OpMonManager
OpMonManager(std::string session, std::string name, std::string opmon_facility_uri="stdout")
Definition
OpMonManager.hpp:60
dunedaq::opmonlib::OpMonManager::start_monitoring
void start_monitoring()
Definition
OpMonManager.cpp:25
dunedaq::opmonlib::OpMonManager::stop_monitoring
void stop_monitoring()
Definition
OpMonManager.cpp:43
dunedaq::opmonlib::OpMonManager::m_thread
std::jthread m_thread
Definition
OpMonManager.hpp:100
Logging.hpp
TLOG
#define TLOG(...)
Definition
macro.hpp:22
dunedaq::opmonlib
Definition
BackendOpMonFacility.hpp:11
dunedaq::MissingConfiguration
Monitoring thread not ERS_EMPTY MissingConfiguration
Definition
OpMonManager.hpp:40
ers::warning
void warning(const Issue &issue)
Definition
ers.hpp:126
session
Definition
session.py:1
Generated on
for DUNE-DAQ by
1.17.0