Skip to content

Commit

Permalink
standardize metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Steensen <luke.steensen@gmail.com>
  • Loading branch information
lukesteensen committed Apr 7, 2020
1 parent eabfe0a commit 42c9987
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/internal_events/blackhole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub struct BlackholeEventReceived {
impl InternalEvent for BlackholeEventReceived {
fn emit_metrics(&self) {
counter!(
"events_received", 1,
"events_processed", 1,
"component_kind" => "sink",
"component_type" => "blackhole",
);
counter!(
"bytes_received", self.byte_size as u64,
"bytes_processed", self.byte_size as u64,
"component_kind" => "sink",
"component_type" => "blackhole",
);
Expand Down
4 changes: 2 additions & 2 deletions src/internal_events/elasticsearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pub struct ElasticSearchEventReceived {
impl InternalEvent for ElasticSearchEventReceived {
fn emit_metrics(&self) {
counter!(
"events_received", 1,
"events_processed", 1,
"component_kind" => "sink",
"component_type" => "elasticsearch",
);
counter!(
"bytes_received", self.byte_size as u64,
"bytes_processed", self.byte_size as u64,
"component_kind" => "sink",
"component_type" => "elasticsearch",
);
Expand Down
4 changes: 2 additions & 2 deletions src/internal_events/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ impl InternalEvent for FileEventReceived<'_> {

fn emit_metrics(&self) {
counter!(
"events_received", 1,
"events_processed", 1,
"component_kind" => "source",
"component_type" => "file",
);
counter!(
"bytes_received", self.byte_size as u64,
"bytes_processed", self.byte_size as u64,
"component_kind" => "source",
"component_type" => "file",
);
Expand Down
13 changes: 3 additions & 10 deletions src/internal_events/lua.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
use super::InternalEvent;
use crate::transforms::lua::v1::format_error;
use metrics::{counter, gauge, timing};
use std::time::Duration;
use metrics::{counter, gauge};

#[derive(Debug)]
pub struct LuaEventProcessed {
pub duration: Duration,
}
pub struct LuaEventProcessed;

impl InternalEvent for LuaEventProcessed {
fn emit_metrics(&self) {
timing!("processing_duration", self.duration,
"component_kind" => "transform",
"component_type" => "lua",
);
counter!("events_processed", 1,
"component_kind" => "transform",
"component_type" => "lua",
Expand Down Expand Up @@ -47,7 +40,7 @@ impl InternalEvent for LuaScriptError {
}

fn emit_metrics(&self) {
counter!("script_error", 1,
counter!("processing_errors", 1,
"component_kind" => "transform",
"component_type" => "lua",
);
Expand Down
1 change: 1 addition & 0 deletions src/internal_events/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct PrometheusRequestCompleted;

impl InternalEvent for PrometheusRequestCompleted {
fn emit_metrics(&self) {
// TODO: make this a timer
counter!("requests_completed", 1,
"component_kind" => "source",
"component_type" => "prometheus",
Expand Down
6 changes: 4 additions & 2 deletions src/internal_events/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ impl InternalEvent for RegexFailedMatch<'_> {
}

fn emit_metrics(&self) {
counter!("failed_match", 1,
counter!("processing_error", 1,
"component_kind" => "transform",
"component_type" => "regex_parser",
"error_type" => "failed_match",
);
}
}
Expand All @@ -48,9 +49,10 @@ impl InternalEvent for RegexMissingField<'_> {
}

fn emit_metrics(&self) {
counter!("missing_field_error", 1,
counter!("processing_error", 1,
"component_kind" => "transform",
"component_type" => "regex_parser",
"error_type" => "missing_field",
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal_events/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ impl InternalEvent for SyslogEventReceived {
}

fn emit_metrics(&self) {
counter!("events_received", 1,
counter!("events_processed", 1,
"component_kind" => "source",
"component_type" => "syslog",
);
counter!("bytes_received", self.byte_size as u64,
counter!("bytes_processed", self.byte_size as u64,
"component_kind" => "source",
"component_kind" => "syslog",
);
Expand Down
8 changes: 4 additions & 4 deletions src/internal_events/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ impl InternalEvent for TcpEventSent {
}

fn emit_metrics(&self) {
counter!("tcp_events_sent", 1,
counter!("events_processed", 1,
"component_kind" => "sink",
);
counter!("tcp_bytes_sent", self.byte_size as u64,
counter!("bytes_processed", self.byte_size as u64,
"component_kind" => "sink",
);
}
Expand All @@ -121,12 +121,12 @@ impl InternalEvent for TcpEventReceived {
}

fn emit_metrics(&self) {
counter!("events_received", 1,
counter!("events_processed", 1,
"component_kind" => "source",
"component_type" => "socket",
"mode" => "tcp",
);
counter!("bytes_received", self.byte_size as u64,
counter!("bytes_processed", self.byte_size as u64,
"component_kind" => "source",
"component_type" => "socket",
"mode" => "tcp",
Expand Down
4 changes: 2 additions & 2 deletions src/internal_events/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ impl InternalEvent for UdpEventReceived {
}

fn emit_metrics(&self) {
counter!("events_received", 1,
counter!("events_processed", 1,
"component_kind" => "source",
"component_type" => "socket",
"mode" => "udp",
);
counter!("bytes_received", self.byte_size as u64,
counter!("bytes_processed", self.byte_size as u64,
"component_kind" => "source",
"component_type" => "socket",
"mode" => "udp",
Expand Down
12 changes: 8 additions & 4 deletions src/internal_events/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ pub struct UnixSocketEventSent {

impl InternalEvent for UnixSocketEventSent {
fn emit_metrics(&self) {
counter!("unix_socket_events_sent", 1,
counter!("events_processed", 1,
"component_kind" => "sink",
"component_type" => "socket",
"mode" => "unix",
);
counter!("unix_socket_bytes_sent", self.byte_size as u64,
counter!("bytes_processed", self.byte_size as u64,
"component_kind" => "sink",
"component_type" => "socket",
"mode" => "unix",
);
}
}
Expand All @@ -87,12 +91,12 @@ impl InternalEvent for UnixSocketEventReceived {
}

fn emit_metrics(&self) {
counter!("events_received", 1,
counter!("events_processed", 1,
"component_kind" => "source",
"component_type" => "socket",
"mode" => "unix",
);
counter!("bytes_received", self.byte_size as u64,
counter!("bytes_processed", self.byte_size as u64,
"component_kind" => "source",
"component_type" => "socket",
"mode" => "unix",
Expand Down
8 changes: 4 additions & 4 deletions src/internal_events/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pub struct VectorEventSent {
impl InternalEvent for VectorEventSent {
fn emit_metrics(&self) {
counter!(
"events_sent", 1,
"events_processed", 1,
"component_kind" => "sink",
"component_type" => "vector",
);
counter!(
"bytes_sent", self.byte_size as u64,
"bytes_processed", self.byte_size as u64,
"component_kind" => "sink",
"component_type" => "vector",
);
Expand All @@ -34,12 +34,12 @@ impl InternalEvent for VectorEventReceived {

fn emit_metrics(&self) {
counter!(
"events_received", 1,
"events_processed", 1,
"component_kind" => "sink",
"component_type" => "vector",
);
counter!(
"bytes_received", self.byte_size as u64,
"bytes_processed", self.byte_size as u64,
"component_kind" => "source",
"component_type" => "vector",
);
Expand Down
6 changes: 1 addition & 5 deletions src/transforms/lua/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
};
use serde::{Deserialize, Serialize};
use snafu::{ResultExt, Snafu};
use std::time::Instant;

#[derive(Debug, Snafu)]
enum BuildError {
Expand Down Expand Up @@ -102,7 +101,6 @@ impl Lua {
}

fn process(&mut self, event: Event) -> Result<Option<Event>, rlua::Error> {
let start = Instant::now();
let result = self.lua.context(|ctx| {
let globals = ctx.globals();

Expand All @@ -124,9 +122,7 @@ impl Lua {
self.invocations_after_gc = 0;
}

emit!(LuaEventProcessed {
duration: Instant::now() - start
});
emit!(LuaEventProcessed);

result
}
Expand Down

0 comments on commit 42c9987

Please sign in to comment.