vector/internal_events/
nginx_metrics.rs

1use metrics::counter;
2use vector_lib::{
3    internal_event::{InternalEvent, error_stage, error_type},
4    json_size::JsonSize,
5};
6
7use crate::sources::nginx_metrics::parser::ParseError;
8
9#[derive(Debug)]
10pub struct NginxMetricsEventsReceived<'a> {
11    pub byte_size: JsonSize,
12    pub count: usize,
13    pub endpoint: &'a str,
14}
15
16impl InternalEvent for NginxMetricsEventsReceived<'_> {
17    fn emit(self) {
18        trace!(
19            message = "Events received.",
20            byte_size = %self.byte_size,
21            count = %self.count,
22            endpoint = self.endpoint,
23        );
24        counter!(
25            "component_received_events_total",
26            "endpoint" => self.endpoint.to_owned(),
27        )
28        .increment(self.count as u64);
29        counter!(
30            "component_received_event_bytes_total",
31            "endpoint" => self.endpoint.to_owned(),
32        )
33        .increment(self.byte_size.get() as u64);
34    }
35}
36
37pub struct NginxMetricsRequestError<'a> {
38    pub error: crate::Error,
39    pub endpoint: &'a str,
40}
41
42impl InternalEvent for NginxMetricsRequestError<'_> {
43    fn emit(self) {
44        error!(
45            message = "Nginx request error.",
46            endpoint = %self.endpoint,
47            error = %self.error,
48            error_type = error_type::REQUEST_FAILED,
49            stage = error_stage::RECEIVING,
50            internal_log_rate_limit = true,
51        );
52        counter!(
53            "component_errors_total",
54            "endpoint" => self.endpoint.to_owned(),
55            "error_type" => error_type::REQUEST_FAILED,
56            "stage" => error_stage::RECEIVING,
57        )
58        .increment(1);
59    }
60}
61
62pub(crate) struct NginxMetricsStubStatusParseError<'a> {
63    pub error: ParseError,
64    pub endpoint: &'a str,
65}
66
67impl InternalEvent for NginxMetricsStubStatusParseError<'_> {
68    fn emit(self) {
69        error!(
70            message = "NginxStubStatus parse error.",
71            endpoint = %self.endpoint,
72            error = %self.error,
73            error_type = error_type::PARSER_FAILED,
74            stage = error_stage::PROCESSING,
75            internal_log_rate_limit = true,
76        );
77        counter!(
78            "component_errors_total",
79            "endpoint" => self.endpoint.to_owned(),
80            "error_type" => error_type::PARSER_FAILED,
81            "stage" => error_stage::PROCESSING,
82        )
83        .increment(1);
84    }
85}