Skip to content

Commit

Permalink
Avoid duplicate ts metrics from the same sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
jaseemabid committed Sep 10, 2023
1 parent 8a9099c commit 800d56d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ lazy_static! {
&["manufacturername", "modelid", "name", "swversion", "type"]).unwrap();

static ref LASTUPDATED: GaugeVec = GaugeVec::new(opts!("sensor_last_updated_ms", "Duration since the sensor was last updated in ms"),
&["manufacturername", "modelid", "name", "swversion", "type"]).unwrap();
&["manufacturername", "modelid", "name", "swversion"]).unwrap();

static ref LASTSEEN: GaugeVec = GaugeVec::new(opts!("sensor_last_seen_ms", "Duration since the sensor was last seen in ms"),
&["manufacturername", "modelid", "name", "swversion", "type"]).unwrap();
&["manufacturername", "modelid", "name", "swversion"]).unwrap();

}

Expand Down Expand Up @@ -241,7 +241,7 @@ fn process(e: &mut Event, state: &mut State) -> Result<(), Box<dyn Error>> {
state.sensors.insert(e.id.to_string(), attr.clone());

LASTSEEN
.with(&attr.labels(true))
.with(&attr.labels(false))
.set(attr.lastseen.timestamp_millis() as f64);

return Ok(());
Expand All @@ -256,7 +256,7 @@ fn process(e: &mut Event, state: &mut State) -> Result<(), Box<dyn Error>> {
debug!("Update state for sensor '{}': {:?}", sensor.name, change);


LASTUPDATED.with(&sensor.labels(true))
LASTUPDATED.with(&sensor.labels(false))
.set(change.lastupdated.timestamp_millis() as f64);

if let Some(p) = change.pressure {
Expand Down

0 comments on commit 800d56d

Please sign in to comment.