vector_api_client/gql/
metrics.rs

1//! Metrics queries/subscriptions.
2
3use graphql_client::GraphQLQuery;
4
5use crate::BoxedSubscription;
6
7/// UptimeSubscription returns uptime metrics to determine how long the Vector
8/// instance has been running.
9#[derive(GraphQLQuery, Debug, Copy, Clone)]
10#[graphql(
11    schema_path = "graphql/schema.json",
12    query_path = "graphql/subscriptions/uptime.graphql",
13    response_derives = "Debug"
14)]
15pub struct UptimeSubscription;
16
17/// ComponentAllocatedBytesSubscription contains metrics on the number of allocated bytes
18/// that have been processed by a Vector instance, against specific components.
19#[derive(GraphQLQuery, Debug, Copy, Clone)]
20#[graphql(
21    schema_path = "graphql/schema.json",
22    query_path = "graphql/subscriptions/component_allocated_bytes.graphql",
23    response_derives = "Debug"
24)]
25pub struct ComponentAllocatedBytesSubscription;
26
27/// ComponentReceivedBytesThroughputsSubscription contains metrics on the number of bytes
28/// that have been received between `interval` samples, against specific components.
29#[derive(GraphQLQuery, Debug, Copy, Clone)]
30#[graphql(
31    schema_path = "graphql/schema.json",
32    query_path = "graphql/subscriptions/component_received_bytes_throughputs.graphql",
33    response_derives = "Debug"
34)]
35pub struct ComponentReceivedBytesThroughputsSubscription;
36
37/// ComponentReceivedBytesTotalsSubscription contains metrics on the number of bytes
38/// that have been received by a Vector instance, against a specific component.
39#[derive(GraphQLQuery, Debug, Copy, Clone)]
40#[graphql(
41    schema_path = "graphql/schema.json",
42    query_path = "graphql/subscriptions/component_received_bytes_totals.graphql",
43    response_derives = "Debug"
44)]
45pub struct ComponentReceivedBytesTotalsSubscription;
46
47/// ComponentReceivedEventsThroughputsSubscription contains metrics on the number of events
48/// that have been accepted for processing between `interval` samples, against specific components.
49#[derive(GraphQLQuery, Debug, Copy, Clone)]
50#[graphql(
51    schema_path = "graphql/schema.json",
52    query_path = "graphql/subscriptions/component_received_events_throughputs.graphql",
53    response_derives = "Debug"
54)]
55pub struct ComponentReceivedEventsThroughputsSubscription;
56
57/// ComponentReceivedEventsTotalsSubscription contains metrics on the number of events
58/// that have been accepted for processing by a Vector instance, against specific components.
59#[derive(GraphQLQuery, Debug, Copy, Clone)]
60#[graphql(
61    schema_path = "graphql/schema.json",
62    query_path = "graphql/subscriptions/component_received_events_totals.graphql",
63    response_derives = "Debug"
64)]
65pub struct ComponentReceivedEventsTotalsSubscription;
66
67/// ComponentSentBytesThroughputsSubscription contains metrics on the number of bytes
68/// that have been received between `interval` samples, against specific components.
69#[derive(GraphQLQuery, Debug, Copy, Clone)]
70#[graphql(
71    schema_path = "graphql/schema.json",
72    query_path = "graphql/subscriptions/component_sent_bytes_throughputs.graphql",
73    response_derives = "Debug"
74)]
75pub struct ComponentSentBytesThroughputsSubscription;
76
77/// ComponentSentBytesTotalsSubscription contains metrics on the number of bytes
78/// that have been received by a Vector instance, against a specific component.
79#[derive(GraphQLQuery, Debug, Copy, Clone)]
80#[graphql(
81    schema_path = "graphql/schema.json",
82    query_path = "graphql/subscriptions/component_sent_bytes_totals.graphql",
83    response_derives = "Debug"
84)]
85pub struct ComponentSentBytesTotalsSubscription;
86
87/// ComponentSentEventsThroughputsSubscription contains metrics on the number of events
88/// that have been emitted between `interval` samples, against specific components.
89#[derive(GraphQLQuery, Debug, Copy, Clone)]
90#[graphql(
91    schema_path = "graphql/schema.json",
92    query_path = "graphql/subscriptions/component_sent_events_throughputs.graphql",
93    response_derives = "Debug"
94)]
95pub struct ComponentSentEventsThroughputsSubscription;
96
97/// ComponentSentEventsTotalsSubscription contains metrics on the number of events
98/// that have been emitted by a Vector instance, against specific components.
99#[derive(GraphQLQuery, Debug, Copy, Clone)]
100#[graphql(
101    schema_path = "graphql/schema.json",
102    query_path = "graphql/subscriptions/component_sent_events_totals.graphql",
103    response_derives = "Debug"
104)]
105pub struct ComponentSentEventsTotalsSubscription;
106
107impl component_sent_events_totals_subscription::ComponentSentEventsTotalsSubscriptionComponentSentEventsTotals {
108    pub fn outputs(&self) -> Vec<(String, i64)> {
109        self.outputs
110            .iter()
111            .map(|output| {
112                (
113                    output.output_id.clone(),
114                    output
115                        .sent_events_total
116                        .as_ref()
117                        .map(|p| p.sent_events_total as i64)
118                        .unwrap_or(0),
119                )
120            })
121            .collect()
122    }
123}
124
125impl component_sent_events_throughputs_subscription::ComponentSentEventsThroughputsSubscriptionComponentSentEventsThroughputs {
126    pub fn outputs(&self) -> Vec<(String, i64)> {
127        self.outputs
128            .iter()
129            .map(|output| {
130                (
131                    output.output_id.clone(),
132                    output.throughput,
133                )
134            })
135            .collect()
136    }
137
138}
139
140/// ComponentErrorsTotalsSubscription contains metrics on the number of errors
141/// (metrics ending in `_errors_total`), against specific components.
142#[derive(GraphQLQuery, Debug, Copy, Clone)]
143#[graphql(
144    schema_path = "graphql/schema.json",
145    query_path = "graphql/subscriptions/component_errors_totals.graphql",
146    response_derives = "Debug"
147)]
148pub struct ComponentErrorsTotalsSubscription;
149
150/// Extension methods for metrics subscriptions
151pub trait MetricsSubscriptionExt {
152    /// Executes an uptime metrics subscription.
153    fn uptime_subscription(&self) -> crate::BoxedSubscription<UptimeSubscription>;
154
155    /// Executes an all component allocated bytes subscription.
156    fn component_allocated_bytes_subscription(
157        &self,
158        interval: i64,
159    ) -> BoxedSubscription<ComponentAllocatedBytesSubscription>;
160
161    /// Executes a component bytes received totals subscription.
162    fn component_received_bytes_totals_subscription(
163        &self,
164        interval: i64,
165    ) -> crate::BoxedSubscription<ComponentReceivedBytesTotalsSubscription>;
166
167    /// Executes a component bytes received throughput subscription.
168    fn component_received_bytes_throughputs_subscription(
169        &self,
170        interval: i64,
171    ) -> crate::BoxedSubscription<ComponentReceivedBytesThroughputsSubscription>;
172
173    /// Executes a component received events totals subscription.
174    fn component_received_events_totals_subscription(
175        &self,
176        interval: i64,
177    ) -> crate::BoxedSubscription<ComponentReceivedEventsTotalsSubscription>;
178
179    /// Executes an component events in throughputs subscription.
180    fn component_received_events_throughputs_subscription(
181        &self,
182        interval: i64,
183    ) -> crate::BoxedSubscription<ComponentReceivedEventsThroughputsSubscription>;
184
185    /// Executes a component bytes sent totals subscription.
186    fn component_sent_bytes_totals_subscription(
187        &self,
188        interval: i64,
189    ) -> crate::BoxedSubscription<ComponentSentBytesTotalsSubscription>;
190
191    /// Executes a component bytes sent throughput subscription.
192    fn component_sent_bytes_throughputs_subscription(
193        &self,
194        interval: i64,
195    ) -> crate::BoxedSubscription<ComponentSentBytesThroughputsSubscription>;
196
197    /// Executes a component events totals subscription.
198    fn component_sent_events_totals_subscription(
199        &self,
200        interval: i64,
201    ) -> crate::BoxedSubscription<ComponentSentEventsTotalsSubscription>;
202
203    /// Executes a component sent events throughputs subscription.
204    fn component_sent_events_throughputs_subscription(
205        &self,
206        interval: i64,
207    ) -> crate::BoxedSubscription<ComponentSentEventsThroughputsSubscription>;
208
209    fn component_errors_totals_subscription(
210        &self,
211        interval: i64,
212    ) -> crate::BoxedSubscription<ComponentErrorsTotalsSubscription>;
213}
214
215impl MetricsSubscriptionExt for crate::SubscriptionClient {
216    /// Executes an uptime metrics subscription.
217    fn uptime_subscription(&self) -> BoxedSubscription<UptimeSubscription> {
218        let request_body = UptimeSubscription::build_query(uptime_subscription::Variables);
219
220        self.start::<UptimeSubscription>(&request_body)
221    }
222
223    /// Executes an all component allocated bytes subscription.
224    fn component_allocated_bytes_subscription(
225        &self,
226        interval: i64,
227    ) -> BoxedSubscription<ComponentAllocatedBytesSubscription> {
228        let request_body = ComponentAllocatedBytesSubscription::build_query(
229            component_allocated_bytes_subscription::Variables { interval },
230        );
231
232        self.start::<ComponentAllocatedBytesSubscription>(&request_body)
233    }
234
235    /// Executes an all component bytes received totals subscription.
236    fn component_received_bytes_totals_subscription(
237        &self,
238        interval: i64,
239    ) -> BoxedSubscription<ComponentReceivedBytesTotalsSubscription> {
240        let request_body = ComponentReceivedBytesTotalsSubscription::build_query(
241            component_received_bytes_totals_subscription::Variables { interval },
242        );
243
244        self.start::<ComponentReceivedBytesTotalsSubscription>(&request_body)
245    }
246
247    /// Executes a component bytes received throughput subscription.
248    fn component_received_bytes_throughputs_subscription(
249        &self,
250        interval: i64,
251    ) -> BoxedSubscription<ComponentReceivedBytesThroughputsSubscription> {
252        let request_body = ComponentReceivedBytesThroughputsSubscription::build_query(
253            component_received_bytes_throughputs_subscription::Variables { interval },
254        );
255
256        self.start::<ComponentReceivedBytesThroughputsSubscription>(&request_body)
257    }
258
259    /// Executes an all component received events totals subscription.
260    fn component_received_events_totals_subscription(
261        &self,
262        interval: i64,
263    ) -> BoxedSubscription<ComponentReceivedEventsTotalsSubscription> {
264        let request_body = ComponentReceivedEventsTotalsSubscription::build_query(
265            component_received_events_totals_subscription::Variables { interval },
266        );
267
268        self.start::<ComponentReceivedEventsTotalsSubscription>(&request_body)
269    }
270
271    /// Executes an all component received events throughputs subscription.
272    fn component_received_events_throughputs_subscription(
273        &self,
274        interval: i64,
275    ) -> BoxedSubscription<ComponentReceivedEventsThroughputsSubscription> {
276        let request_body = ComponentReceivedEventsThroughputsSubscription::build_query(
277            component_received_events_throughputs_subscription::Variables { interval },
278        );
279
280        self.start::<ComponentReceivedEventsThroughputsSubscription>(&request_body)
281    }
282
283    /// Executes an all component bytes sent totals subscription.
284    fn component_sent_bytes_totals_subscription(
285        &self,
286        interval: i64,
287    ) -> BoxedSubscription<ComponentSentBytesTotalsSubscription> {
288        let request_body = ComponentSentBytesTotalsSubscription::build_query(
289            component_sent_bytes_totals_subscription::Variables { interval },
290        );
291
292        self.start::<ComponentSentBytesTotalsSubscription>(&request_body)
293    }
294
295    /// Executes a component bytes sent throughput subscription.
296    fn component_sent_bytes_throughputs_subscription(
297        &self,
298        interval: i64,
299    ) -> BoxedSubscription<ComponentSentBytesThroughputsSubscription> {
300        let request_body = ComponentSentBytesThroughputsSubscription::build_query(
301            component_sent_bytes_throughputs_subscription::Variables { interval },
302        );
303
304        self.start::<ComponentSentBytesThroughputsSubscription>(&request_body)
305    }
306
307    /// Executes a component sent events totals subscription.
308    fn component_sent_events_totals_subscription(
309        &self,
310        interval: i64,
311    ) -> crate::BoxedSubscription<ComponentSentEventsTotalsSubscription> {
312        let request_body = ComponentSentEventsTotalsSubscription::build_query(
313            component_sent_events_totals_subscription::Variables { interval },
314        );
315
316        self.start::<ComponentSentEventsTotalsSubscription>(&request_body)
317    }
318
319    /// Executes a component sent events throughputs subscription.
320    fn component_sent_events_throughputs_subscription(
321        &self,
322        interval: i64,
323    ) -> crate::BoxedSubscription<ComponentSentEventsThroughputsSubscription> {
324        let request_body = ComponentSentEventsThroughputsSubscription::build_query(
325            component_sent_events_throughputs_subscription::Variables { interval },
326        );
327
328        self.start::<ComponentSentEventsThroughputsSubscription>(&request_body)
329    }
330
331    fn component_errors_totals_subscription(
332        &self,
333        interval: i64,
334    ) -> BoxedSubscription<ComponentErrorsTotalsSubscription> {
335        let request_body = ComponentErrorsTotalsSubscription::build_query(
336            component_errors_totals_subscription::Variables { interval },
337        );
338
339        self.start::<ComponentErrorsTotalsSubscription>(&request_body)
340    }
341}