Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
fallback_monitoring_backend.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
19#pragma once
20
21#include "monitoring_backend.h"
23
24#include <chrono>
25#include <mutex>
26#include <unordered_map>
27#include <vector>
28
29namespace database
30{
31namespace integrated
32{
33namespace adapters
34{
35namespace backends
36{
37
46{
47public:
50
51 // Non-copyable, non-movable
56
59 bool is_initialized() const override;
60
61 common::VoidResult record_metric(const std::string& name, double value) override;
63 const std::string& name, double value,
64 const std::unordered_map<std::string, std::string>& tags) override;
65
68 common::VoidResult reset() override;
69
70 void record_query_execution(std::chrono::microseconds duration, bool success) override;
71 void record_connection_acquired() override;
72 void record_connection_released() override;
73 void update_pool_stats(std::size_t active, std::size_t idle, std::size_t total) override;
74 void record_transaction_begin() override;
75 void record_transaction_commit() override;
76 void record_transaction_rollback() override;
77
79 std::string export_prometheus_metrics() override;
80
81private:
85 std::chrono::microseconds calculate_percentile(double percentile);
86
90 void update_avg_latency();
91
94 mutable std::mutex mutex_;
95 std::chrono::steady_clock::time_point start_time_;
96
97 // Metrics storage
99 std::vector<std::chrono::microseconds> query_latencies_;
100 std::unordered_map<std::string, double> generic_metrics_;
101};
102
103} // namespace backends
104} // namespace adapters
105} // namespace integrated
106} // namespace database
fallback_monitoring_backend(fallback_monitoring_backend &&)=delete
common::VoidResult initialize() override
Initialize the monitoring backend.
fallback_monitoring_backend & operator=(fallback_monitoring_backend &&)=delete
void update_pool_stats(std::size_t active, std::size_t idle, std::size_t total) override
Update connection pool statistics.
common::Result< metrics_snapshot > get_metrics() override
Get current metrics snapshot.
fallback_monitoring_backend & operator=(const fallback_monitoring_backend &)=delete
void record_query_execution(std::chrono::microseconds duration, bool success) override
Record query execution.
fallback_monitoring_backend(const fallback_monitoring_backend &)=delete
std::chrono::microseconds calculate_percentile(double percentile)
Calculate percentile from latency samples.
std::string export_prometheus_metrics() override
Export metrics in Prometheus format.
common::Result< database_metrics > get_database_metrics() override
Get database-specific metrics.
common::VoidResult shutdown() override
Shutdown the monitoring backend gracefully.
common::Result< health_check_result > check_health() override
Perform health check.
common::VoidResult record_metric(const std::string &name, double value) override
Record a metric value.
Database monitoring adapter with runtime backend selection.
Abstract interface for monitoring backends.
Monitoring and metrics configuration.