NVIDIA DeepStream SDK API Reference

9.0 Release
sources/libs/nvds_rest_server/prometheus_client.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 #pragma once
13 
14 #include "prometheus/registry.h"
15 #include <memory>
16 #include <atomic>
17 #include <string>
18 #include <mutex>
19 
20 #define GET_PROMETHEUS PrometheusClient::getInstance
21 
23 {
24 public:
26  static PrometheusClient* getInstance();
27  std::shared_ptr<prometheus::Registry> getMetricsRegistry() const { return m_metrics_registry; }
28  std::shared_ptr<prometheus::Registry> getStreamInfoRegistry() const { return m_stream_info_registry; }
29  std::shared_ptr<prometheus::Registry> getReadyRegistry() const { return m_ready_registry; }
30  std::shared_ptr<prometheus::Registry> getLiveRegistry() const { return m_live_registry; }
31  std::shared_ptr<prometheus::Registry> getStartupRegistry() const { return m_startup_registry; }
32 
33  // Methods for stream statistics from metrics-info JSON
34  void updateStreamStats(double fps, uint64_t frame_number, double latency_ms,
35  const std::string& sensor_id, const std::string& sensor_name, int source_id);
36  void updateStreamCount(int count);
37  void clearStreamMetrics();
38 
39  // Methods for system statistics from metrics-info JSON
40  void updateSystemGpuMemory(double gpu_gb);
41  void updateSystemRamMemory(double ram_gb);
42  void updateSystemCpuUtilization(double cpu_util);
43  void updateSystemGpuUtilization(double gpu_util);
44 
45  // Methods for health statistics from health-info JSON
46  void updateDsLiveness(bool is_alive);
47  void updateDsReady(bool is_ready);
48  void updateDsStartup(bool is_startup);
49 
50  void updateStreamInfoCount(int count);
51 
52 private:
53  static PrometheusClient* _instance;
54  static std::once_flag _init_flag;
55 
56  std::shared_ptr<prometheus::Registry> m_ready_registry = nullptr;
57  std::shared_ptr<prometheus::Registry> m_live_registry = nullptr;
58  std::shared_ptr<prometheus::Registry> m_startup_registry = nullptr;
59  std::shared_ptr<prometheus::Registry> m_metrics_registry = nullptr;
60  std::shared_ptr<prometheus::Registry> m_stream_info_registry = nullptr;
61  prometheus::Family<prometheus::Gauge>* m_fps_gauge_family = nullptr;
62  prometheus::Family<prometheus::Gauge>* m_latency_gauge_family = nullptr;
63  prometheus::Family<prometheus::Gauge>* m_frame_number_gauge_family = nullptr;
64  prometheus::Family<prometheus::Gauge>* m_memory_gauge_family = nullptr;
65  prometheus::Family<prometheus::Gauge>* m_utilization_gauge_family = nullptr;
66  prometheus::Family<prometheus::Gauge>* m_stream_count_gauge = nullptr;
67  prometheus::Family<prometheus::Gauge>* m_ready_gauge_family = nullptr;
68  prometheus::Family<prometheus::Gauge>* m_live_gauge_family = nullptr;
69  prometheus::Family<prometheus::Gauge>* m_startup_gauge_family = nullptr;
70  prometheus::Family<prometheus::Gauge>* m_stream_info_count_gauge = nullptr;
71  void BuildGaugeFamily();
72 
73 };
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:31
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:22
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:30
PrometheusClient::getReadyRegistry
std::shared_ptr< prometheus::Registry > getReadyRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:29
PrometheusClient::getMetricsRegistry
std::shared_ptr< prometheus::Registry > getMetricsRegistry() const
Definition: sources/libs/nvds_rest_server/prometheus_client.h:27
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:28
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()