Monitoring  3.3.4
O2 Monitoring library
Monitoring.h
Go to the documentation of this file.
1 // Copyright CERN and copyright holders of ALICE O2. This software is
2 // distributed under the terms of the GNU General Public License v3 (GPL
3 // Version 3), copied verbatim in the file "COPYING".
4 //
5 // See http://alice-o2.web.cern.ch/license for full licensing information.
6 //
7 // In applying this license CERN does not waive the privileges and immunities
8 // granted to it by virtue of its status as an Intergovernmental Organization
9 // or submit itself to any jurisdiction.
10 
15 
16 #ifndef ALICEO2_MONITORING_MONITORING_H
17 #define ALICEO2_MONITORING_MONITORING_H
18 
19 #include <atomic>
20 #include <chrono>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <thread>
25 #include <tuple>
26 #include <unordered_map>
27 #include <vector>
28 #include <deque>
29 
30 #include "Monitoring/Backend.h"
33 
34 namespace o2
35 {
37 namespace monitoring
38 {
39 
47 {
48  public:
50  Monitoring& operator=(const Monitoring&) = delete;
51 
53  Monitoring(const Monitoring&) = delete;
54 
56  Monitoring();
57 
59  void addBackend(std::unique_ptr<Backend> backend);
60 
62  ~Monitoring();
63 
68  void send(Metric&& metric, DerivedMetricMode mode = DerivedMetricMode::NONE);
69 
72  void enableProcessMonitoring(const unsigned int interval = 5);
73 
75  void flushBuffer();
76 
79  void enableBuffering(const std::size_t size = 128);
80 
84  void addGlobalTag(std::string_view name, std::string_view value);
85 
89  void addGlobalTag(tags::Key key, tags::Value value);
90 
94  //ComplexMetric& getAutoPushMetric(std::string name, unsigned int interval = 1);
95 
96  private:
99  void transmit(std::vector<Metric>&& metrics);
100 
102  void flushBuffer(short index);
103 
105  bool matchVerbosity(Verbosity backend, Verbosity metric);
106 
109  std::unique_ptr<DerivedMetrics> mDerivedHandler;
110 
112  std::vector<std::unique_ptr<Backend>> mBackends;
113 
115  void transmit(Metric&& metric);
116 
118  std::atomic<bool> mMonitorRunning;
119 
121  std::thread mMonitorThread;
122 
124  std::unique_ptr<ProcessMonitor> mProcessMonitor;
125 
127  void pushLoop();
128 
130  std::unordered_map<std::underlying_type<Verbosity>::type, std::vector<Metric>> mStorage;
131 
133  bool mBuffering;
134 
136  std::size_t mBufferSize;
137 
139  //std::deque<ComplexMetric> mPushStore;
140 
142  std::atomic<unsigned int> mProcessMonitoringInterval;
143 
145  //std::atomic<unsigned int> mAutoPushInterval;
146 };
147 
148 } // namespace monitoring
149 } // namespace o2
150 
151 #endif // ALICEO2_MONITORING_MONITORING_H
void addBackend(std::unique_ptr< Backend > backend)
Creates and appends backend to the backend list.
Definition: Monitoring.cxx:113
Definition: Backend.h:23
void enableBuffering(const std::size_t size=128)
Definition: Monitoring.cxx:46
Verbosity
Metric and Backedn verbosity.
Definition: Metric.h:24
DerivedMetricMode
Available derived metric modes.
Definition: DerivedMetrics.h:33
void enableProcessMonitoring(const unsigned int interval=5)
Definition: Monitoring.cxx:82
~Monitoring()
Joins process monitor thread if possible.
Definition: Monitoring.cxx:120
Main class that collects metrics from user and dispatches them to selected monitoring backends...
Definition: Monitoring.h:46
void flushBuffer()
Flushes metric buffer (this can also happen when buffer is full)
Definition: Monitoring.cxx:56
Represents a metric including value, type of the value, name, timestamp and tags. ...
Definition: Metric.h:37
void addGlobalTag(std::string_view name, std::string_view value)
Definition: Monitoring.cxx:97
Monitoring & operator=(const Monitoring &)=delete
Disable copy constructor.
Monitoring()
Instantiates derived metrics processor (see DerivedMetrics) and process monitor (seeProcessMonitor).
Definition: Monitoring.cxx:36
void send(Metric &&metric, DerivedMetricMode mode=DerivedMetricMode::NONE)
Definition: Monitoring.cxx:169