Skip to content

Commit 3168347

Browse files
committed
New env var to customize configuration.
Code taken from iamseth#51
1 parent 3fcb21f commit 3168347

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

main.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import (
2626
var (
2727
// Version will be set at build time.
2828
Version = "0.0.0.dev"
29-
listenAddress = flag.String("web.listen-address", ":9161", "Address to listen on for web interface and telemetry.")
30-
metricPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
29+
listenAddress = flag.String("web.listen-address", getEnv("LISTEN_ADDRESS", ":9161"), "Address to listen on for web interface and telemetry. (env: LISTEN_ADDRESS)")
30+
metricPath = flag.String("web.telemetry-path", getEnv("TELEMETRY_PATH", "/metrics"), "Path under which to expose metrics. (env: TELEMETRY_PATH)")
3131
landingPage = []byte("<html><head><title>Oracle DB Exporter " + Version + "</title></head><body><h1>Oracle DB Exporter " + Version + "</h1><p><a href='" + *metricPath + "'>Metrics</a></p></body></html>")
32-
defaultFileMetrics = flag.String("default.metrics", "default-metrics.toml", "File with default metrics in a TOML file.")
33-
customMetrics = flag.String("custom.metrics", os.Getenv("CUSTOM_METRICS"), "File that may contain various custom metrics in a TOML file.")
34-
queryTimeout = flag.String("query.timeout", "5", "Query timeout (in seconds).")
32+
defaultFileMetrics = flag.String("default.metrics", getEnv("DEFAULT_METRICS", "default-metrics.toml"), "File with default metrics in a TOML file. (env: DEFAULT_METRICS)")
33+
customMetrics = flag.String("custom.metrics", getEnv("CUSTOM_METRICS", ""), "File that may contain various custom metrics in a TOML file. (env: CUSTOM_METRICS)")
34+
queryTimeout = flag.String("query.timeout", getEnv("QUERY_TIMEOUT", "5"), "Query timeout (in seconds). (env: QUERY_TIMEOUT)")
3535
)
3636

3737
// Metric name parts.
@@ -73,6 +73,14 @@ type Exporter struct {
7373

7474
}
7575

76+
// getEnv returns the value of an environment variable, or returns the provided fallback value
77+
func getEnv(key, fallback string) string {
78+
if value, ok := os.LookupEnv(key); ok {
79+
return value
80+
}
81+
return fallback
82+
}
83+
7684
// NewExporter returns a new Oracle DB exporter for the provided DSN.
7785
func NewExporter(dsn string) *Exporter {
7886
db, err := sql.Open("oci8", dsn)

0 commit comments

Comments
 (0)