pub struct AnalyticsDatabase { /* private fields */ }Expand description
Analytics database manager
Implementations§
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn new(database_path: &Path) -> Result<Self>
pub async fn new(database_path: &Path) -> Result<Self>
Create a new analytics database connection
§Arguments
database_path- Path to the SQLite database file (or “:memory:” for in-memory)
Sourcepub async fn run_migrations(&self) -> Result<()>
pub async fn run_migrations(&self) -> Result<()>
Run database migrations
Sourcepub fn pool(&self) -> &SqlitePool
pub fn pool(&self) -> &SqlitePool
Get a reference to the database pool
Sourcepub async fn insert_minute_aggregate(
&self,
agg: &MetricsAggregate,
) -> Result<i64>
pub async fn insert_minute_aggregate( &self, agg: &MetricsAggregate, ) -> Result<i64>
Insert a minute-level metrics aggregate
Sourcepub async fn insert_minute_aggregates_batch(
&self,
aggregates: &[MetricsAggregate],
) -> Result<()>
pub async fn insert_minute_aggregates_batch( &self, aggregates: &[MetricsAggregate], ) -> Result<()>
Insert multiple minute-level aggregates in a batch
Sourcepub async fn insert_hour_aggregate(
&self,
agg: &HourMetricsAggregate,
) -> Result<i64>
pub async fn insert_hour_aggregate( &self, agg: &HourMetricsAggregate, ) -> Result<i64>
Insert an hour-level metrics aggregate
Sourcepub async fn insert_day_aggregate(
&self,
agg: &DayMetricsAggregate,
) -> Result<i64>
pub async fn insert_day_aggregate( &self, agg: &DayMetricsAggregate, ) -> Result<i64>
Insert a day-level metrics aggregate
Sourcepub async fn upsert_endpoint_stats(&self, stats: &EndpointStats) -> Result<()>
pub async fn upsert_endpoint_stats(&self, stats: &EndpointStats) -> Result<()>
Insert or update endpoint statistics
Sourcepub async fn insert_error_event(&self, error: &ErrorEvent) -> Result<i64>
pub async fn insert_error_event(&self, error: &ErrorEvent) -> Result<i64>
Insert an error event
Sourcepub async fn insert_traffic_pattern(
&self,
pattern: &TrafficPattern,
) -> Result<()>
pub async fn insert_traffic_pattern( &self, pattern: &TrafficPattern, ) -> Result<()>
Insert a traffic pattern
Sourcepub async fn insert_snapshot(&self, snapshot: &AnalyticsSnapshot) -> Result<i64>
pub async fn insert_snapshot(&self, snapshot: &AnalyticsSnapshot) -> Result<i64>
Insert an analytics snapshot
Sourcepub async fn get_minute_aggregates(
&self,
filter: &AnalyticsFilter,
) -> Result<Vec<MetricsAggregate>>
pub async fn get_minute_aggregates( &self, filter: &AnalyticsFilter, ) -> Result<Vec<MetricsAggregate>>
Get minute aggregates for a time range
Sourcepub async fn get_top_endpoints(
&self,
limit: i64,
workspace_id: Option<&str>,
) -> Result<Vec<EndpointStats>>
pub async fn get_top_endpoints( &self, limit: i64, workspace_id: Option<&str>, ) -> Result<Vec<EndpointStats>>
Get top endpoints by request count
Sourcepub async fn get_recent_errors(
&self,
limit: i64,
filter: &AnalyticsFilter,
) -> Result<Vec<ErrorEvent>>
pub async fn get_recent_errors( &self, limit: i64, filter: &AnalyticsFilter, ) -> Result<Vec<ErrorEvent>>
Get recent error events
Sourcepub async fn get_traffic_patterns(
&self,
days: i64,
workspace_id: Option<&str>,
) -> Result<Vec<TrafficPattern>>
pub async fn get_traffic_patterns( &self, days: i64, workspace_id: Option<&str>, ) -> Result<Vec<TrafficPattern>>
Get traffic patterns for heatmap
Sourcepub async fn cleanup_minute_aggregates(&self, days: u32) -> Result<u64>
pub async fn cleanup_minute_aggregates(&self, days: u32) -> Result<u64>
Delete old minute aggregates
Sourcepub async fn cleanup_hour_aggregates(&self, days: u32) -> Result<u64>
pub async fn cleanup_hour_aggregates(&self, days: u32) -> Result<u64>
Delete old hour aggregates
Sourcepub async fn cleanup_error_events(&self, days: u32) -> Result<u64>
pub async fn cleanup_error_events(&self, days: u32) -> Result<u64>
Delete old error events
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn export_to_csv<W: Write>(
&self,
writer: &mut W,
filter: &AnalyticsFilter,
) -> Result<usize>
pub async fn export_to_csv<W: Write>( &self, writer: &mut W, filter: &AnalyticsFilter, ) -> Result<usize>
Export metrics to CSV format
Sourcepub async fn export_to_json(&self, filter: &AnalyticsFilter) -> Result<String>
pub async fn export_to_json(&self, filter: &AnalyticsFilter) -> Result<String>
Export metrics to JSON format
Sourcepub async fn export_endpoints_to_csv<W: Write>(
&self,
writer: &mut W,
workspace_id: Option<&str>,
limit: i64,
) -> Result<usize>
pub async fn export_endpoints_to_csv<W: Write>( &self, writer: &mut W, workspace_id: Option<&str>, limit: i64, ) -> Result<usize>
Export endpoint stats to CSV
Sourcepub async fn export_errors_to_csv<W: Write>(
&self,
writer: &mut W,
filter: &AnalyticsFilter,
limit: i64,
) -> Result<usize>
pub async fn export_errors_to_csv<W: Write>( &self, writer: &mut W, filter: &AnalyticsFilter, limit: i64, ) -> Result<usize>
Export error events to CSV
Source§impl AnalyticsDatabase
impl AnalyticsDatabase
Sourcepub async fn get_overview_metrics(
&self,
duration_seconds: i64,
) -> Result<OverviewMetrics>
pub async fn get_overview_metrics( &self, duration_seconds: i64, ) -> Result<OverviewMetrics>
Get overview metrics for the dashboard
Sourcepub async fn get_top_protocols(
&self,
limit: i64,
workspace_id: Option<&str>,
) -> Result<Vec<ProtocolStat>>
pub async fn get_top_protocols( &self, limit: i64, workspace_id: Option<&str>, ) -> Result<Vec<ProtocolStat>>
Get top protocols by request count
Sourcepub async fn get_request_time_series(
&self,
filter: &AnalyticsFilter,
granularity: Granularity,
) -> Result<Vec<TimeSeries>>
pub async fn get_request_time_series( &self, filter: &AnalyticsFilter, granularity: Granularity, ) -> Result<Vec<TimeSeries>>
Get request count time series
Sourcepub async fn get_latency_trends(
&self,
filter: &AnalyticsFilter,
) -> Result<Vec<LatencyTrend>>
pub async fn get_latency_trends( &self, filter: &AnalyticsFilter, ) -> Result<Vec<LatencyTrend>>
Get latency trends
Sourcepub async fn get_error_summary(
&self,
filter: &AnalyticsFilter,
limit: i64,
) -> Result<Vec<ErrorSummary>>
pub async fn get_error_summary( &self, filter: &AnalyticsFilter, limit: i64, ) -> Result<Vec<ErrorSummary>>
Get error summary
Trait Implementations§
Source§impl Clone for AnalyticsDatabase
impl Clone for AnalyticsDatabase
Source§fn clone(&self) -> AnalyticsDatabase
fn clone(&self) -> AnalyticsDatabase
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AnalyticsDatabase
impl !RefUnwindSafe for AnalyticsDatabase
impl Send for AnalyticsDatabase
impl Sync for AnalyticsDatabase
impl Unpin for AnalyticsDatabase
impl !UnwindSafe for AnalyticsDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more