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]]
|
[[package]]
|
||||||
name = "homekit-exporter"
|
name = "homekit-exporter"
|
||||||
version = "0.5.5"
|
version = "0.5.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "homekit-exporter"
|
name = "homekit-exporter"
|
||||||
version = "0.5.5"
|
version = "0.5.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
description = "Prometheus exporter for HomeKit sensors"
|
description = "Prometheus exporter for HomeKit sensors"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Maintainer: Alex Janka <alex@alexjanka.com>
|
# Maintainer: Alex Janka <alex@alexjanka.com>
|
||||||
|
|
||||||
pkgname=homekit-logger
|
pkgname=homekit-logger
|
||||||
pkgver=0.5.5
|
pkgver=0.5.6
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Prometheus exporter for HomeKit sensors"
|
pkgdesc="Prometheus exporter for HomeKit sensors"
|
||||||
arch=('x86_64' 'aarch64')
|
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 state = state.lock().await;
|
||||||
let mut set = JoinSet::new();
|
let mut set = JoinSet::new();
|
||||||
for (name, mut connected) in state.drain() {
|
for (name, mut connected) in state.drain() {
|
||||||
set.spawn(
|
set.spawn(async move {
|
||||||
async move {
|
|
||||||
let mut return_string = String::new();
|
let mut return_string = String::new();
|
||||||
let mut types_seen = Vec::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 (aid, accessory) in &connected.accessories {
|
||||||
for service in accessory.services.values() {
|
for service in accessory.services.values() {
|
||||||
for (cid, characteristic) in &service.characteristics {
|
for (cid, characteristic) in &service.characteristics {
|
||||||
if !MONITORED_CHARACTERISTICS.contains(&characteristic.characteristic_type) {
|
if !MONITORED_CHARACTERISTICS.contains(&characteristic.characteristic_type)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(value) = &characteristic.value {
|
if let Some(value) = &characteristic.value {
|
||||||
if !types_seen.contains(&characteristic.characteristic_type) {
|
if !types_seen.contains(&characteristic.characteristic_type) {
|
||||||
types_seen.push(characteristic.characteristic_type);
|
types_seen.push(characteristic.characteristic_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return_string.push_str(format!(
|
return_string.push_str(format!(
|
||||||
"{}{{hub=\"{}\",service_type=\"{}\",accessory_name=\"{}\",accessory=\"{}.{}\",service=\"{}.{}.{}\"}} {}\n",
|
"{}{{hub=\"{}\",service_type=\"{}\",accessory_name=\"{}\",accessory=\"{}.{}\",service=\"{}.{}.{}\"}} {}\n",
|
||||||
characteristic.characteristic_type,
|
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 types_string = String::new();
|
||||||
let mut values_string = String::new();
|
let mut values_string = String::new();
|
||||||
let mut shown_types = Vec::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);
|
state.insert(k, v);
|
||||||
|
if let Some((metrics, types)) = val {
|
||||||
for c in types {
|
for c in types {
|
||||||
if !shown_types.contains(&c) {
|
if !shown_types.contains(&c) {
|
||||||
types_string.push_str(format!("# TYPE {} gauge\n", c).as_str());
|
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);
|
values_string.push_str(&metrics);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Some(format!("{types_string}{values_string}"))
|
Some(format!("{types_string}{values_string}"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue