Extract file IO from mutex lock zone.
This commit is contained in:
parent
a22dec763c
commit
4cf347c5eb
15
main.rs
15
main.rs
|
@ -33,19 +33,20 @@ fn main() -> std::io::Result<()> {
|
||||||
let thread_metrics = metrics.clone();
|
let thread_metrics = metrics.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let filepath = prometheus_file_path.to_owned();
|
let filepath = prometheus_file_path.to_owned();
|
||||||
|
let mut prom_str: String = "".to_owned();
|
||||||
loop {
|
loop {
|
||||||
{
|
{
|
||||||
match File::create(&filepath) {
|
match File::create(&filepath) {
|
||||||
Ok(mut file) => {
|
Ok(mut file) => {
|
||||||
if let Ok(m) = thread_metrics.lock() {
|
if let Ok(m) = thread_metrics.lock() {
|
||||||
let prom_str = format!("officetemp_humidity {}\nofficetemp_temperature {}\n", m.humidity, m.temperature);
|
prom_str = format!("officetemp_humidity {}\nofficetemp_temperature {}\n", m.humidity, m.temperature);
|
||||||
match file.write_all(prom_str.as_bytes()) {
|
|
||||||
Ok(()) => (),
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Cannot write to {}: {}", prometheus_file_path, err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
match file.write_all((&prom_str).as_bytes()) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Cannot write to {}: {}", prometheus_file_path, err);
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Cannot write to {}: {}", prometheus_file_path, err);
|
eprintln!("Cannot write to {}: {}", prometheus_file_path, err);
|
||||||
|
|
Loading…
Reference in a new issue