add ability to specify exporter IP address

This commit is contained in:
Konstantin Zamyakin 2019-09-27 00:44:48 +03:00
parent eb03a6f1f2
commit 2a91bc5332
2 changed files with 18 additions and 8 deletions

View File

@ -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.

View File

@ -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))