pub struct StatsDatabase { /* private fields */ }Implementations§
Source§impl StatsDatabase
impl StatsDatabase
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open (or create) the stats database at the given path.
§Errors
Returns an error if the database cannot be opened or initialized.
Sourcepub fn record_upload(
&self,
bytes: u64,
files: u64,
folder: Option<&str>,
peer: Option<&str>,
network_id: Option<&str>,
) -> Result<()>
pub fn record_upload( &self, bytes: u64, files: u64, folder: Option<&str>, peer: Option<&str>, network_id: Option<&str>, ) -> Result<()>
Sourcepub fn record_download(
&self,
bytes: u64,
files: u64,
folder: Option<&str>,
peer: Option<&str>,
network_id: Option<&str>,
) -> Result<()>
pub fn record_download( &self, bytes: u64, files: u64, folder: Option<&str>, peer: Option<&str>, network_id: Option<&str>, ) -> Result<()>
Sourcepub fn record_transfer(
&self,
direction: &str,
bytes: u64,
files: u64,
folder: Option<&str>,
peer: Option<&str>,
network_id: Option<&str>,
) -> Result<()>
pub fn record_transfer( &self, direction: &str, bytes: u64, files: u64, folder: Option<&str>, peer: Option<&str>, network_id: Option<&str>, ) -> Result<()>
Record a transfer (upload or download) bandwidth event.
§Errors
Returns an error if the database write fails.
Sourcepub fn record_connection(&self, peer: &str) -> Result<()>
pub fn record_connection(&self, peer: &str) -> Result<()>
Sourcepub fn current_stats(&self) -> Result<BandwidthStats>
pub fn current_stats(&self) -> Result<BandwidthStats>
Return aggregated bandwidth statistics for the current period.
§Errors
Returns an error if the database cannot be queried.
Sourcepub fn purge_old_bandwidth(&self, older_than: Duration) -> Result<usize>
pub fn purge_old_bandwidth(&self, older_than: Duration) -> Result<usize>
Delete bandwidth events older than the given duration.
§Errors
Returns an error if the database operation fails.
Sourcepub fn record_network_event(
&self,
network_id: &str,
event_type: &str,
peer: Option<&str>,
details: Option<&str>,
metadata_json: Option<&str>,
) -> Result<()>
pub fn record_network_event( &self, network_id: &str, event_type: &str, peer: Option<&str>, details: Option<&str>, metadata_json: Option<&str>, ) -> Result<()>
Sourcepub fn record_sync_session_start(
&self,
network_id: &str,
folder_namespace: &str,
) -> Result<i64>
pub fn record_sync_session_start( &self, network_id: &str, folder_namespace: &str, ) -> Result<i64>
Record a sync session start and return its session ID.
§Errors
Returns an error if the database write fails.
Sourcepub fn record_sync_session_finish(
&self,
session_id: i64,
files: u64,
bytes: u64,
errors: u64,
status: &str,
) -> Result<()>
pub fn record_sync_session_finish( &self, session_id: i64, files: u64, bytes: u64, errors: u64, status: &str, ) -> Result<()>
Sourcepub fn record_relay_check(
&self,
relay_url: &str,
connected: bool,
latency_ms: Option<i64>,
error_message: Option<&str>,
) -> Result<()>
pub fn record_relay_check( &self, relay_url: &str, connected: bool, latency_ms: Option<i64>, error_message: Option<&str>, ) -> Result<()>
Sourcepub fn recent_network_events(
&self,
network_id: &str,
limit: usize,
) -> Result<Vec<NetworkEventRecord>>
pub fn recent_network_events( &self, network_id: &str, limit: usize, ) -> Result<Vec<NetworkEventRecord>>
Query recent network events for a given network.
§Errors
Returns an error if the database query fails.
Sourcepub fn recent_sync_sessions(
&self,
network_id: &str,
limit: usize,
) -> Result<Vec<SyncSessionRecord>>
pub fn recent_sync_sessions( &self, network_id: &str, limit: usize, ) -> Result<Vec<SyncSessionRecord>>
Query recent sync sessions for a given network.
§Errors
Returns an error if the database query fails.
Sourcepub fn relay_uptime(&self, relay_url: &str, window_secs: i64) -> Result<f64>
pub fn relay_uptime(&self, relay_url: &str, window_secs: i64) -> Result<f64>
Calculate relay uptime as a ratio (0.0-1.0) over the given time window.
§Errors
Returns an error if the database query fails.
Sourcepub fn size_on_disk(&self) -> Result<u64>
pub fn size_on_disk(&self) -> Result<u64>
Return estimated database size in bytes.
§Errors
Returns an error if the file metadata cannot be read.
Sourcepub fn freelist_count(&self) -> Result<i64>
pub fn freelist_count(&self) -> Result<i64>
Return the freelist page count (indicates whether VACUUM would help).
§Errors
Returns an error if the database operation fails.
Trait Implementations§
Source§impl Clone for StatsDatabase
impl Clone for StatsDatabase
Source§fn clone(&self) -> StatsDatabase
fn clone(&self) -> StatsDatabase
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StatsDatabase
impl Debug for StatsDatabase
Auto Trait Implementations§
impl Freeze for StatsDatabase
impl RefUnwindSafe for StatsDatabase
impl Send for StatsDatabase
impl Sync for StatsDatabase
impl Unpin for StatsDatabase
impl UnsafeUnpin for StatsDatabase
impl UnwindSafe for StatsDatabase
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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