-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathhostname.cpp
162 lines (137 loc) · 5.33 KB
/
hostname.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "hostname.h"
#include "config.h"
#include <util/generic/string.h>
#include <util/string/builder.h>
#include <util/system/hostname.h>
namespace NCloud::NBlockStore {
namespace {
////////////////////////////////////////////////////////////////////////////////
ui32 GetServicePort(EHostService serviceType, const TDiagnosticsConfig& config)
{
switch (serviceType) {
case EHostService::Kikimr: return config.GetKikimrMonPort();
case EHostService::Nbs: return config.GetNbsMonPort();
default:
Y_ABORT("Wrong EHostService: %d", serviceType);
}
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
TString GetShortHostName(const TString& fullName)
{
auto pos = fullName.find('.', 0);
return pos != NPOS ? fullName.substr(0, pos) : fullName;
}
TString GetShortHostName()
{
return GetShortHostName(HostName());
}
TString GetExternalHostUrl(
const TString& hostName,
EHostService serviceType,
const TDiagnosticsConfig& config)
{
TStringBuilder out;
switch (config.GetHostNameScheme()) {
case NProto::HOSTNAME_BASTION:
out << "https://"
<< GetShortHostName(hostName)
<< '.'
<< config.GetBastionNameSuffix();
if (serviceType != EHostService::Kikimr) {
out << ':' << GetServicePort(serviceType, config);
}
break;
case NProto::HOSTNAME_YDBVIEWER:
out << "https://" << config.GetViewerHostName()
<< '/' << hostName
<< ':' << GetServicePort(serviceType, config);
break;
default:
out << "http://" << hostName
<< ':' << GetServicePort(serviceType, config);
break;
}
out << '/';
return out;
}
TString GetMonitoringVolumeUrl(
const TDiagnosticsConfig& config,
const TString& diskId)
{
TMonitoringUrlData data = config.GetMonitoringUrlData();
return TStringBuilder()
<< data.MonitoringUrl << "/projects/" << data.MonitoringProject
<< "/dashboards/" << data.MonitoringVolumeDashboard
<< "?from=now-1d&to=now&refresh=60000&p.cluster="
<< data.MonitoringClusterName << "&p.volume=" << diskId;
}
TString GetMonitoringPartitionUrl(const TDiagnosticsConfig& config)
{
TMonitoringUrlData data = config.GetMonitoringUrlData();
return TStringBuilder()
<< data.MonitoringUrl << "/projects/" << data.MonitoringProject
<< "/dashboards/" << data.MonitoringPartitionDashboard
<< "?from=now-1d&to=now&"
"refresh=60000&p.service=tablets&p.cluster="
<< data.MonitoringClusterName << "&p.host=" << GetShortHostName();
}
TString GetMonitoringNBSAlertsUrl(const TDiagnosticsConfig& config)
{
TMonitoringUrlData data = config.GetMonitoringUrlData();
return TStringBuilder()
<< data.MonitoringUrl << "/projects/" << data.MonitoringProject
<< "/dashboards/" << data.MonitoringNBSAlertsDashboard
<< "?from=now-1d&to=now&refresh=60000&p.cluster="
<< data.MonitoringClusterName << "&p.host=" << GetShortHostName();
}
TString GetMonitoringNBSOverviewToTVUrl(const TDiagnosticsConfig& config)
{
TMonitoringUrlData data = config.GetMonitoringUrlData();
return TStringBuilder()
<< data.MonitoringUrl << "/projects/" << data.MonitoringProject
<< "/dashboards/" << data.MonitoringNBSTVDashboard
<< "?from=now-1d&to=now&refresh=60000&p.cluster="
<< data.MonitoringClusterName << "&p.host=" << GetShortHostName();
}
TString GetMonitoringYDBGroupUrl(
const TDiagnosticsConfig& config,
ui32 groupId,
const TString& storagePool)
{
constexpr TStringBuf GetFast =
R"(q.0.s=histogram_percentile(100, {project="kikimr", cluster="*", storagePool="%s", group="%)" PRIu32
R"(", host="*", service="vdisks", subsystem="latency_histo", handleclass="GetFast"})&q.0.name=A)";
constexpr TStringBuf PutUserData =
R"(q.1.s=histogram_percentile(100, {project="kikimr", cluster="*", storagePool="%s", group="%)" PRIu32
R"(", host="*", service="vdisks", subsystem="latency_histo", handleclass="PutUserData"})&q.1.name=B)";
constexpr TStringBuf Url =
"%s/projects/%s/explorer/"
"queries?%s&%s&from=now-1d&to=now&refresh=60000";
return Sprintf(
Url.data(),
config.GetMonitoringUrlData().MonitoringUrl.c_str(),
config.GetMonitoringUrlData().MonitoringYDBProject.c_str(),
Sprintf(GetFast.data(), storagePool.c_str(), groupId).c_str(),
Sprintf(PutUserData.data(), storagePool.c_str(), groupId).c_str());
}
TString GetMonitoringDashboardYDBGroupUrl(
const TDiagnosticsConfig& config,
ui32 groupId)
{
const auto& monitoringYDBProject =
config.GetMonitoringUrlData().MonitoringYDBProject;
if (monitoringYDBProject.empty()) {
return "";
}
constexpr TStringBuf Url =
"%s/projects/%s/dashboards/"
"%s?from=now-1d&to=now&refresh=60000&p.cluster=*&p.group=%" PRIu32;
return Sprintf(
Url.data(),
config.GetMonitoringUrlData().MonitoringUrl.c_str(),
monitoringYDBProject.c_str(),
config.GetMonitoringUrlData().MonitoringYDBGroupDashboard.c_str(),
groupId);
}
} // namespace NCloud::NBlockStore