|
@@ -377,10 +377,25 @@ func NewMetricsCmd() *cobra.Command {
|
|
|
Long: `Fetch metrics from the prometheus server and display them in a human-friendly way`,
|
|
|
Args: cobra.ExactArgs(0),
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ if !csConfig.Prometheus.Enabled {
|
|
|
+ log.Warningf("Prometheus is not enabled, can't show metrics")
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ if csConfig.Prometheus.ListenAddr == "" || csConfig.Prometheus.ListenPort == 0 {
|
|
|
+ log.Warningf("No prometheus address or port specified in '%s', can't show metrics", *csConfig.Self)
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ if prometheusURL == "" {
|
|
|
+ log.Debugf("No prometheus URL provided using: %s:%d", csConfig.Prometheus.ListenAddr, csConfig.Prometheus.ListenPort)
|
|
|
+ prometheusURL = fmt.Sprintf("http://%s:%d/metrics", csConfig.Prometheus.ListenAddr, csConfig.Prometheus.ListenPort)
|
|
|
+ }
|
|
|
+
|
|
|
ShowPrometheus(prometheusURL)
|
|
|
},
|
|
|
}
|
|
|
- cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "http://127.0.0.1:6060/metrics", "Prometheus url")
|
|
|
+ cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "", "Prometheus url (http://<ip>:<port>/metrics)")
|
|
|
|
|
|
return cmdMetrics
|
|
|
}
|