datadog_api/apis/
metrics.rs1use crate::{
2 client::DatadogClient,
3 models::{MetricMetadata, MetricsListResponse, MetricsQueryResponse},
4 Result,
5};
6use serde::Serialize;
7
8pub struct MetricsApi {
10 client: DatadogClient,
11}
12
13impl MetricsApi {
14 #[must_use]
16 pub const fn new(client: DatadogClient) -> Self {
17 Self { client }
18 }
19
20 pub async fn query_metrics(
26 &self,
27 from: i64,
28 to: i64,
29 query: &str,
30 ) -> Result<MetricsQueryResponse> {
31 #[derive(Serialize)]
32 struct QueryParams<'a> {
33 from: i64,
34 to: i64,
35 query: &'a str,
36 }
37
38 let params = QueryParams { from, to, query };
39
40 self.client.get_with_query("/api/v1/query", ¶ms).await
41 }
42
43 pub async fn list_metrics(&self, query: &str) -> Result<MetricsListResponse> {
49 #[derive(Serialize)]
50 struct QueryParams<'a> {
51 q: &'a str,
52 }
53
54 let params = QueryParams { q: query };
55
56 self.client.get_with_query("/api/v1/metrics", ¶ms).await
57 }
58
59 pub async fn get_metric_metadata(&self, metric_name: &str) -> Result<MetricMetadata> {
65 let endpoint = format!("/api/v1/metrics/{metric_name}");
66 self.client.get(&endpoint).await
67 }
68}