12#include <unordered_map>
15#include <condition_variable>
22 class performance_monitor;
32 std::chrono::steady_clock::time_point
end_time;
153 std::chrono::steady_clock::time_point
timestamp);
180 std::shared_ptr<performance_monitor> monitor);
186 void set_error(
const std::string& error);
214 std::chrono::microseconds latency_threshold);
219 void record_slow_query(
const std::string& query, std::chrono::microseconds execution_time);
225 std::vector<query_metrics>
get_slow_queries(std::chrono::microseconds threshold)
const;
233 std::vector<performance_alert>
get_recent_alerts(std::chrono::minutes window)
const;
287 virtual bool export_alerts(
const std::vector<performance_alert>& alerts) = 0;
300 bool export_alerts(
const std::vector<performance_alert>& alerts)
override;
335 #define MONITOR_QUERY(query, db_type) \
336 database::monitoring::query_timer timer_(query, db_type)
338 #define MONITOR_QUERY_RESULT(rows) \
339 timer_.set_rows_affected(rows)
341 #define MONITOR_QUERY_ERROR(error) \
342 timer_.set_error(error)
Simple HTTP server for performance dashboard.
std::string handle_request(const std::string &path) const
std::atomic< bool > running_
dashboard_server(int port=8080)
std::string custom_dashboard_
std::thread server_thread_
void set_custom_dashboard(const std::string &html_content)
Export metrics to external monitoring systems.
virtual ~metrics_exporter()=default
virtual bool export_metrics(const performance_summary &summary)=0
virtual bool export_alerts(const std::vector< performance_alert > &alerts)=0
Export metrics in Prometheus format.
std::string format_prometheus_metrics(const performance_summary &summary) const
bool export_alerts(const std::vector< performance_alert > &alerts) override
bool export_metrics(const performance_summary &summary) override
prometheus_exporter(const std::string &endpoint, int port)
RAII timer for measuring query execution time.
void set_error(const std::string &error)
void set_rows_affected(size_t rows)
std::shared_ptr< performance_monitor > monitor_
query_timer(const std::string &query, database_types db_type, std::shared_ptr< performance_monitor > monitor)
Constructor with explicit performance_monitor (recommended)
std::chrono::steady_clock::time_point start_time_
Defines the enumeration of supported database types.
database_types
Represents various database backends or modes.
@ none
No specific database type is set.
Metrics for database connection usage.
std::atomic< size_t > idle_connections
connection_metrics()=default
connection_metrics & operator=(connection_metrics &&other) noexcept
std::atomic< size_t > failed_connections
connection_metrics(connection_metrics &&other) noexcept
std::atomic< std::chrono::microseconds > max_acquisition_time
std::atomic< std::chrono::microseconds > avg_acquisition_time
std::atomic< size_t > active_connections
std::chrono::steady_clock::time_point last_update
connection_metrics(const connection_metrics &other)
std::atomic< size_t > total_connections
connection_metrics & operator=(const connection_metrics &other)
Metrics for individual query execution.
std::chrono::steady_clock::time_point start_time
std::string error_message
std::chrono::steady_clock::time_point end_time
std::chrono::microseconds execution_time