kevin
kevin

Reputation: 193

Prometheus Operator change the scrape_interval

I want to set scrape_interval for the Prometheus to 15 seconds. My config below doesn't work, there is an error in the last line. I am wondering how should I config the 15 seconds scrape_interval?

apiVersion: monitoring.coreos.com/v1
    kind: Prometheus
    metadata:
      name: main
    spec:
      serviceAccountName: prometheus
      replicas: 1
      version: v1.7.1
      serviceMonitorNamespaceSelector: {}
      serviceMonitorSelector:
        matchLabels:
          team: frontend
      ruleSelector:
        matchLabels:
          role: alert-rules
          prometheus: rules
      resources:
        requests:
          memory: 400Mi
    scrape_interval: 15s  ##Error in this line.

I got this error message when compiling the config above:

error: error validating "promethus.yml": error validating data: ValidationError(Prometheus): unknown field "scrape_interval" in com.coreos.monitoring.v1.Prometheus; if you choose to ignore these errors, turn validation off with --validate=false

Thanks!

Upvotes: 4

Views: 7546

Answers (2)

Wytrzymały Wiktor
Wytrzymały Wiktor

Reputation: 13878

scrape_interval should go under the global Prometheus configuration:

Prometheus configuration is YAML. The Prometheus download comes with a sample configuration in a file called prometheus.yml that is a good place to get started.

Here is an example of a valid configuration YAML. Please notice:

# my global config
global:
  scrape_interval:     15s
  evaluation_interval: 30s
  # scrape_timeout is set to the global default (10s).

Your file named "promethus.yml" with apiVersion: monitoring.coreos.com/v1 is not the same as the config file prometheus.yml I mentioned above and so, adding the scrape_interval to it would result in a validation error. You cannot mix Prometheus configs with Prometheus Operator's ones. These are different concepts.

I also recommend going through the official guide to get a better grip of the Prometheus and it's configuration options. Or stick with the Prometheus Operator.

Upvotes: 0

bjakubski
bjakubski

Reputation: 1747

scrape_interval is probably a parameter name in the prometheus config and not for the Prometheus object in k8s (which is read by prometheus-operator and used to generate actual config).

You can see in the prometheus operator documentation that the parameter you are looking for is scrapeInterval. Ensure correct indentation, this is supposed to be part of spec:.

Note that you do not have to change scrape interval globally. You can have per scrape target intervals defined in your ServiceMonitor objects.

Upvotes: 1

Related Questions