Merge pull request #15 from sc0rp10/master
add ability to specify exporter IP address
This commit is contained in:
commit
1bd6a74e3c
@ -47,6 +47,7 @@ Start the binary with `-h` to get the complete syntax. The parameters are:
|
||||
| Parameter | Mandatory | Valid values | Default | Description |
|
||||
| -- | -- | -- | -- | -- |
|
||||
| `-v` | no | <switch> | | Enable verbose mode.
|
||||
| `-p` | no | any valid ip address | 127.0.0.1 | Specify the service address. This is the address your Prometheus instance should point to.
|
||||
| `-p` | no | any valid port number | 9586 | Specify the service port. This is the port your Prometheus instance should point to.
|
||||
| `-n` | no | path to the wireguard configuration file | | This flag adds the *friendly_name* attribute to the exported entries. See [Friendly names](#friendly-names) for more details.
|
||||
| `-s` | no | <switch> | off | Enable the allowed ip + subnet split mode for the labels.
|
||||
|
13
src/main.rs
13
src/main.rs
@ -21,6 +21,7 @@ extern crate prometheus_exporter_base;
|
||||
use crate::exporter_error::ExporterError;
|
||||
use prometheus_exporter_base::render_prometheus;
|
||||
use std::sync::Arc;
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
fn wg_with_text(
|
||||
wg_config_str: &str,
|
||||
@ -89,6 +90,13 @@ fn main() {
|
||||
let matches = clap::App::new(crate_name!())
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!("\n"))
|
||||
.arg(
|
||||
Arg::with_name("addr")
|
||||
.short("l")
|
||||
.help("exporter address")
|
||||
.default_value("127.0.0.1")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("port")
|
||||
.short("p")
|
||||
@ -140,9 +148,10 @@ fn main() {
|
||||
|
||||
let bind = matches.value_of("port").unwrap();
|
||||
let bind = u16::from_str_radix(&bind, 10).expect("port must be a valid number");
|
||||
let addr = ([0, 0, 0, 0], bind).into();
|
||||
let ip = matches.value_of("addr").unwrap().parse::<Ipv4Addr>().unwrap();
|
||||
let addr = (ip, bind).into();
|
||||
|
||||
info!("starting exporter on {}", addr);
|
||||
info!("starting exporter on http://{}/metrics", addr);
|
||||
|
||||
render_prometheus(&addr, options, |request, options| {
|
||||
Box::new(perform_request(request, options))
|
||||
|
Loading…
Reference in New Issue
Block a user