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,70 +20,73 @@ 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 {
|
||||
let mut return_string = String::new();
|
||||
let mut types_seen = Vec::new();
|
||||
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) {
|
||||
continue;
|
||||
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)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if let Some(value) = &characteristic.value {
|
||||
if !types_seen.contains(&characteristic.characteristic_type) {
|
||||
types_seen.push(characteristic.characteristic_type);
|
||||
}
|
||||
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,
|
||||
name,
|
||||
service.service_type,
|
||||
accessory.name,
|
||||
name,
|
||||
aid,
|
||||
name,
|
||||
aid,
|
||||
cid,
|
||||
match value {
|
||||
Data::Bool(v) => format!("{}", if *v { 1 } else { 0 }),
|
||||
Data::Uint8(v) => format!("{v}"),
|
||||
Data::Uint16(v) => format!("{v}"),
|
||||
Data::Uint32(v) => format!("{v}"),
|
||||
Data::Uint64(v) => format!("{v}"),
|
||||
Data::Int(v) => format!("{v}"),
|
||||
Data::Float(v) => format!("{v}"),
|
||||
Data::String(v) => v.to_string(),
|
||||
Data::Tlv8(v) => v.to_string(),
|
||||
Data::Data(v) => v.to_string(),
|
||||
}
|
||||
|
||||
return_string.push_str(format!(
|
||||
"{}{{hub=\"{}\",service_type=\"{}\",accessory_name=\"{}\",accessory=\"{}.{}\",service=\"{}.{}.{}\"}} {}\n",
|
||||
characteristic.characteristic_type,
|
||||
name,
|
||||
service.service_type,
|
||||
accessory.name,
|
||||
name,
|
||||
aid,
|
||||
name,
|
||||
aid,
|
||||
cid,
|
||||
match value {
|
||||
Data::Bool(v) => format!("{}", if *v { 1 } else { 0 }),
|
||||
Data::Uint8(v) => format!("{v}"),
|
||||
Data::Uint16(v) => format!("{v}"),
|
||||
Data::Uint32(v) => format!("{v}"),
|
||||
Data::Uint64(v) => format!("{v}"),
|
||||
Data::Int(v) => format!("{v}"),
|
||||
Data::Float(v) => format!("{v}"),
|
||||
Data::String(v) => v.to_string(),
|
||||
Data::Tlv8(v) => v.to_string(),
|
||||
Data::Data(v) => v.to_string(),
|
||||
}
|
||||
).as_str());
|
||||
}
|
||||
).as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
for c in types {
|
||||
if !shown_types.contains(&c) {
|
||||
types_string.push_str(format!("# TYPE {} gauge\n", c).as_str());
|
||||
shown_types.push(c);
|
||||
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());
|
||||
shown_types.push(c);
|
||||
}
|
||||
}
|
||||
values_string.push_str(&metrics);
|
||||
}
|
||||
values_string.push_str(&metrics);
|
||||
}
|
||||
|
||||
Some(format!("{types_string}{values_string}"))
|
||||
|
|
Loading…
Reference in a new issue