-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathApMonBackend.h
More file actions
90 lines (75 loc) · 3.01 KB
/
ApMonBackend.h
File metadata and controls
90 lines (75 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file ApMonBackend.h
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
///
#ifndef ALICEO2_MONITORING_BACKENDS_APMONBACKEND_H
#define ALICEO2_MONITORING_BACKENDS_APMONBACKEND_H
#include "Monitoring/Backend.h"
#include <ApMon.h>
#include <string>
#include <chrono>
#include <memory>
#include <functional>
namespace o2
{
/// ALICE O2 Monitoring system
namespace monitoring
{
/// Monitoring backends
namespace backends
{
/// \brief Backend that uses AppMon (MonALISA)
///
/// Uses ApMonBackend library to push metric to MonALISA Service.
/// ApMonBackend accepts timestamps as integers, therefore a cast is needed.
///
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
class ApMonBackend final : public Backend
{
public:
/// Constructs AppMon backend
/// \param path filepath to ApMonBackend configuration file
ApMonBackend(const std::string& path);
/// Default destructor
~ApMonBackend() = default;
/// Sends multiple metrics not related to each other
/// \@param metrics vector of metrics
void send(std::vector<Metric>&& metrics) override;
/// Sends metric via MonALISA
/// ApMonBackend's intances is type-aware therefore cast of metric value is needed
/// \param metric reference to metric object:
void send(const Metric& metric) override;
/// Extends entity value
/// \param name tag name (unused)
/// \param value tag value that is concatenated to entity string
void addGlobalTag(std::string_view name, std::string_view value) override;
private:
/// Sends batch of metrics
/// \param metrics vector of metrics
void sendBatch(const std::vector<std::reference_wrapper<const Metric>>& metrics);
/// Converts timestamp to format supported by ApMonBackend
/// \param timestamp timestamp in std::chrono::time_point format
/// \return timestamp as integer (milliseconds from epoch)
int convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp);
/// Gets node name
/// It looks for environment variable ALIEN_PROC_ID and if it is not set, it uses hostname as node name
/// \return node name as string
std::string getNodeName();
std::unique_ptr<ApMon> mApMon; ///< ApMon object
std::string mEntity; ///< MonALISA entity, created out of global tags
inline static constexpr std::string_view mClusterName = "O2Monitoring_Nodes"; ///< MonALISA cluster name
};
} // namespace backends
} // namespace monitoring
} // namespace o2
#endif // ALICEO2_MONITORING_BACKENDS_APMONBACKEND_H