]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Copyright (c) 2017 Uber Technologies, Inc. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #ifndef JAEGERTRACING_METRICS_METRICS_H | |
18 | #define JAEGERTRACING_METRICS_METRICS_H | |
19 | ||
20 | #include <string> | |
21 | #include <unordered_map> | |
22 | ||
23 | #include "jaegertracing/Compilers.h" | |
24 | ||
25 | #include "jaegertracing/metrics/Counter.h" | |
26 | #include "jaegertracing/metrics/Gauge.h" | |
27 | #include "jaegertracing/metrics/StatsFactory.h" | |
28 | #include "jaegertracing/metrics/StatsFactoryImpl.h" | |
29 | #include "jaegertracing/metrics/StatsReporter.h" | |
30 | ||
31 | namespace jaegertracing { | |
32 | namespace metrics { | |
33 | ||
34 | class Metrics { | |
35 | public: | |
36 | static std::unique_ptr<Metrics> makeNullMetrics(); | |
37 | ||
38 | static std::unique_ptr<Metrics> fromStatsReporter(StatsReporter& reporter) | |
39 | { | |
40 | // Factory only used for constructor, so need not live past the | |
41 | // initialization of Metrics object. | |
42 | StatsFactoryImpl factory(reporter); | |
43 | return std::unique_ptr<Metrics>(new Metrics(factory)); | |
44 | } | |
45 | ||
46 | static std::string addTagsToMetricName( | |
47 | const std::string& name, | |
48 | const std::unordered_map<std::string, std::string>& tags); | |
49 | ||
50 | explicit Metrics(StatsFactory& factory) | |
51 | : _tracesStartedSampled(factory.createCounter( | |
52 | "jaeger.traces", { { "state", "started" }, { "sampled", "y" } })) | |
53 | , _tracesStartedNotSampled(factory.createCounter( | |
54 | "jaeger.traces", { { "state", "started" }, { "sampled", "n" } })) | |
55 | , _spansStarted(factory.createCounter( | |
56 | "jaeger.spans", | |
57 | { { "state", "started" }, { "group", "lifecycle" } })) | |
58 | , _spansFinished(factory.createCounter( | |
59 | "jaeger.spans", | |
60 | { { "state", "finished" }, { "group", "lifecycle" } })) | |
61 | , _spansSampled(factory.createCounter( | |
62 | "jaeger.spans", { { "group", "sampling" }, { "sampled", "y" } })) | |
63 | , _spansNotSampled(factory.createCounter( | |
64 | "jaeger.spans", { { "group", "sampling" }, { "sampled", "n" } })) | |
65 | , _decodingErrors(factory.createCounter("jaeger.decoding-errors")) | |
66 | , _reporterSuccess(factory.createCounter("jaeger.reporter-spans", | |
67 | { { "state", "success" } })) | |
68 | , _reporterFailure(factory.createCounter("jaeger.reporter-spans", | |
69 | { { "state", "failure" } })) | |
70 | , _reporterDropped(factory.createCounter("jaeger.reporter-spans", | |
71 | { { "state", "dropped" } })) | |
72 | , _reporterQueueLength(factory.createGauge("jaeger.reporter-queue")) | |
73 | , _samplerRetrieved(factory.createCounter("jaeger.sampler", | |
74 | { { "state", "retrieved" } })) | |
75 | , _samplerUpdated(factory.createCounter("jaeger.sampler", | |
76 | { { "state", "updated" } })) | |
77 | , _samplerUpdateFailure(factory.createCounter( | |
78 | "jaeger.sampler", | |
79 | { { "state", "failure" }, { "phase", "updating" } })) | |
80 | , _samplerQueryFailure(factory.createCounter( | |
81 | "jaeger.sampler", | |
82 | { { "state", "failure" }, { "phase", "query" } })) | |
83 | , _samplerParsingFailure(factory.createCounter( | |
84 | "jaeger.sampler", | |
85 | { { "state", "failure" }, { "phase", "parsing" } })) | |
86 | , _baggageUpdateSuccess(factory.createCounter("jaeger.baggage-update", | |
87 | { { "result", "ok" } })) | |
88 | , _baggageUpdateFailure(factory.createCounter("jaeger.baggage-update", | |
89 | { { "result", "err" } })) | |
90 | , _baggageTruncate(factory.createCounter("jaeger.baggage-truncate")) | |
91 | , _baggageRestrictionsUpdateSuccess(factory.createCounter( | |
92 | "jaeger.baggage-restrictions-update", { { "result", "ok" } })) | |
93 | , _baggageRestrictionsUpdateFailure(factory.createCounter( | |
94 | "jaeger.baggage-restrictions-update", { { "result", "err" } })) | |
95 | { | |
96 | } | |
97 | ||
98 | ~Metrics(); | |
99 | ||
100 | const Counter& tracesStartedSampled() const | |
101 | { | |
102 | return *_tracesStartedSampled; | |
103 | } | |
104 | ||
105 | Counter& tracesStartedSampled() { return *_tracesStartedSampled; } | |
106 | ||
107 | const Counter& tracesStartedNotSampled() const | |
108 | { | |
109 | return *_tracesStartedNotSampled; | |
110 | } | |
111 | ||
112 | Counter& tracesStartedNotSampled() { return *_tracesStartedNotSampled; } | |
113 | ||
114 | const Counter& spansStarted() const { return *_spansStarted; } | |
115 | ||
116 | Counter& spansStarted() { return *_spansStarted; } | |
117 | ||
118 | const Counter& spansFinished() const { return *_spansFinished; } | |
119 | ||
120 | Counter& spansFinished() { return *_spansFinished; } | |
121 | ||
122 | const Counter& spansSampled() const { return *_spansSampled; } | |
123 | ||
124 | Counter& spansSampled() { return *_spansSampled; } | |
125 | ||
126 | const Counter& spansNotSampled() const { return *_spansNotSampled; } | |
127 | ||
128 | Counter& spansNotSampled() { return *_spansNotSampled; } | |
129 | ||
130 | const Counter& decodingErrors() const { return *_decodingErrors; } | |
131 | ||
132 | Counter& decodingErrors() { return *_decodingErrors; } | |
133 | ||
134 | const Counter& reporterSuccess() const { return *_reporterSuccess; } | |
135 | ||
136 | Counter& reporterSuccess() { return *_reporterSuccess; } | |
137 | ||
138 | const Counter& reporterFailure() const { return *_reporterFailure; } | |
139 | ||
140 | Counter& reporterFailure() { return *_reporterFailure; } | |
141 | ||
142 | const Counter& reporterDropped() const { return *_reporterDropped; } | |
143 | ||
144 | Counter& reporterDropped() { return *_reporterDropped; } | |
145 | ||
146 | const Gauge& reporterQueueLength() const { return *_reporterQueueLength; } | |
147 | ||
148 | Gauge& reporterQueueLength() { return *_reporterQueueLength; } | |
149 | ||
150 | const Counter& samplerRetrieved() const { return *_samplerRetrieved; } | |
151 | ||
152 | Counter& samplerRetrieved() { return *_samplerRetrieved; } | |
153 | ||
154 | const Counter& samplerUpdated() const { return *_samplerUpdated; } | |
155 | ||
156 | Counter& samplerUpdated() { return *_samplerUpdated; } | |
157 | ||
158 | const Counter& samplerUpdateFailure() const | |
159 | { | |
160 | return *_samplerUpdateFailure; | |
161 | } | |
162 | ||
163 | Counter& samplerUpdateFailure() { return *_samplerUpdateFailure; } | |
164 | ||
165 | const Counter& samplerQueryFailure() const { return *_samplerQueryFailure; } | |
166 | ||
167 | Counter& samplerQueryFailure() { return *_samplerQueryFailure; } | |
168 | ||
169 | const Counter& samplerParsingFailure() const | |
170 | { | |
171 | return *_samplerParsingFailure; | |
172 | } | |
173 | ||
174 | Counter& samplerParsingFailure() { return *_samplerParsingFailure; } | |
175 | ||
176 | const Counter& baggageUpdateSuccess() const | |
177 | { | |
178 | return *_baggageUpdateSuccess; | |
179 | } | |
180 | ||
181 | Counter& baggageUpdateSuccess() { return *_baggageUpdateSuccess; } | |
182 | ||
183 | const Counter& baggageUpdateFailure() const | |
184 | { | |
185 | return *_baggageUpdateFailure; | |
186 | } | |
187 | ||
188 | Counter& baggageUpdateFailure() { return *_baggageUpdateFailure; } | |
189 | ||
190 | const Counter& baggageTruncate() const { return *_baggageTruncate; } | |
191 | ||
192 | Counter& baggageTruncate() { return *_baggageTruncate; } | |
193 | ||
194 | const Counter& baggageRestrictionsUpdateSuccess() const | |
195 | { | |
196 | return *_baggageRestrictionsUpdateSuccess; | |
197 | } | |
198 | ||
199 | Counter& baggageRestrictionsUpdateSuccess() | |
200 | { | |
201 | return *_baggageRestrictionsUpdateSuccess; | |
202 | } | |
203 | ||
204 | const Counter& baggageRestrictionsUpdateFailure() const | |
205 | { | |
206 | return *_baggageRestrictionsUpdateFailure; | |
207 | } | |
208 | ||
209 | Counter& baggageRestrictionsUpdateFailure() | |
210 | { | |
211 | return *_baggageRestrictionsUpdateFailure; | |
212 | } | |
213 | ||
214 | private: | |
215 | std::unique_ptr<Counter> _tracesStartedSampled; | |
216 | std::unique_ptr<Counter> _tracesStartedNotSampled; | |
217 | std::unique_ptr<Counter> _tracesJoinedSampled; | |
218 | std::unique_ptr<Counter> _tracesJoinedNotSampled; | |
219 | std::unique_ptr<Counter> _spansStarted; | |
220 | std::unique_ptr<Counter> _spansFinished; | |
221 | std::unique_ptr<Counter> _spansSampled; | |
222 | std::unique_ptr<Counter> _spansNotSampled; | |
223 | std::unique_ptr<Counter> _decodingErrors; | |
224 | std::unique_ptr<Counter> _reporterSuccess; | |
225 | std::unique_ptr<Counter> _reporterFailure; | |
226 | std::unique_ptr<Counter> _reporterDropped; | |
227 | std::unique_ptr<Gauge> _reporterQueueLength; | |
228 | std::unique_ptr<Counter> _samplerRetrieved; | |
229 | std::unique_ptr<Counter> _samplerUpdated; | |
230 | std::unique_ptr<Counter> _samplerUpdateFailure; | |
231 | std::unique_ptr<Counter> _samplerQueryFailure; | |
232 | std::unique_ptr<Counter> _samplerParsingFailure; | |
233 | std::unique_ptr<Counter> _baggageUpdateSuccess; | |
234 | std::unique_ptr<Counter> _baggageUpdateFailure; | |
235 | std::unique_ptr<Counter> _baggageTruncate; | |
236 | std::unique_ptr<Counter> _baggageRestrictionsUpdateSuccess; | |
237 | std::unique_ptr<Counter> _baggageRestrictionsUpdateFailure; | |
238 | }; | |
239 | ||
240 | } // namespace metrics | |
241 | } // namespace jaegertracing | |
242 | ||
243 | #endif // JAEGERTRACING_METRICS_METRICS_H |