Skip to main content

quicknode_sdk/admin/
endpoint_metrics.rs

1#[cfg(feature = "node")]
2use napi_derive::napi;
3#[cfg(feature = "python")]
4use pyo3::pyclass;
5#[cfg(feature = "python")]
6use pyo3_stub_gen::derive::gen_stub_pyclass;
7use serde::{Deserialize, Serialize};
8
9/// Parameters for `get_endpoint_metrics`.
10#[cfg_attr(feature = "python", gen_stub_pyclass)]
11#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
12#[cfg_attr(feature = "node", napi(object))]
13#[derive(Debug, Clone, Default, Serialize)]
14pub struct GetEndpointMetricsRequest {
15    /// Time period (`hour`, `day`, `week`, or `month`).
16    pub period: String,
17    /// Metric name (e.g. `method_calls_over_time`, `response_status_breakdown`).
18    pub metric: String,
19}
20
21/// Parameters for `get_account_metrics`.
22#[cfg_attr(feature = "python", gen_stub_pyclass)]
23#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
24#[cfg_attr(feature = "node", napi(object))]
25#[derive(Debug, Clone, Default, Serialize)]
26pub struct GetAccountMetricsRequest {
27    /// Time period (`hour`, `day`, `week`, or `month`).
28    pub period: String,
29    /// Metric name (e.g. `method_calls_over_time`, `credits_over_time`).
30    pub metric: String,
31    /// Optional percentile for latency metrics (e.g. `p50`, `p95`, `p99`).
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub percentile: Option<String>,
34}
35
36/// A single metric series, consisting of a descriptive tag and timestamped data points.
37#[cfg_attr(feature = "python", gen_stub_pyclass)]
38#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
39#[cfg_attr(feature = "node", napi(object))]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct EndpointMetric {
42    /// Data points, each as `[timestamp, value]`.
43    pub data: Vec<Vec<i64>>,
44    /// Human-readable tag identifying the series.
45    pub tag: String,
46}
47
48/// Response from `get_endpoint_metrics`.
49#[cfg_attr(feature = "python", gen_stub_pyclass)]
50#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
51#[cfg_attr(feature = "node", napi(object))]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct GetEndpointMetricsResponse {
54    /// Metric series returned for the endpoint.
55    #[serde(default)]
56    pub data: Vec<EndpointMetric>,
57    /// Error message when the request did not succeed.
58    pub error: Option<String>,
59}
60
61/// Response from `get_account_metrics`.
62#[cfg_attr(feature = "python", gen_stub_pyclass)]
63#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
64#[cfg_attr(feature = "node", napi(object))]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct GetAccountMetricsResponse {
67    /// Metric series returned for the account.
68    #[serde(default)]
69    pub data: Vec<EndpointMetric>,
70    /// Error message when the request did not succeed.
71    pub error: Option<String>,
72}