Merge pull request #68 from dmaganto/feature/tls_metrics_support
Add TLS support for metrics
This commit is contained in:
commit
f54aa70c5f
25
README.md
25
README.md
|
@ -83,6 +83,31 @@ $ docker run --rm -it -p 9090:9090 -v $PWD/examples/prometheus.yml:/etc/promethe
|
|||
```
|
||||
Then head over to http://localhost:9090/graph?g0.range_input=1h&g0.expr=example_value_active&g0.tab=1 or http://localhost:9090/targets to check the scraped metrics or the targets.
|
||||
|
||||
# Exposing metrics through HTTPS
|
||||
|
||||
web-config.yml
|
||||
```
|
||||
# Minimal TLS configuration example. Additionally, a certificate and a key file
|
||||
# are needed.
|
||||
tls_server_config:
|
||||
cert_file: server.crt
|
||||
key_file: server.key
|
||||
```
|
||||
Running
|
||||
```
|
||||
$ ./json_exporter --config.file examples/config.yml --web.config=web-config.yml &
|
||||
|
||||
$ curl -k "https://localhost:7979/probe?target=http://localhost:8000/examples/data.json" | grep ^example
|
||||
example_global_value{environment="beta",location="mars"} 1234
|
||||
example_value_active{environment="beta",id="id-A"} 1
|
||||
example_value_active{environment="beta",id="id-C"} 1
|
||||
example_value_boolean{environment="beta",id="id-A"} 1
|
||||
example_value_boolean{environment="beta",id="id-C"} 0
|
||||
example_value_count{environment="beta",id="id-A"} 1
|
||||
example_value_count{environment="beta",id="id-C"} 3
|
||||
```
|
||||
For futher information about TLS configuration, please visit: [exporter-toolkit/https](https://github.com/prometheus/exporter-toolkit/blob/v0.1.0/https/README.md)
|
||||
|
||||
# Docker
|
||||
|
||||
```console
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/prometheus/common/promlog"
|
||||
"github.com/prometheus/common/promlog/flag"
|
||||
"github.com/prometheus/common/version"
|
||||
"github.com/prometheus/exporter-toolkit/https"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
|
@ -35,6 +36,7 @@ var (
|
|||
configFile = kingpin.Flag("config.file", "JSON exporter configuration file.").Default("config.yml").ExistingFile()
|
||||
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests.").Default(":7979").String()
|
||||
configCheck = kingpin.Flag("config.check", "If true validate the config file and then exit.").Default("false").Bool()
|
||||
tlsConfigFile = kingpin.Flag("web.config", "[EXPERIMENTAL] Path to config yaml file that can enable TLS or authentication.").Default("").String()
|
||||
)
|
||||
|
||||
func Run() {
|
||||
|
@ -70,8 +72,11 @@ func Run() {
|
|||
http.HandleFunc("/probe", func(w http.ResponseWriter, req *http.Request) {
|
||||
probeHandler(w, req, logger, config)
|
||||
})
|
||||
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
|
||||
|
||||
server := &http.Server{Addr: *listenAddress}
|
||||
if err := https.Listen(server, *tlsConfigFile, logger); err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to start the server", "err", err) //nolint:errcheck
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
go.mod
3
go.mod
|
@ -6,7 +6,8 @@ require (
|
|||
github.com/go-kit/kit v0.10.0
|
||||
github.com/kawamuray/jsonpath v0.0.0-20160208140654-5c448ebf9735
|
||||
github.com/prometheus/client_golang v1.8.0
|
||||
github.com/prometheus/common v0.14.0
|
||||
github.com/prometheus/common v0.15.0
|
||||
github.com/prometheus/exporter-toolkit v0.0.0-20201116090157-62b2456fb703
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
)
|
||||
|
|
6
go.sum
6
go.sum
|
@ -243,6 +243,10 @@ github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lN
|
|||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||
github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4=
|
||||
github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
|
||||
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||
github.com/prometheus/exporter-toolkit v0.0.0-20201116090157-62b2456fb703 h1:aonobVNFgXD77IIy3sGiHc6AyvlSIcfZqv/SNADLWH8=
|
||||
github.com/prometheus/exporter-toolkit v0.0.0-20201116090157-62b2456fb703/go.mod h1:fMnwTJue5eYJ9Dw45pxgU/wG1cTBeX/YN5appV2zTD0=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
|
@ -301,6 +305,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9 h1:umElSU9WZirRdgu2yFHY0ayQkEnKiOC1TtM3fWXFnoU=
|
||||
golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
|
|
Loading…
Reference in New Issue