Open kaspar030 opened 1 year ago
You should be able to do something like this with just a u64
:
#[derive(Serialize)]
pub struct Metrics {
#[serde(serialize_with = "serialize_timestamp")]
timestamp: DateTime<Utc>,
}
fn serialize_timestamp<S: Serialize>(serializer: S, val: &S) -> Result<S::Ok, S::Error> {
timestamp.as_u64().serialize(serializer)
}
I'm re-exporting an external metric (the watt minutes total of a shelly plug s'
/status
json. There's a timestamp for that metric in the json.I'd like to be able to get that explicit timestamp into the generated prometheus string.
Is there a way to do this with serde_prometheus that I didn't find? If not, would that be hard to add?