add a prometheus_uri option for cscli's config (#625)
* add a prometheus_uri option for cscli's config, and update documentation * specify min version
This commit is contained in:
parent
7f40160f6e
commit
7d93302e05
|
@ -382,17 +382,16 @@ func NewMetricsCmd() *cobra.Command {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if csConfig.Prometheus.ListenAddr == "" || csConfig.Prometheus.ListenPort == 0 {
|
if prometheusURL == "" {
|
||||||
log.Warningf("No prometheus address or port specified in '%s', can't show metrics", *csConfig.Self)
|
prometheusURL = csConfig.Cscli.PrometheusUrl
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if prometheusURL == "" {
|
if prometheusURL == "" {
|
||||||
log.Debugf("No prometheus URL provided using: %s:%d", csConfig.Prometheus.ListenAddr, csConfig.Prometheus.ListenPort)
|
log.Errorf("No prometheus url, please specify in %s or via -u", *csConfig.Self)
|
||||||
prometheusURL = fmt.Sprintf("http://%s:%d/metrics", csConfig.Prometheus.ListenAddr, csConfig.Prometheus.ListenPort)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowPrometheus(prometheusURL)
|
ShowPrometheus(prometheusURL + "/metrics")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "", "Prometheus url (http://<ip>:<port>/metrics)")
|
cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "", "Prometheus url (http://<ip>:<port>/metrics)")
|
||||||
|
|
|
@ -277,6 +277,7 @@ This section is only used by `cscli`.
|
||||||
cscli:
|
cscli:
|
||||||
output: (human|json|raw)
|
output: (human|json|raw)
|
||||||
hub_branch: <hub_branch>
|
hub_branch: <hub_branch>
|
||||||
|
prometheus_uri: <uri>
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `output`
|
#### `output`
|
||||||
|
@ -289,6 +290,11 @@ The default output format (human, json or raw).
|
||||||
|
|
||||||
The git branch on which `cscli` is going to fetch configurations.
|
The git branch on which `cscli` is going to fetch configurations.
|
||||||
|
|
||||||
|
#### `prometheus_uri`
|
||||||
|
> uri
|
||||||
|
|
||||||
|
(>1.0.7) An uri (without the trailing `/metrics`) that will be used by `cscli metrics` command, ie. `http://127.0.0.1:6060/`
|
||||||
|
|
||||||
## `db_config`
|
## `db_config`
|
||||||
|
|
||||||
Please refer to the [database configuration](/Crowdsec/v1/references/database).
|
Please refer to the [database configuration](/Crowdsec/v1/references/database).
|
||||||
|
|
|
@ -113,6 +113,13 @@ func (c *GlobalConfig) LoadConfiguration() error {
|
||||||
c.Cscli.DataDir = c.ConfigPaths.DataDir
|
c.Cscli.DataDir = c.ConfigPaths.DataDir
|
||||||
c.Cscli.HubDir = c.ConfigPaths.HubDir
|
c.Cscli.HubDir = c.ConfigPaths.HubDir
|
||||||
c.Cscli.HubIndexFile = c.ConfigPaths.HubIndexFile
|
c.Cscli.HubIndexFile = c.ConfigPaths.HubIndexFile
|
||||||
|
if c.Cscli.PrometheusUrl == "" {
|
||||||
|
port := 6060
|
||||||
|
if c.Prometheus.ListenPort != 0 {
|
||||||
|
port = c.Prometheus.ListenPort
|
||||||
|
}
|
||||||
|
c.Cscli.PrometheusUrl = fmt.Sprintf("http://127.0.0.1:%d/", port)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.API.Client != nil && c.API.Client.CredentialsFilePath != "" && !c.DisableAgent {
|
if c.API.Client != nil && c.API.Client.CredentialsFilePath != "" && !c.DisableAgent {
|
||||||
|
|
|
@ -11,4 +11,5 @@ type CscliCfg struct {
|
||||||
ConfigDir string `yaml:"-"`
|
ConfigDir string `yaml:"-"`
|
||||||
HubIndexFile string `yaml:"-"`
|
HubIndexFile string `yaml:"-"`
|
||||||
SimulationFilePath string `yaml:"-"`
|
SimulationFilePath string `yaml:"-"`
|
||||||
|
PrometheusUrl string `yaml:"prometheus_uri"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue