Skip to main content

fastly_api/apis/
metrics_platform_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`get_platform_metrics_aggregate_historical`]
15#[derive(Clone, Debug, Default)]
16pub struct GetPlatformMetricsAggregateHistoricalParams {
17    /// Duration of sample windows.
18    pub granularity: String,
19    /// A valid RFC-8339-formatted date and time indicating the inclusive start of the query time range. If not provided, a default is chosen based on the provided `granularity` value.
20    pub from: Option<String>,
21    /// A valid RFC-8339-formatted date and time indicating the exclusive end of the query time range. If not provided, a default is chosen based on the provided `granularity` value.
22    pub to: Option<String>,
23    /// One or more metrics to retrieve. Multiple values should be comma-separated.
24    pub metric: Option<String>,
25    /// One or more metric sets to retrieve. Multiple values should be comma-separated. A metric set expands to a list of metrics; see the Metric Sets section above for the metrics in each set. A metric that appears in more than one requested set is returned once. 
26    pub metric_set: Option<String>,
27    /// Field to group_by in the query. For example, `group_by=region` will return entries for grouped by timestamp and region. 
28    pub group_by: Option<String>,
29    /// Limit query to one or more specific geographic regions. Values should be comma-separated. 
30    pub region: Option<String>,
31    /// Limit query to one or more specific POPs. Values should be comma-separated.
32    pub datacenter: Option<String>,
33    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
34    pub cursor: Option<String>,
35    /// Number of results per page. The maximum is 10000.
36    pub limit: Option<String>
37}
38
39/// struct for passing parameters to the method [`get_platform_metrics_entity_historical`]
40#[derive(Clone, Debug, Default)]
41pub struct GetPlatformMetricsEntityHistoricalParams {
42    /// Alphanumeric string identifying the entity.
43    pub entity_id: String,
44    /// Duration of sample windows.
45    pub granularity: String,
46    /// A valid RFC-8339-formatted date and time indicating the inclusive start of the query time range. If not provided, a default is chosen based on the provided `granularity` value.
47    pub from: Option<String>,
48    /// A valid RFC-8339-formatted date and time indicating the exclusive end of the query time range. If not provided, a default is chosen based on the provided `granularity` value.
49    pub to: Option<String>,
50    /// One or more metrics to retrieve. Multiple values should be comma-separated.
51    pub metric: Option<String>,
52    /// One or more metric sets to retrieve. Multiple values should be comma-separated. A metric set expands to a list of metrics; see the Metric Sets section above for the metrics in each set. A metric that appears in more than one requested set is returned once. 
53    pub metric_set: Option<String>,
54    /// Field to group_by in the query. For example, `group_by=region` will return entries for grouped by timestamp and region. 
55    pub group_by: Option<String>,
56    /// Limit query to one or more specific geographic regions. Values should be comma-separated. 
57    pub region: Option<String>,
58    /// Limit query to one or more specific POPs. Values should be comma-separated.
59    pub datacenter: Option<String>,
60    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
61    pub cursor: Option<String>,
62    /// Number of results per page. The maximum is 10000.
63    pub limit: Option<String>
64}
65
66
67/// struct for typed errors of method [`get_platform_metrics_aggregate_historical`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum GetPlatformMetricsAggregateHistoricalError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`get_platform_metrics_entity_historical`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetPlatformMetricsEntityHistoricalError {
78    UnknownValue(serde_json::Value),
79}
80
81
82/// Fetches historical metrics for all entities for a customer for a given granularity. Entity in this context refers to an instance of a Fastly resource, such as a VCL service, Compute service, or NGWAF workspace.
83pub async fn get_platform_metrics_aggregate_historical(configuration: &mut configuration::Configuration, params: GetPlatformMetricsAggregateHistoricalParams) -> Result<crate::models::PlatformMetricsResponse, Error<GetPlatformMetricsAggregateHistoricalError>> {
84    let local_var_configuration = configuration;
85
86    // unbox the parameters
87    let granularity = params.granularity;
88    let from = params.from;
89    let to = params.to;
90    let metric = params.metric;
91    let metric_set = params.metric_set;
92    let group_by = params.group_by;
93    let region = params.region;
94    let datacenter = params.datacenter;
95    let cursor = params.cursor;
96    let limit = params.limit;
97
98
99    let local_var_client = &local_var_configuration.client;
100
101    let local_var_uri_str = format!("{}/metrics/v2/platform/aggregate/{granularity}", local_var_configuration.base_path, granularity=crate::apis::urlencode(granularity));
102    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
103
104    if let Some(ref local_var_str) = from {
105        local_var_req_builder = local_var_req_builder.query(&[("from", &local_var_str.to_string())]);
106    }
107    if let Some(ref local_var_str) = to {
108        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
109    }
110    if let Some(ref local_var_str) = metric {
111        local_var_req_builder = local_var_req_builder.query(&[("metric", &local_var_str.to_string())]);
112    }
113    if let Some(ref local_var_str) = metric_set {
114        local_var_req_builder = local_var_req_builder.query(&[("metric_set", &local_var_str.to_string())]);
115    }
116    if let Some(ref local_var_str) = group_by {
117        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
118    }
119    if let Some(ref local_var_str) = region {
120        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
121    }
122    if let Some(ref local_var_str) = datacenter {
123        local_var_req_builder = local_var_req_builder.query(&[("datacenter", &local_var_str.to_string())]);
124    }
125    if let Some(ref local_var_str) = cursor {
126        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
127    }
128    if let Some(ref local_var_str) = limit {
129        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
130    }
131    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
132        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133    }
134    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
135        let local_var_key = local_var_apikey.key.clone();
136        let local_var_value = match local_var_apikey.prefix {
137            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
138            None => local_var_key,
139        };
140        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
141    };
142
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    if "GET" != "GET" && "GET" != "HEAD" {
147      let headers = local_var_resp.headers();
148      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
149          Some(v) => v.to_str().unwrap().parse().unwrap(),
150          None => configuration::DEFAULT_RATELIMIT,
151      };
152      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
153          Some(v) => v.to_str().unwrap().parse().unwrap(),
154          None => 0,
155      };
156    }
157
158    let local_var_status = local_var_resp.status();
159    let local_var_content = local_var_resp.text().await?;
160
161    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162        serde_json::from_str(&local_var_content).map_err(Error::from)
163    } else {
164        let local_var_entity: Option<GetPlatformMetricsAggregateHistoricalError> = serde_json::from_str(&local_var_content).ok();
165        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
166        Err(Error::ResponseError(local_var_error))
167    }
168}
169
170/// Fetches historical metrics for a single entity for a given granularity. Entity in this context refers to an instance of a Fastly resource, such as a VCL service, Compute service, or NGWAF workspace.
171pub async fn get_platform_metrics_entity_historical(configuration: &mut configuration::Configuration, params: GetPlatformMetricsEntityHistoricalParams) -> Result<crate::models::PlatformMetricsResponse, Error<GetPlatformMetricsEntityHistoricalError>> {
172    let local_var_configuration = configuration;
173
174    // unbox the parameters
175    let entity_id = params.entity_id;
176    let granularity = params.granularity;
177    let from = params.from;
178    let to = params.to;
179    let metric = params.metric;
180    let metric_set = params.metric_set;
181    let group_by = params.group_by;
182    let region = params.region;
183    let datacenter = params.datacenter;
184    let cursor = params.cursor;
185    let limit = params.limit;
186
187
188    let local_var_client = &local_var_configuration.client;
189
190    let local_var_uri_str = format!("{}/metrics/v2/platform/entities/{entity_id}/{granularity}", local_var_configuration.base_path, entity_id=crate::apis::urlencode(entity_id), granularity=crate::apis::urlencode(granularity));
191    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
192
193    if let Some(ref local_var_str) = from {
194        local_var_req_builder = local_var_req_builder.query(&[("from", &local_var_str.to_string())]);
195    }
196    if let Some(ref local_var_str) = to {
197        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
198    }
199    if let Some(ref local_var_str) = metric {
200        local_var_req_builder = local_var_req_builder.query(&[("metric", &local_var_str.to_string())]);
201    }
202    if let Some(ref local_var_str) = metric_set {
203        local_var_req_builder = local_var_req_builder.query(&[("metric_set", &local_var_str.to_string())]);
204    }
205    if let Some(ref local_var_str) = group_by {
206        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
207    }
208    if let Some(ref local_var_str) = region {
209        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
210    }
211    if let Some(ref local_var_str) = datacenter {
212        local_var_req_builder = local_var_req_builder.query(&[("datacenter", &local_var_str.to_string())]);
213    }
214    if let Some(ref local_var_str) = cursor {
215        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
216    }
217    if let Some(ref local_var_str) = limit {
218        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
219    }
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
222    }
223    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
224        let local_var_key = local_var_apikey.key.clone();
225        let local_var_value = match local_var_apikey.prefix {
226            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
227            None => local_var_key,
228        };
229        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
230    };
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    if "GET" != "GET" && "GET" != "HEAD" {
236      let headers = local_var_resp.headers();
237      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
238          Some(v) => v.to_str().unwrap().parse().unwrap(),
239          None => configuration::DEFAULT_RATELIMIT,
240      };
241      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
242          Some(v) => v.to_str().unwrap().parse().unwrap(),
243          None => 0,
244      };
245    }
246
247    let local_var_status = local_var_resp.status();
248    let local_var_content = local_var_resp.text().await?;
249
250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251        serde_json::from_str(&local_var_content).map_err(Error::from)
252    } else {
253        let local_var_entity: Option<GetPlatformMetricsEntityHistoricalError> = serde_json::from_str(&local_var_content).ok();
254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258