NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/prometheus/family.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <unordered_map>
24 #include <vector>
25 
26 #include "prometheus/client_metric.h"
27 #include "prometheus/collectable.h"
28 #include "prometheus/detail/core_export.h"
29 #include "prometheus/detail/future_std.h"
30 #include "prometheus/detail/utils.h"
31 #include "prometheus/labels.h"
32 #include "prometheus/metric_family.h"
33 
34 // IWYU pragma: no_include "prometheus/counter.h"
35 // IWYU pragma: no_include "prometheus/gauge.h"
36 // IWYU pragma: no_include "prometheus/histogram.h"
37 // IWYU pragma: no_include "prometheus/info.h"
38 // IWYU pragma: no_include "prometheus/summary.h"
39 
40 namespace prometheus {
41 
78 template <typename T>
79 class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
80  public:
109  Family(const std::string& name, const std::string& help,
110  const Labels& constant_labels);
111 
129  template <typename... Args>
130  T& Add(const Labels& labels, Args&&... args) {
131  return Add(labels, detail::make_unique<T>(args...));
132  }
133 
138  void Remove(T* metric);
139 
143  bool Has(const Labels& labels) const;
144 
148  const std::string& GetName() const;
149 
153  const Labels& GetConstantLabels() const;
154 
160  std::vector<MetricFamily> Collect() const override;
161 
162  private:
163  std::unordered_map<Labels, std::unique_ptr<T>, detail::LabelHasher> metrics_;
164 
165  const std::string name_;
166  const std::string help_;
167  const Labels constant_labels_;
168  mutable std::mutex mutex_;
169 
170  ClientMetric CollectMetric(const Labels& labels, T* metric) const;
171  T& Add(const Labels& labels, std::unique_ptr<T> object);
172 };
173 
174 } // namespace prometheus
prometheus::Family::Add
T & Add(const Labels &labels, Args &&... args)
Add a new dimensional data.
Definition: 9.2/includes/prometheus/family.h:130
prometheus::detail::LabelHasher
Label hasher for use in STL containers.
Definition: includes/prometheus/detail/utils.h:29
prometheus::Labels
std::map< std::string, std::string > Labels
Multiple labels and their value.
Definition: includes/prometheus/labels.h:26
prometheus::ClientMetric
Definition: includes/prometheus/client_metric.h:29
PROMETHEUS_CPP_CORE_EXPORT
#define PROMETHEUS_CPP_CORE_EXPORT
Definition: includes/prometheus/detail/core_export.h:31
prometheus
Definition: includes/prometheus/check_names.h:25