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:
Thibault "bui" Koechlin 2021-02-17 13:53:57 +01:00 committed by GitHub
parent 7f40160f6e
commit 7d93302e05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 6 deletions

View file

@ -382,17 +382,16 @@ func NewMetricsCmd() *cobra.Command {
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 == "" {
prometheusURL = csConfig.Cscli.PrometheusUrl
}
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)
log.Errorf("No prometheus url, please specify in %s or via -u", *csConfig.Self)
os.Exit(1)
}
ShowPrometheus(prometheusURL)
ShowPrometheus(prometheusURL + "/metrics")
},
}
cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "", "Prometheus url (http://<ip>:<port>/metrics)")

View file

@ -277,6 +277,7 @@ This section is only used by `cscli`.
cscli:
output: (human|json|raw)
hub_branch: <hub_branch>
prometheus_uri: <uri>
```
#### `output`
@ -289,6 +290,11 @@ The default output format (human, json or raw).
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`
Please refer to the [database configuration](/Crowdsec/v1/references/database).

View file

@ -113,6 +113,13 @@ func (c *GlobalConfig) LoadConfiguration() error {
c.Cscli.DataDir = c.ConfigPaths.DataDir
c.Cscli.HubDir = c.ConfigPaths.HubDir
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 {

View file

@ -11,4 +11,5 @@ type CscliCfg struct {
ConfigDir string `yaml:"-"`
HubIndexFile string `yaml:"-"`
SimulationFilePath string `yaml:"-"`
PrometheusUrl string `yaml:"prometheus_uri"`
}