- Default global scrape configuration
- Global scrape configuration
- Kubernetes annotations
- Job configuration
10s). You can override this interval by setting a scrape configuration,
adding an annotation to a Kubernetes object, or adding a job configuration.
Global scrape configuration
To apply those settings globally to all jobs, define the following default scrape configuration:scrape configuration to set options for your instance.
If you don’t specify a field, it uses the default values.
The Prometheus relabel_config
configuration applies to relabels and metricRelabels parameters. This configuration
allows for advanced modifications to any target and its labels before Collector
ingests metrics.
By default, scrapes request gzip compression by using the Accept-Encoding header.
This is configured by the enableCompression option.
Kubernetes annotations
You can use Kubernetes annotations to override any global defaults. Collector supports the following Prometheus annotations to enable scraping for a pod. By default,prometheus.io
prefixes each of these annotations, such as prometheus.io/scrape. You can
change the annotation prefix to a different value.
/scrape: Determines whether to enable scraping. Excludes scraping the pod if set tofalse./port: The port to scrape on the pod./path: The pod’s metrics path./params: HTTP URL parameters./scheme: The connection protocol, eitherhttporhttps./job: Overrides the value of thejoblabel./collectionInterval: Determines how often to scrape endpoints. Default:10s./collectionTimeout: The timeout for a scrape operation./serviceAccountBearerToken: The token value, if using service account authentication./httpProxyURL: The Proxy URL of connections to this pod./tlsServerName: The host name when using TLS authentication./tlsInsecureSkipVerify: Determines whether to verify a server’s certificate. Set totrueto avoid verifying the server’s certificate for validity.
files/env vars.
/httpBasicAuthUsernameEnvVar: TheUsernameenvironment variable when using basic authentication./httpBasicAuthPasswordEnvVar: ThePasswordenvironment variable when using basic authentication./httpBasicAuthPasswordFile: The path to a file containing a password when using basic authentication./httpBearerTokenEnvVar: TheTokenenvironment variable when using HTTP bearer token authentication./httpBearerTokenFile: The path to a file containing a bearer token when using HTTP bearer token authentication./tlsCAFile: The path to a CA certificate when using TLS authentication./tlsCertFile: The path to a personal certificate when using TLS authentication./tlsKeyFile: The path to a private key when using TLS authentication.
httpBasicAuthUsernameEnvVar and httpBasicAuthPasswordEnvVar annotations’ values:
Change annotation prefix
You can change the annotation prefix by setting the environment variableKUBERNETES_PROCESSOR_ANNOTATIONS_PREFIX as the value of the annotationsPrefix key
in the processor section of the kubernetes collection. The default value is
prometheus.io/.
If you modify a Collector manifest, you must
update it in the cluster and restart the Collector.
Scrape multiple ports
Theprometheus.io/port annotation can accept a comma-separated list of the ports
to scrape, such as prometheus.io/port: 1234,5678.
The endpoints must both use the same path. For example both ports 1234 and 5678
must expose Prometheus metrics on the /metrics path.
If you specify multiple ports, the pods must expose all ports in the list. The following
is an example of a container ports configuration in a pod manifest that exposes
both 1234 and 5678:
Define jobs configuration
When using annotations for scraping, you can configure the jobs collection to
override any of the defaults set in the global scrape configuration.
The following example contains the value types for the jobs collection:
The
name value must be unique across all scrape configurations, and must match the
job name set in the annotations. For example, prometheus.io/job.scrapeInterval to 1m and create a relabeling rule that
changes the name of the label code to status_code for the api job, add the
following configuration to the config.yml field of the chronocollector-config
ConfigMap:
If you modify a Collector manifest, you must
update it in the cluster and restart the Collector.
Differences between relabel and metricRelabels
A Prometheus relabel configuration defines the targets you want to scrape and
the target labels. Using relabel rewrites the label set of a target before it’s
scraped.
Collector applies metricRelabels after the scrape but before ingesting data. Use
metricRelabels if there are expensive metrics that you want to drop, or labels
coming from the scrape itself that you want to manipulate.
In this example, the relabel rule replaces the name of the label code to
status_code for the api job before scraping the metrics:
metricsRelabel rule replaces the pod and job labels for the
cadvisor job on promremotebench-0 to database:
Environment variable expansions and
Prometheus relabel rule regular expression capture group references can use the same syntax.
For example,
${1} is valid in both contexts.If your relabel configuration uses Prometheus relabel rule regular expression capture
group references, and they are in the ${1} format, escape the syntax by adding an
extra $ character to the expression such as $${1}.metricRelabels actions
The following actions are available for metricRelabels:
-
replace: Match a regular expression against the concatenatedsourceLabels. Then, settargetLabeltoreplacement, with match group references (such as${1}or${2}) in the replacement substituted by their value. If the regular expression doesn’t match, no replacement occurs. -
keep: Drop targets for which a regular expression doesn’t match the concatenatedsourceLabels. -
drop: Drop targets for which the regular expression matches the concatenatedsourceLabels. The following example demonstrates usingrelabelsto drop the__name__oncadvisormetrics: -
labelmap: Match a regular expression against all label names. Then, copy the values of the matching labels to the label names given by the replacement with match group references (such as${1}or${2}) in the replacement substituted by their value. The following example useslabelmapto copy all labels containing__meta_kubernetes_service_label_and keep only a portion:In this example, the label__meta_kubernetes_service_label_app='api'is changed toapp='api'. -
labeldrop: Match a regular expression against all label names and remove any label that from the set of labels. The following example matches all label names that containcontainer_label_com_amazonaws_ecs_task_arn: -
labelkeep: Match a regular expression against all label names and remove any label that doesn’t match from the set of labels. The following example drops all label names that don’t matchjob: