NVIDIA DeepStream SDK API Reference

9.1 Release
sources/libs/nvds_rest_server/prometheus_client.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025-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 "prometheus/registry.h"
21 #include <memory>
22 #include <atomic>
23 #include <string>
24 #include <mutex>
25 
26 #define GET_PROMETHEUS PrometheusClient::getInstance
27 
29 {
30 public:
32  static PrometheusClient* getInstance();
33  std::shared_ptr<prometheus::Registry> getMetricsRegistry() const { return m_metrics_registry; }
34  std::shared_ptr<prometheus::Registry> getStreamInfoRegistry() const { return m_stream_info_registry; }
35  std::shared_ptr<prometheus::Registry> getReadyRegistry() const { return m_ready_registry; }
36  std::shared_ptr<prometheus::Registry> getLiveRegistry() const { return m_live_registry; }
37  std::shared_ptr<prometheus::Registry> getStartupRegistry() const { return m_startup_registry; }
38 
39  // Methods for stream statistics from metrics-info JSON
40  void updateStreamStats(double fps, uint64_t frame_number, double latency_ms,
41  const std::string& sensor_id, const std::string& sensor_name, int source_id);
42  void updateStreamCount(int count);
43  void clearStreamMetrics();
44 
45  // Methods for system statistics from metrics-info JSON
46  void updateSystemGpuMemory(double gpu_gb);
47  void updateSystemRamMemory(double ram_gb);
48  void updateSystemCpuUtilization(double cpu_util);
49  void updateSystemGpuUtilization(double gpu_util);
50 
51  // Methods for health statistics from health-info JSON
52  void updateDsLiveness(bool is_alive);
53  void updateDsReady(bool is_ready);
54  void updateDsStartup(bool is_startup);
55 
56  void updateStreamInfoCount(int count);
57 
58 private:
59  static PrometheusClient* _instance;
60  static std::once_flag _init_flag;
61 
62  std::shared_ptr<prometheus::Registry> m_ready_registry = nullptr;
63  std::shared_ptr<prometheus::Registry> m_live_registry = nullptr;
64  std::shared_ptr<prometheus::Registry> m_startup_registry = nullptr;
65  std::shared_ptr<prometheus::Registry> m_metrics_registry = nullptr;
66  std::shared_ptr<prometheus::Registry> m_stream_info_registry = nullptr;
67  prometheus::Family<prometheus::Gauge>* m_fps_gauge_family = nullptr;
68  prometheus::Family<prometheus::Gauge>* m_latency_gauge_family = nullptr;
69  prometheus::Family<prometheus::Gauge>* m_frame_number_gauge_family = nullptr;
70  prometheus::Family<prometheus::Gauge>* m_memory_gauge_family = nullptr;
71  prometheus::Family<prometheus::Gauge>* m_utilization_gauge_family = nullptr;
72  prometheus::Family<prometheus::Gauge>* m_stream_count_gauge = nullptr;
73  prometheus::Family<prometheus::Gauge>* m_ready_gauge_family = nullptr;
74  prometheus::Family<prometheus::Gauge>* m_live_gauge_family = nullptr;
75  prometheus::Family<prometheus::Gauge>* m_startup_gauge_family = nullptr;
76  prometheus::Family<prometheus::Gauge>* m_stream_info_count_gauge = nullptr;
77  void BuildGaugeFamily();
78 
79 };
PrometheusClient::updateDsReady
void updateDsReady(bool is_ready)
PrometheusClient::updateSystemRamMemory
void updateSystemRamMemory(double ram_gb)
PrometheusClient::getStartupRegistry
std::shared_ptr< prometheus::Registry > getStartupRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:37
prometheus::Family< prometheus::Gauge >
PrometheusClient::getInstance
static PrometheusClient * getInstance()
PrometheusClient::PrometheusClient
PrometheusClient()
PrometheusClient::updateDsLiveness
void updateDsLiveness(bool is_alive)
PrometheusClient
Definition: sources/libs/nvds_rest_server/prometheus_client.h:28
PrometheusClient::updateSystemCpuUtilization
void updateSystemCpuUtilization(double cpu_util)
PrometheusClient::getLiveRegistry
std::shared_ptr< prometheus::Registry > getLiveRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:36
PrometheusClient::getReadyRegistry
std::shared_ptr< prometheus::Registry > getReadyRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:35
PrometheusClient::getMetricsRegistry
std::shared_ptr< prometheus::Registry > getMetricsRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:33
PrometheusClient::updateStreamStats
void updateStreamStats(double fps, uint64_t frame_number, double latency_ms, const std::string &sensor_id, const std::string &sensor_name, int source_id)
PrometheusClient::updateDsStartup
void updateDsStartup(bool is_startup)
PrometheusClient::getStreamInfoRegistry
std::shared_ptr< prometheus::Registry > getStreamInfoRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:34
PrometheusClient::updateSystemGpuMemory
void updateSystemGpuMemory(double gpu_gb)
PrometheusClient::updateSystemGpuUtilization
void updateSystemGpuUtilization(double gpu_util)
PrometheusClient::updateStreamInfoCount
void updateStreamInfoCount(int count)
PrometheusClient::updateStreamCount
void updateStreamCount(int count)
PrometheusClient::clearStreamMetrics
void clearStreamMetrics()