-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathMonitorClient.cpp
More file actions
127 lines (104 loc) · 4 KB
/
Copy pathMonitorClient.cpp
File metadata and controls
127 lines (104 loc) · 4 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* MonitorClient.cpp
*
* Copyright (C) 2021 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#include <boost/asio/io_service.hpp>
#include <monitor/MonitorClient.hpp>
#include <shared_core/ILogDestination.hpp>
#include "MonitorClientImpl.hpp"
namespace rstudio {
namespace monitor {
namespace {
class MonitorLogDestination : public core::log::ILogDestination
{
public:
MonitorLogDestination(core::log::LogLevel logLevel, const std::string& programIdentity) :
ILogDestination(logLevel),
programIdentity_(programIdentity)
{
}
unsigned int getId() const override
{
// Return a unique ID that's not likely to be used by other log destination types (stderr and syslog are 0 & 1,
// and file log destinations in the server start at 3.
return 56;
}
void reload() override
{
// Nothing to do.
}
void writeLog(core::log::LogLevel logLevel, const std::string& message) override
{
// Don't log messages which are more detailed than the configured maximum.
if (logLevel > m_logLevel)
return;
client().logMessage(programIdentity_, logLevel, message);
}
private:
std::string programIdentity_;
};
// single global instance of the monitor client (allocate it on the heap
// and never free it so that there are no order of destruction surprises)
Client* s_pClient = NULL;
} // anonymous namespace
std::shared_ptr<core::log::ILogDestination> Client::createLogDestination(
core::log::LogLevel logLevel,
const std::string& programIdentity)
{
return std::shared_ptr<core::log::ILogDestination>(new MonitorLogDestination(logLevel, programIdentity));
}
void initializeMonitorClient(const std::string& metricsSocket,
const std::string& auth,
bool useSharedSecret)
{
BOOST_ASSERT(s_pClient == NULL);
s_pClient = new SyncClient(metricsSocket, auth, useSharedSecret);
}
void initializeMonitorClient(const std::string& metricsSocket,
const std::string& auth,
boost::asio::io_service& ioService,
bool useSharedSecret)
{
BOOST_ASSERT(s_pClient == NULL);
s_pClient = new AsyncClient(metricsSocket, auth, ioService, useSharedSecret);
}
void initializeMonitorClient(const std::string& tcpAddress,
const std::string& tcpPort,
bool useSsl,
bool verifySslCerts,
const std::string& prefixUri,
const std::string& auth,
bool useSharedSecret)
{
BOOST_ASSERT(s_pClient == NULL);
s_pClient = new SyncClient(tcpAddress, tcpPort, useSsl, verifySslCerts, prefixUri, auth, useSharedSecret);
}
void initializeMonitorClient(const std::string& tcpAddress,
const std::string& tcpPort,
bool useSsl,
bool verifySslCerts,
const std::string& prefixUri,
const std::string& auth,
boost::asio::io_service& ioService,
bool useSharedSecret)
{
BOOST_ASSERT(s_pClient == NULL);
s_pClient = new AsyncClient(tcpAddress, tcpPort, useSsl, verifySslCerts, prefixUri, auth, ioService, useSharedSecret);
}
Client& client()
{
BOOST_ASSERT(s_pClient != NULL);
return *s_pClient;
}
} // namespace monitor
} // namespace rstudio