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 "
logging/Logging.hpp
"
12
#include <
opmonlib/OpMonManager.hpp
>
13
14
using namespace
dunedaq::opmonlib
;
15
16
OpMonManager::OpMonManager
(std::string
session
, std::string name,
facility_ptr_t
f_ptr)
17
:
MonitorableObject
(name,
session
)
18
{
19
20
m_facility
.store(f_ptr);
21
}
22
23
void
24
OpMonManager::start_monitoring
()
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
43
void
44
OpMonManager::stop_monitoring
()
45
{
46
47
TLOG
() <<
"Gracefully requesting the monitoring thread to stop"
;
48
49
m_thread
.request_stop();
50
m_thread
.join();
51
}
52
53
void
54
OpMonManager::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();
76
publish
(
collect
());
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
}
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
OpMonManager.hpp
dunedaq::opmonlib::MonitorableObject::facility_ptr_t
std::shared_ptr< opmonlib::OpMonFacility > facility_ptr_t
Definition
MonitorableObject.hpp:162
dunedaq::opmonlib::MonitorableObject::collect
opmon::MonitoringTreeInfo collect() noexcept
Definition
MonitorableObject.cpp:100
dunedaq::opmonlib::MonitorableObject::m_facility
std::atomic< facility_ptr_t > m_facility
Definition
MonitorableObject.hpp:163
dunedaq::opmonlib::MonitorableObject::publish
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
Definition
MonitorableObject.cpp:59
dunedaq::opmonlib::MonitorableObject::MonitorableObject
MonitorableObject(const MonitorableObject &)=delete
dunedaq::opmonlib::OpMonManager::m_cfg
std::atomic< const confmodel::OpMonConf * > m_cfg
Definition
OpMonManager.hpp:87
dunedaq::opmonlib::OpMonManager::get_opmon_level
auto get_opmon_level() const noexcept
Definition
MonitorableObject.hpp:91
dunedaq::opmonlib::OpMonManager::run
void run(std::stop_token)
Definition
OpMonManager.cpp:54
dunedaq::opmonlib::OpMonManager::OpMonManager
OpMonManager(std::string session, std::string name, std::string opmon_facility_uri="stdout")
Definition
OpMonManager.hpp:47
dunedaq::opmonlib::OpMonManager::start_monitoring
void start_monitoring()
Definition
OpMonManager.cpp:24
dunedaq::opmonlib::OpMonManager::stop_monitoring
void stop_monitoring()
Definition
OpMonManager.cpp:44
dunedaq::opmonlib::OpMonManager::m_thread
std::jthread m_thread
Definition
OpMonManager.hpp:86
Logging.hpp
TLOG
#define TLOG(...)
Definition
macro.hpp:21
dunedaq::opmonlib
Definition
BackendOpMonFacility.hpp:11
ers::warning
void warning(const Issue &issue)
Definition
ers.hpp:150
session
Definition
session.py:1
Generated on
for DUNE-DAQ by
1.18.0