maybe im stupid...
This commit is contained in:
parent
62a934fc20
commit
c780932300
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1143,7 +1143,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "homekit-exporter"
|
||||
version = "0.5.5"
|
||||
version = "0.5.6"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"env_logger",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "homekit-exporter"
|
||||
version = "0.5.5"
|
||||
version = "0.5.6"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
description = "Prometheus exporter for HomeKit sensors"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Maintainer: Alex Janka <alex@alexjanka.com>
|
||||
|
||||
pkgname=homekit-logger
|
||||
pkgver=0.5.5
|
||||
pkgver=0.5.6
|
||||
pkgrel=1
|
||||
pkgdesc="Prometheus exporter for HomeKit sensors"
|
||||
arch=('x86_64' 'aarch64')
|
||||
|
|
|
@ -20,24 +20,26 @@ pub async fn metrics(state: &State<Mutex<HashMap<String, DeviceConnection>>>) ->
|
|||
let mut state = state.lock().await;
|
||||
let mut set = JoinSet::new();
|
||||
for (name, mut connected) in state.drain() {
|
||||
set.spawn(
|
||||
async move {
|
||||
set.spawn(async move {
|
||||
let mut return_string = String::new();
|
||||
let mut types_seen = Vec::new();
|
||||
|
||||
connected.update_characteristics().await.ok()?;
|
||||
if let Err(e) = connected.update_characteristics().await {
|
||||
log::error!("updating characteristics for {name}: error {e:?}");
|
||||
return (name, connected, None);
|
||||
}
|
||||
|
||||
for (aid, accessory) in &connected.accessories {
|
||||
for service in accessory.services.values() {
|
||||
for (cid, characteristic) in &service.characteristics {
|
||||
if !MONITORED_CHARACTERISTICS.contains(&characteristic.characteristic_type) {
|
||||
if !MONITORED_CHARACTERISTICS.contains(&characteristic.characteristic_type)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if let Some(value) = &characteristic.value {
|
||||
if !types_seen.contains(&characteristic.characteristic_type) {
|
||||
types_seen.push(characteristic.characteristic_type);
|
||||
}
|
||||
|
||||
return_string.push_str(format!(
|
||||
"{}{{hub=\"{}\",service_type=\"{}\",accessory_name=\"{}\",accessory=\"{}.{}\",service=\"{}.{}.{}\"}} {}\n",
|
||||
characteristic.characteristic_type,
|
||||
|
@ -67,16 +69,16 @@ pub async fn metrics(state: &State<Mutex<HashMap<String, DeviceConnection>>>) ->
|
|||
}
|
||||
}
|
||||
|
||||
Some((name,connected,return_string,types_seen))
|
||||
}
|
||||
);
|
||||
(name, connected, Some((return_string, types_seen)))
|
||||
});
|
||||
}
|
||||
|
||||
let mut types_string = String::new();
|
||||
let mut values_string = String::new();
|
||||
let mut shown_types = Vec::new();
|
||||
while let Some(Ok(Some((k, v, metrics, types)))) = set.join_next().await {
|
||||
while let Some(Ok((k, v, val))) = set.join_next().await {
|
||||
state.insert(k, v);
|
||||
if let Some((metrics, types)) = val {
|
||||
for c in types {
|
||||
if !shown_types.contains(&c) {
|
||||
types_string.push_str(format!("# TYPE {} gauge\n", c).as_str());
|
||||
|
@ -85,6 +87,7 @@ pub async fn metrics(state: &State<Mutex<HashMap<String, DeviceConnection>>>) ->
|
|||
}
|
||||
values_string.push_str(&metrics);
|
||||
}
|
||||
}
|
||||
|
||||
Some(format!("{types_string}{values_string}"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue