]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/metrics/InMemoryStatsReporter.cpp
2 * Copyright (c) 2017 Uber Technologies, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "jaegertracing/metrics/InMemoryStatsReporter.h"
19 #include "jaegertracing/metrics/Counter.h"
20 #include "jaegertracing/metrics/Gauge.h"
21 #include "jaegertracing/metrics/Metric.h"
22 #include "jaegertracing/metrics/Metrics.h"
23 #include "jaegertracing/metrics/Timer.h"
25 namespace jaegertracing
{
29 template <typename Function
>
30 void updateMap(InMemoryStatsReporter::ValueMap
& map
,
31 const std::string
& name
,
33 const std::unordered_map
<std::string
, std::string
>& tags
,
36 const auto metricName
= Metrics::addTagsToMetricName(name
, tags
);
37 auto& initialValue
= map
[metricName
];
38 initialValue
= f(initialValue
, newValue
);
41 } // anonymous namespace
43 void InMemoryStatsReporter::incCounter(
44 const std::string
& name
,
46 const std::unordered_map
<std::string
, std::string
>& tags
)
52 [](int64_t initialValue
, int64_t newValue
) {
53 return initialValue
+ newValue
;
57 void InMemoryStatsReporter::recordTimer(
58 const std::string
& name
,
60 const std::unordered_map
<std::string
, std::string
>& tags
)
63 _timers
, name
, time
, tags
, [](int64_t initialValue
, int64_t newValue
) {
64 return initialValue
+ newValue
;
68 void InMemoryStatsReporter::updateGauge(
69 const std::string
& name
,
71 const std::unordered_map
<std::string
, std::string
>& tags
)
73 updateMap(_gauges
, name
, amount
, tags
, [](int64_t, int64_t newValue
) {
78 void InMemoryStatsReporter::reset()
85 } // namespace metrics
86 } // namespace jaegertracing