Retrieve config information from environment variables
This commit is contained in:
parent
11b8bfd57c
commit
252d8b9da1
1 changed files with 21 additions and 0 deletions
|
@ -14,11 +14,13 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/hipages/php-fpm_exporter/phpfpm"
|
"github.com/hipages/php-fpm_exporter/phpfpm"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configuration variables
|
// Configuration variables
|
||||||
|
@ -82,4 +84,23 @@ func init() {
|
||||||
serverCmd.Flags().StringSliceVar(&scrapeURIs, "phpfpm.scrape-uri", []string{"tcp://127.0.0.1:9000/status"}, "FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status")
|
serverCmd.Flags().StringSliceVar(&scrapeURIs, "phpfpm.scrape-uri", []string{"tcp://127.0.0.1:9000/status"}, "FastCGI address, e.g. unix:///tmp/php.sock;/status or tcp://127.0.0.1:9000/status")
|
||||||
serverCmd.Flags().StringSliceVar(&customLabelNames, "phpfpm.label-name", []string{}, "Name of the custom label that will be inserted.")
|
serverCmd.Flags().StringSliceVar(&customLabelNames, "phpfpm.label-name", []string{}, "Name of the custom label that will be inserted.")
|
||||||
serverCmd.Flags().StringSliceVar(&customLabelValues, "phpfpm.label-value", []string{}, "Value of the custom label that will be inserted.")
|
serverCmd.Flags().StringSliceVar(&customLabelValues, "phpfpm.label-value", []string{}, "Value of the custom label that will be inserted.")
|
||||||
|
|
||||||
|
//viper.BindEnv("web.listen-address", "PHP_FPM_WEB_LISTEN_ADDRESS")
|
||||||
|
//viper.BindPFlag("web.listen-address", serverCmd.Flags().Lookup("web.listen-address"))
|
||||||
|
|
||||||
|
// Workaround since vipers BindEnv is currently not working as expected (see https://github.com/spf13/viper/issues/461)
|
||||||
|
|
||||||
|
envs := map[string]string{
|
||||||
|
"PHP_FPM_WEB_LISTEN_ADDRESS": "web.listen-address",
|
||||||
|
"PHP_FPM_WEB_TELEMETRY_PATH": "web.telemetry-path",
|
||||||
|
"PHP_FPM_SCRAPE_URI": "phpfpm.scrape-uri",
|
||||||
|
}
|
||||||
|
|
||||||
|
for env, flag := range envs {
|
||||||
|
flag := serverCmd.Flags().Lookup(flag)
|
||||||
|
flag.Usage = fmt.Sprintf("%v [env %v]", flag.Usage, env)
|
||||||
|
if value := os.Getenv(env); value != "" {
|
||||||
|
flag.Value.Set(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue