Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the flags configurable using environment variables #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[[constraint]]
name = "github.com/peterbourgon/ff"
version = "1.2.0"
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,34 @@ To run it:
./clickhouse_exporter [flags]
```

Help on flags:
Flags are also configurable using environment variables. See the usage with:

```bash
./clickhouse_exporter --help
```

Credentials(if not default):

via environment variables
```
CLICKHOUSE_USER
CLICKHOUSE_PASSWORD
Usage of clickhouse-exporter:
-insecure
Ignore server certificate if using https. Override environment (CLICKHOUSE_INSECURE) (default true)
-password string
Clickhouse password. Override environment (CLICKHOUSE_PASSWORD)
-scrape_uri string
URI to clickhouse http endpoint. Override environment (CLICKHOUSE_SCRAPE_URI) (default "http://localhost:8123/")
-telemetry.address string
Address on which to expose metrics. Override environment (CLICKHOUSE_TELEMETRY_ADDRESS) (default ":9116")
-telemetry.endpoint string
Path under which to expose metrics. Override environment (CLICKHOUSE_TELEMETRY_ENDPOINT) (default "/metrics")
-user string
Clickhouse user. Override environment (CLICKHOUSE_USER)
```

## Using Docker

```
docker run -d -p 9116:9116 f1yegor/clickhouse-exporter -scrape_uri=http://clickhouse.service.consul:8123/
```

## Sample dashboard

Grafana dashboard could be a start for inspiration https://grafana.net/dashboards/882
22 changes: 13 additions & 9 deletions clickhouse_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ import (
"os"

"github.com/f1yegor/clickhouse_exporter/exporter"
"github.com/peterbourgon/ff"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/log"
)

var (
listeningAddress = flag.String("telemetry.address", ":9116", "Address on which to expose metrics.")
metricsEndpoint = flag.String("telemetry.endpoint", "/metrics", "Path under which to expose metrics.")
clickhouseScrapeURI = flag.String("scrape_uri", "http://localhost:8123/", "URI to clickhouse http endpoint")
insecure = flag.Bool("insecure", true, "Ignore server certificate if using https")
user = os.Getenv("CLICKHOUSE_USER")
password = os.Getenv("CLICKHOUSE_PASSWORD")
fs = flag.NewFlagSet("clickhouse-exporter", flag.ExitOnError)
listeningAddress = fs.String("telemetry.address", ":9116", "Address on which to expose metrics. Override environment (CLICKHOUSE_TELEMETRY_ADDRESS)")
metricsEndpoint = fs.String("telemetry.endpoint", "/metrics", "Path under which to expose metrics. Override environment (CLICKHOUSE_TELEMETRY_ENDPOINT)")
clickhouseScrapeURI = fs.String("scrape_uri", "http://localhost:8123/", "URI to clickhouse http endpoint. Override environment (CLICKHOUSE_SCRAPE_URI)")
insecure = fs.Bool("insecure", true, "Ignore server certificate if using https. Override environment (CLICKHOUSE_INSECURE)")
user = fs.String("user", "", "Clickhouse user. Override environment (CLICKHOUSE_USER)")
password = fs.String("password", "", "Clickhouse password. Override environment (CLICKHOUSE_PASSWORD)")
)

func main() {
flag.Parse()
if err := ff.Parse(fs, os.Args[1:], ff.WithEnvVarPrefix("CLICKHOUSE")); err != nil {
panic(err)
}

uri, err := url.Parse(*clickhouseScrapeURI)
if err != nil {
log.Fatal(err)
}
e := exporter.NewExporter(*uri, *insecure, user, password)
e := exporter.NewExporter(*uri, *insecure, *user, *password)
prometheus.MustRegister(e)

log.Printf("Starting Server: %s", *listeningAddress)
Expand Down
14 changes: 14 additions & 0 deletions vendor/github.com/peterbourgon/ff/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/peterbourgon/ff/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading