Skip to content

Commit

Permalink
Update metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
vruello committed Nov 26, 2024
1 parent a5e6786 commit 3c968b8
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 142 deletions.
31 changes: 19 additions & 12 deletions common/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ pub struct Monitoring {
listen_address: String,
listen_port: u16,
http_request_duration_buckets: Option<Vec<f64>>,
count_received_events_per_machine: Option<bool>,
count_event_size_per_machine: Option<bool>,
count_input_events_per_machine: Option<bool>,
count_input_event_bytes_per_machine: Option<bool>,
count_http_request_body_network_size_per_machine: Option<bool>,
count_http_request_body_real_size_per_machine: Option<bool>,
}
Expand All @@ -398,12 +398,12 @@ impl Monitoring {
}
}

pub fn count_received_events_per_machine(&self) -> bool {
self.count_received_events_per_machine.unwrap_or(false)
pub fn count_input_events_per_machine(&self) -> bool {
self.count_input_events_per_machine.unwrap_or(false)
}

pub fn count_event_size_per_machine(&self) -> bool {
self.count_event_size_per_machine.unwrap_or(false)
pub fn count_input_event_bytes_per_machine(&self) -> bool {
self.count_input_event_bytes_per_machine.unwrap_or(false)
}

pub fn count_http_request_body_network_size_per_machine(&self) -> bool {
Expand Down Expand Up @@ -632,7 +632,9 @@ mod tests {
assert_eq!(s.monitoring().unwrap().listen_address(), "127.0.0.1");
assert_eq!(s.monitoring().unwrap().listen_port(), 9090);
assert_eq!(
s.monitoring().unwrap().count_event_size_per_machine(),
s.monitoring()
.unwrap()
.count_input_event_bytes_per_machine(),
false
);
assert_eq!(
Expand All @@ -648,7 +650,7 @@ mod tests {
false
);
assert_eq!(
s.monitoring().unwrap().count_received_events_per_machine(),
s.monitoring().unwrap().count_input_events_per_machine(),
false
);
assert_eq!(
Expand Down Expand Up @@ -688,10 +690,10 @@ mod tests {
listen_address = "127.0.0.1"
listen_port = 9090
http_request_duration_buckets = [0.0005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0]
count_event_size_per_machine = true
count_input_event_bytes_per_machine = true
count_http_request_body_network_size_per_machine = true
count_http_request_body_real_size_per_machine = true
count_received_events_per_machine = true
count_input_events_per_machine = true
"#;

#[test]
Expand All @@ -702,7 +704,12 @@ mod tests {
assert!(s.monitoring().is_some());
assert_eq!(s.monitoring().unwrap().listen_address(), "127.0.0.1");
assert_eq!(s.monitoring().unwrap().listen_port(), 9090);
assert_eq!(s.monitoring().unwrap().count_event_size_per_machine(), true);
assert_eq!(
s.monitoring()
.unwrap()
.count_input_event_bytes_per_machine(),
true
);
assert_eq!(
s.monitoring()
.unwrap()
Expand All @@ -716,7 +723,7 @@ mod tests {
true
);
assert_eq!(
s.monitoring().unwrap().count_received_events_per_machine(),
s.monitoring().unwrap().count_input_events_per_machine(),
true
);
assert_eq!(
Expand Down
26 changes: 16 additions & 10 deletions common/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use anyhow::{anyhow, bail, Result};
use log::{info, warn};
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumString, VariantNames};
use strum::{AsRefStr, EnumString, IntoStaticStr, VariantNames};
use uuid::Uuid;

use crate::utils::VersionHasher;
Expand Down Expand Up @@ -96,12 +96,8 @@ pub struct FilesConfiguration {
}

impl FilesConfiguration {
pub fn new(
path: String,
) -> Self {
Self {
path
}
pub fn new(path: String) -> Self {
Self { path }
}

pub fn path(&self) -> &str {
Expand Down Expand Up @@ -182,7 +178,17 @@ impl Display for SubscriptionOutput {
}
}
#[derive(
Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash, VariantNames, AsRefStr, EnumString,
Debug,
Clone,
Eq,
PartialEq,
Serialize,
Deserialize,
Hash,
VariantNames,
AsRefStr,
EnumString,
IntoStaticStr,
)]
#[strum(serialize_all = "snake_case", ascii_case_insensitive)]
pub enum SubscriptionOutputFormat {
Expand Down Expand Up @@ -683,8 +689,8 @@ impl SubscriptionData {
self
}

/// Set the subscription's max elements.
pub fn set_max_elements(&mut self, max_elements: Option<u32>) -> &mut Self {
/// Set the subscription's max elements.
pub fn set_max_elements(&mut self, max_elements: Option<u32>) -> &mut Self {
self.parameters.max_elements = max_elements;
self.update_internal_version();
self
Expand Down
17 changes: 10 additions & 7 deletions doc/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ Metrics collection and publication can be enabled in the OpenWEC settings (see `

| **Metric** | **Type** | **Labels** | **Description** |
|---|---|---|---|
| `openwec_received_events_total` | `Counter` | `subscription_uuid`, `subscription_name`, `machine` (optional*) | Number of events received by openwec |
| `openwec_event_size_bytes_total` | `Counter` | `subscription_uuid`, `subscription_name`, `machine` (optional*) | The total size of all events received by openwec |
| `http_request_body_real_size_bytes_total` | `Counter` | `method`, `uri`, `machine` (optional*) | The total size of all http requests body received by openwec after decryption and decompression |
| `http_request_body_network_size_bytes_total` | `Counter` | `method`, `uri`, `machine` (optional*) | The total size of all http requests body received by openwec |
| `openwec_messages_total` | `Counter` | `action` (one of `"enumerate"`, `"heartbeat"`, `"events"`) | Number of messages received by openwec |
| `openwec_event_output_failures_total` | `Counter` | `subscription_uuid`, `subscription_name` | Number of events that could not be written to outputs by openwec |
| `http_request_duration_seconds` | `Histogram` | `method`, `status`, `uri` | HTTP requests duration histogram |
| `openwec_input_events_total` | `Counter` | `subscription_uuid`, `subscription_name`, `machine` (optional*) | The total number of events received by openwec |
| `openwec_input_event_bytes_total` | `Counter` | `subscription_uuid`, `subscription_name`, `machine` (optional*) | The total size of all events received by openwec |
| `openwec_input_messages_total` | `Counter` | `action` (one of `"enumerate"`, `"heartbeat"`, `"events"`) | The total number of messages received by openwec |
| `openwec_input_event_parsing_failures_total` | `Counter` | `subscription_uuid`, `subscription_name`, `type` | The total number of event parsing failures |
| `openwec_http_requests_total` | `Counter` | `uri`, `code` | The total number of HTTP requests handled by openwec |
| `openwec_http_request_duration_seconds` | `Histogram` | `uri` | Histogram of response duration for HTTP requests |
| `openwec_http_request_body_network_size_bytes_total` | `Counter` | `uri`, `machine` (optional*) | The total size of all http requests body received by openwec |
| `openwec_http_request_body_real_size_bytes_total` | `Counter` | `uri`, `machine` (optional*) | The total size of all http requests body received by openwec after decryption and decompression |
| `openwec_output_driver_failures_total` | `Counter` | `subscription_uuid`, `subscription_name`, `driver` | The total number of output driver failures |
| `openwec_output_format_failures_total` | `Counter` | `subscription_uuid`, `subscription_name`, `format` | The total number of output format failures |

> [!WARNING]
> Enabling the `machine` labels may cause a **huge** increase in metric cardinality!
14 changes: 7 additions & 7 deletions openwec.conf.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,25 @@
# listen_port =

# [Optional]
# Request duration buckets (in seconds) used by the "http_request_duration_seconds" histogram
# Request duration buckets (in seconds) used by the "openwec_http_request_duration_seconds" histogram
# http_request_duration_buckets = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0]

# [Optional]
# If set, a "machine" label will be added to the "openwec_received_events_total" metric
# If set, a "machine" label will be added to the "openwec_input_events_total" metric
# Warning: this may cause a HUGE increase in metric cardinality
# count_received_events_per_machine = false
# count_input_events_per_machine = false

# [Optional]
# If set, a "machine" label will be added to the "openwec_event_size_bytes_total" metric
# If set, a "machine" label will be added to the "openwec_input_event_bytes_total" metric
# Warning: this may cause a HUGE increase in metric cardinality
# count_event_size_per_machine = false
# count_input_event_bytes_per_machine = false

# [Optional]
# If set, a "machine" label will be added to the "http_request_body_network_size_bytes_total" metric
# If set, a "machine" label will be added to the "openwec_http_request_body_network_size_bytes_total" metric
# Warning: this may cause a HUGE increase in metric cardinality
# count_http_request_body_network_size_per_machine = false

# [Optional]
# If set, a "machine" label will be added to the "http_request_body_real_size_bytes_total" metric
# If set, a "machine" label will be added to the "openwec_http_request_body_real_size_bytes_total" metric
# Warning: this may cause a HUGE increase in metric cardinality
# count_http_request_body_real_size_per_machine = false
Loading

0 comments on commit 3c968b8

Please sign in to comment.