snarkos_metrics/lib.rs
1// Copyright (C) 2019-2022 Aleo Systems Inc.
2// This file is part of the snarkOS library.
3
4// The snarkOS library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkOS library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.
16
17// Re-export the metrics macros.
18pub use metrics::*;
19
20use metrics_exporter_prometheus::PrometheusBuilder;
21
22pub fn initialize() -> Option<tokio::task::JoinHandle<()>> {
23 let (recorder, exporter) = PrometheusBuilder::new().build().expect("can't build the prometheus exporter");
24
25 metrics::set_boxed_recorder(Box::new(recorder)).expect("can't set the prometheus exporter");
26
27 let metrics_exporter_task = tokio::task::spawn(async move {
28 exporter.await.expect("can't await the prometheus exporter");
29 });
30
31 Some(metrics_exporter_task)
32}