Configuration

Prometheus is configured via command-line flags and a configuration file. Whilethe command-line flags configure immutable system parameters (such as storagelocations, amount of data to keep on disk and in memory, etc.), theconfiguration file defines everything related to scraping jobs and theirinstances, as well aswhich rule files to load.

To view all available command-line flags, run ./prometheus -h.

Prometheus can reload its configuration at runtime. If the new configurationis not well-formed, the changes will not be applied.A configuration reload is triggered by sending a SIGHUP to the Prometheus process orsending a HTTP POST request to the /-/reload endpoint (when the —web.enable-lifecycle flag is enabled).This will also reload any configured rule files.

Configuration file

To specify which configuration file to load, use the —config.file flag.

The file is written in YAML format,defined by the scheme described below.Brackets indicate that a parameter is optional. For non-list parameters thevalue is set to the specified default.

Generic placeholders are defined as follows:

  • <boolean>: a boolean that can take the values true or false
  • <duration>: a duration matching the regular expression [0-9]+(ms|[smhdwy])
  • <labelname>: a string matching the regular expression [a-zA-Z][a-zA-Z0-9]*
  • <labelvalue>: a string of unicode characters
  • <filename>: a valid path in the current working directory
  • <host>: a valid string consisting of a hostname or IP followed by an optional port number
  • <path>: a valid URL path
  • <scheme>: a string that can take the values http or https
  • <string>: a regular string
  • <secret>: a regular string that is a secret, such as a password
  • <tmpl_string>: a string which is template-expanded before usageThe other placeholders are specified separately.

A valid example file can be found here.

The global configuration specifies parameters that are valid in all other configurationcontexts. They also serve as defaults for other configuration sections.

  1. global:
  2. # How frequently to scrape targets by default.
  3. [ scrape_interval: <duration> | default = 1m ]
  4. # How long until a scrape request times out.
  5. [ scrape_timeout: <duration> | default = 10s ]
  6. # How frequently to evaluate rules.
  7. [ evaluation_interval: <duration> | default = 1m ]
  8. # The labels to add to any time series or alerts when communicating with
  9. # external systems (federation, remote storage, Alertmanager).
  10. external_labels:
  11. [ <labelname>: <labelvalue> ... ]
  12. # Rule files specifies a list of globs. Rules and alerts are read from
  13. # all matching files.
  14. rule_files:
  15. [ - <filepath_glob> ... ]
  16. # A list of scrape configurations.
  17. scrape_configs:
  18. [ - <scrape_config> ... ]
  19. # Alerting specifies settings related to the Alertmanager.
  20. alerting:
  21. alert_relabel_configs:
  22. [ - <relabel_config> ... ]
  23. alertmanagers:
  24. [ - <alertmanager_config> ... ]
  25. # Settings related to the remote write feature.
  26. remote_write:
  27. [ - <remote_write> ... ]
  28. # Settings related to the remote read feature.
  29. remote_read:
  30. [ - <remote_read> ... ]

<scrape_config>

A scrape_config section specifies a set of targets and parameters describing howto scrape them. In the general case, one scrape configuration specifies a singlejob. In advanced configurations, this may change.

Targets may be statically configured via the static_configs parameter ordynamically discovered using one of the supported service-discovery mechanisms.

Additionally, relabel_configs allow advanced modifications to anytarget and its labels before scraping.

  1. # The job name assigned to scraped metrics by default.
  2. job_name: <job_name>
  3. # How frequently to scrape targets from this job.
  4. [ scrape_interval: <duration> | default = <global_config.scrape_interval> ]
  5. # Per-scrape timeout when scraping this job.
  6. [ scrape_timeout: <duration> | default = <global_config.scrape_timeout> ]
  7. # The HTTP resource path on which to fetch metrics from targets.
  8. [ metrics_path: <path> | default = /metrics ]
  9. # honor_labels controls how Prometheus handles conflicts between labels that are
  10. # already present in scraped data and labels that Prometheus would attach
  11. # server-side ("job" and "instance" labels, manually configured target
  12. # labels, and labels generated by service discovery implementations).
  13. #
  14. # If honor_labels is set to "true", label conflicts are resolved by keeping label
  15. # values from the scraped data and ignoring the conflicting server-side labels.
  16. #
  17. # If honor_labels is set to "false", label conflicts are resolved by renaming
  18. # conflicting labels in the scraped data to "exported_<original-label>" (for
  19. # example "exported_instance", "exported_job") and then attaching server-side
  20. # labels.
  21. #
  22. # Setting honor_labels to "true" is useful for use cases such as federation and
  23. # scraping the Pushgateway, where all labels specified in the target should be
  24. # preserved.
  25. #
  26. # Note that any globally configured "external_labels" are unaffected by this
  27. # setting. In communication with external systems, they are always applied only
  28. # when a time series does not have a given label yet and are ignored otherwise.
  29. [ honor_labels: <boolean> | default = false ]
  30. # honor_timestamps controls whether Prometheus respects the timestamps present
  31. # in scraped data.
  32. #
  33. # If honor_timestamps is set to "true", the timestamps of the metrics exposed
  34. # by the target will be used.
  35. #
  36. # If honor_timestamps is set to "false", the timestamps of the metrics exposed
  37. # by the target will be ignored.
  38. [ honor_timestamps: <boolean> | default = true ]
  39. # Configures the protocol scheme used for requests.
  40. [ scheme: <scheme> | default = http ]
  41. # Optional HTTP URL parameters.
  42. params:
  43. [ <string>: [<string>, ...] ]
  44. # Sets the `Authorization` header on every scrape request with the
  45. # configured username and password.
  46. # password and password_file are mutually exclusive.
  47. basic_auth:
  48. [ username: <string> ]
  49. [ password: <secret> ]
  50. [ password_file: <string> ]
  51. # Sets the `Authorization` header on every scrape request with
  52. # the configured bearer token. It is mutually exclusive with `bearer_token_file`.
  53. [ bearer_token: <secret> ]
  54. # Sets the `Authorization` header on every scrape request with the bearer token
  55. # read from the configured file. It is mutually exclusive with `bearer_token`.
  56. [ bearer_token_file: /path/to/bearer/token/file ]
  57. # Configures the scrape request's TLS settings.
  58. tls_config:
  59. [ <tls_config> ]
  60. # Optional proxy URL.
  61. [ proxy_url: <string> ]
  62. # List of Azure service discovery configurations.
  63. azure_sd_configs:
  64. [ - <azure_sd_config> ... ]
  65. # List of Consul service discovery configurations.
  66. consul_sd_configs:
  67. [ - <consul_sd_config> ... ]
  68. # List of DNS service discovery configurations.
  69. dns_sd_configs:
  70. [ - <dns_sd_config> ... ]
  71. # List of EC2 service discovery configurations.
  72. ec2_sd_configs:
  73. [ - <ec2_sd_config> ... ]
  74. # List of OpenStack service discovery configurations.
  75. openstack_sd_configs:
  76. [ - <openstack_sd_config> ... ]
  77. # List of file service discovery configurations.
  78. file_sd_configs:
  79. [ - <file_sd_config> ... ]
  80. # List of GCE service discovery configurations.
  81. gce_sd_configs:
  82. [ - <gce_sd_config> ... ]
  83. # List of Kubernetes service discovery configurations.
  84. kubernetes_sd_configs:
  85. [ - <kubernetes_sd_config> ... ]
  86. # List of Marathon service discovery configurations.
  87. marathon_sd_configs:
  88. [ - <marathon_sd_config> ... ]
  89. # List of AirBnB's Nerve service discovery configurations.
  90. nerve_sd_configs:
  91. [ - <nerve_sd_config> ... ]
  92. # List of Zookeeper Serverset service discovery configurations.
  93. serverset_sd_configs:
  94. [ - <serverset_sd_config> ... ]
  95. # List of Triton service discovery configurations.
  96. triton_sd_configs:
  97. [ - <triton_sd_config> ... ]
  98. # List of labeled statically configured targets for this job.
  99. static_configs:
  100. [ - <static_config> ... ]
  101. # List of target relabel configurations.
  102. relabel_configs:
  103. [ - <relabel_config> ... ]
  104. # List of metric relabel configurations.
  105. metric_relabel_configs:
  106. [ - <relabel_config> ... ]
  107. # Per-scrape limit on number of scraped samples that will be accepted.
  108. # If more than this number of samples are present after metric relabelling
  109. # the entire scrape will be treated as failed. 0 means no limit.
  110. [ sample_limit: <int> | default = 0 ]

Where <job_name> must be unique across all scrape configurations.

<tls_config>

A tls_config allows configuring TLS connections.

  1. # CA certificate to validate API server certificate with.
  2. [ ca_file: <filename> ]
  3. # Certificate and key files for client cert authentication to the server.
  4. [ cert_file: <filename> ]
  5. [ key_file: <filename> ]
  6. # ServerName extension to indicate the name of the server.
  7. # https://tools.ietf.org/html/rfc4366#section-3.1
  8. [ server_name: <string> ]
  9. # Disable validation of the server certificate.
  10. [ insecure_skip_verify: <boolean> ]

<azure_sd_config>

Azure SD configurations allow retrieving scrape targets from Azure VMs.

The following meta labels are available on targets during relabeling:

  • __meta_azure_machine_id: the machine ID
  • __meta_azure_machine_location: the location the machine runs in
  • __meta_azure_machine_name: the machine name
  • __meta_azure_machine_os_type: the machine operating system
  • __meta_azure_machine_private_ip: the machine's private IP
  • __meta_azure_machine_public_ip: the machine's public IP if it exists
  • __meta_azure_machine_resource_group: the machine's resource group
  • _meta_azure_machine_tag<tagname>: each tag value of the machine
  • __meta_azure_machine_scale_set: the name of the scale set which the vm is part of (this value is only set if you are using a scale set)
  • __meta_azure_subscription_id: the subscription ID
  • __meta_azure_tenant_id: the tenant IDSee below for the configuration options for Azure discovery:
  1. # The information to access the Azure API.
  2. # The Azure environment.
  3. [ environment: <string> | default = AzurePublicCloud ]
  4. # The authentication method, either OAuth or ManagedIdentity.
  5. # See https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
  6. [ authentication_method: <string> | default = OAuth]
  7. # The subscription ID. Always required.
  8. subscription_id: <string>
  9. # Optional tenant ID. Only required with authentication_method OAuth.
  10. [ tenant_id: <string> ]
  11. # Optional client ID. Only required with authentication_method OAuth.
  12. [ client_id: <string> ]
  13. # Optional client secret. Only required with authentication_method OAuth.
  14. [ client_secret: <secret> ]
  15. # Refresh interval to re-read the instance list.
  16. [ refresh_interval: <duration> | default = 300s ]
  17. # The port to scrape metrics from. If using the public IP address, this must
  18. # instead be specified in the relabeling rule.
  19. [ port: <int> | default = 80 ]

<consul_sd_config>

Consul SD configurations allow retrieving scrape targets from Consul'sCatalog API.

The following meta labels are available on targets during relabeling:

  • __meta_consul_address: the address of the target
  • __meta_consul_dc: the datacenter name for the target
  • _meta_consul_tagged_address<key>: each node tagged address key value of the target
  • _meta_consul_metadata<key>: each node metadata key value of the target
  • __meta_consul_node: the node name defined for the target
  • __meta_consul_service_address: the service address of the target
  • __meta_consul_service_id: the service ID of the target
  • _meta_consul_service_metadata<key>: each service metadata key value of the target
  • __meta_consul_service_port: the service port of the target
  • __meta_consul_service: the name of the service the target belongs to
  • __meta_consul_tags: the list of tags of the target joined by the tag separator
  1. # The information to access the Consul API. It is to be defined
  2. # as the Consul documentation requires.
  3. [ server: <host> | default = "localhost:8500" ]
  4. [ token: <secret> ]
  5. [ datacenter: <string> ]
  6. [ scheme: <string> | default = "http" ]
  7. [ username: <string> ]
  8. [ password: <secret> ]
  9. tls_config:
  10. [ <tls_config> ]
  11. # A list of services for which targets are retrieved. If omitted, all services
  12. # are scraped.
  13. services:
  14. [ - <string> ]
  15. # See https://www.consul.io/api/catalog.html#list-nodes-for-service to know more
  16. # about the possible filters that can be used.
  17. # An optional list of tags used to filter nodes for a given service. Services must contain all tags in the list.
  18. tags:
  19. [ - <string> ]
  20. # Node metadata used to filter nodes for a given service.
  21. [ node_meta:
  22. [ <name>: <value> ... ] ]
  23. # The string by which Consul tags are joined into the tag label.
  24. [ tag_separator: <string> | default = , ]
  25. # Allow stale Consul results (see https://www.consul.io/api/features/consistency.html). Will reduce load on Consul.
  26. [ allow_stale: <bool> ]
  27. # The time after which the provided names are refreshed.
  28. # On large setup it might be a good idea to increase this value because the catalog will change all the time.
  29. [ refresh_interval: <duration> | default = 30s ]

Note that the IP number and port used to scrape the targets is assembled as<meta_consul_address>:<metaconsulservice_port>. However, in someConsul setups, the relevant address is in meta_consul_service_address.In those cases, you can use the relabelfeature to replace the special address label.

The relabeling phase is the preferred and more powerfulway to filter services or nodes for a service based on arbitrary labels. Forusers with thousands of services it can be more efficient to use the Consul APIdirectly which has basic support for filtering nodes (currently by nodemetadata and a single tag).

<dns_sd_config>

A DNS-based service discovery configuration allows specifying a set of DNSdomain names which are periodically queried to discover a list of targets. TheDNS servers to be contacted are read from /etc/resolv.conf.

This service discovery method only supports basic DNS A, AAAA and SRV recordqueries, but not the advanced DNS-SD approach specified inRFC6763.

During the relabeling phase, the meta label__meta_dns_name is available on each target and is set to therecord name that produced the discovered target.

  1. # A list of DNS domain names to be queried.
  2. names:
  3. [ - <domain_name> ]
  4. # The type of DNS query to perform.
  5. [ type: <query_type> | default = 'SRV' ]
  6. # The port number used if the query type is not SRV.
  7. [ port: <number>]
  8. # The time after which the provided names are refreshed.
  9. [ refresh_interval: <duration> | default = 30s ]

Where <domain_name> is a valid DNS domain name.Where <query_type> is SRV, A, or AAAA.

<ec2_sd_config>

EC2 SD configurations allow retrieving scrape targets from AWS EC2instances. The private IP address is used by default, but may be changed tothe public IP address with relabeling.

The following meta labels are available on targets during relabeling:

  • __meta_ec2_availability_zone: the availability zone in which the instance is running
  • __meta_ec2_instance_id: the EC2 instance ID
  • __meta_ec2_instance_state: the state of the EC2 instance
  • __meta_ec2_instance_type: the type of the EC2 instance
  • __meta_ec2_owner_id: the ID of the AWS account that owns the EC2 instance
  • __meta_ec2_platform: the Operating System platform, set to 'windows' on Windows servers, absent otherwise
  • __meta_ec2_primary_subnet_id: the subnet ID of the primary network interface, if available
  • __meta_ec2_private_dns_name: the private DNS name of the instance, if available
  • __meta_ec2_private_ip: the private IP address of the instance, if present
  • __meta_ec2_public_dns_name: the public DNS name of the instance, if available
  • __meta_ec2_public_ip: the public IP address of the instance, if available
  • __meta_ec2_subnet_id: comma separated list of subnets IDs in which the instance is running, if available
  • _meta_ec2_tag<tagkey>: each tag value of the instance
  • __meta_ec2_vpc_id: the ID of the VPC in which the instance is running, if availableSee below for the configuration options for EC2 discovery:
  1. # The information to access the EC2 API.
  2. # The AWS region. If blank, the region from the instance metadata is used.
  3. [ region: <string> ]
  4. # Custom endpoint to be used.
  5. [ endpoint: <string> ]
  6. # The AWS API keys. If blank, the environment variables `AWS_ACCESS_KEY_ID`
  7. # and `AWS_SECRET_ACCESS_KEY` are used.
  8. [ access_key: <string> ]
  9. [ secret_key: <secret> ]
  10. # Named AWS profile used to connect to the API.
  11. [ profile: <string> ]
  12. # AWS Role ARN, an alternative to using AWS API keys.
  13. [ role_arn: <string> ]
  14. # Refresh interval to re-read the instance list.
  15. [ refresh_interval: <duration> | default = 60s ]
  16. # The port to scrape metrics from. If using the public IP address, this must
  17. # instead be specified in the relabeling rule.
  18. [ port: <int> | default = 80 ]
  19. # Filters can be used optionally to filter the instance list by other criteria.
  20. # Available filter criteria can be found here:
  21. # https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html
  22. # Filter API documentation: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Filter.html
  23. filters:
  24. [ - name: <string>
  25. values: <string>, [...] ]

The relabeling phase is the preferred and more powerfulway to filter targets based on arbitrary labels. For users with thousands ofinstances it can be more efficient to use the EC2 API directly which hassupport for filtering instances.

<openstack_sd_config>

OpenStack SD configurations allow retrieving scrape targets from OpenStack Novainstances.

One of the following <openstack_role> types can be configured to discover targets:

hypervisor

The hypervisor role discovers one target per Nova hypervisor node. The targetaddress defaults to the host_ip attribute of the hypervisor.

The following meta labels are available on targets during relabeling:

  • __meta_openstack_hypervisor_host_ip: the hypervisor node's IP address.
  • __meta_openstack_hypervisor_name: the hypervisor node's name.
  • __meta_openstack_hypervisor_state: the hypervisor node's state.
  • __meta_openstack_hypervisor_status: the hypervisor node's status.
  • __meta_openstack_hypervisor_type: the hypervisor node's type.

instance

The instance role discovers one target per network interface of Novainstance. The target address defaults to the private IP address of the networkinterface.

The following meta labels are available on targets during relabeling:

  • __meta_openstack_address_pool: the pool of the private IP.
  • __meta_openstack_instance_flavor: the flavor of the OpenStack instance.
  • __meta_openstack_instance_id: the OpenStack instance ID.
  • __meta_openstack_instance_name: the OpenStack instance name.
  • __meta_openstack_instance_status: the status of the OpenStack instance.
  • __meta_openstack_private_ip: the private IP of the OpenStack instance.
  • __meta_openstack_project_id: the project (tenant) owning this instance.
  • __meta_openstack_public_ip: the public IP of the OpenStack instance.
  • _meta_openstack_tag<tagkey>: each tag value of the instance.
  • __meta_openstack_user_id: the user account owning the tenant.See below for the configuration options for OpenStack discovery:
  1. # The information to access the OpenStack API.
  2. # The OpenStack role of entities that should be discovered.
  3. role: <openstack_role>
  4. # The OpenStack Region.
  5. region: <string>
  6. # identity_endpoint specifies the HTTP endpoint that is required to work with
  7. # the Identity API of the appropriate version. While it's ultimately needed by
  8. # all of the identity services, it will often be populated by a provider-level
  9. # function.
  10. [ identity_endpoint: <string> ]
  11. # username is required if using Identity V2 API. Consult with your provider's
  12. # control panel to discover your account's username. In Identity V3, either
  13. # userid or a combination of username and domain_id or domain_name are needed.
  14. [ username: <string> ]
  15. [ userid: <string> ]
  16. # password for the Identity V2 and V3 APIs. Consult with your provider's
  17. # control panel to discover your account's preferred method of authentication.
  18. [ password: <secret> ]
  19. # At most one of domain_id and domain_name must be provided if using username
  20. # with Identity V3. Otherwise, either are optional.
  21. [ domain_name: <string> ]
  22. [ domain_id: <string> ]
  23. # The project_id and project_name fields are optional for the Identity V2 API.
  24. # Some providers allow you to specify a project_name instead of the project_id.
  25. # Some require both. Your provider's authentication policies will determine
  26. # how these fields influence authentication.
  27. [ project_name: <string> ]
  28. [ project_id: <string> ]
  29. # The application_credential_id or application_credential_name fields are
  30. # required if using an application credential to authenticate. Some providers
  31. # allow you to create an application credential to authenticate rather than a
  32. # password.
  33. [ application_credential_name: <string> ]
  34. [ application_credential_id: <string> ]
  35. # The application_credential_secret field is required if using an application
  36. # credential to authenticate.
  37. [ application_credential_secret: <secret> ]
  38. # Whether the service discovery should list all instances for all projects.
  39. # It is only relevant for the 'instance' role and usually requires admin permissions.
  40. [ all_tenants: <boolean> | default: false ]
  41. # Refresh interval to re-read the instance list.
  42. [ refresh_interval: <duration> | default = 60s ]
  43. # The port to scrape metrics from. If using the public IP address, this must
  44. # instead be specified in the relabeling rule.
  45. [ port: <int> | default = 80 ]
  46. # TLS configuration.
  47. tls_config:
  48. [ <tls_config> ]

<file_sd_config>

File-based service discovery provides a more generic way to configure static targetsand serves as an interface to plug in custom service discovery mechanisms.

It reads a set of files containing a list of zero or more<static_config>s. Changes to all defined files are detected via disk watchesand applied immediately. Files may be provided in YAML or JSON format. Onlychanges resulting in well-formed target groups are applied.

The JSON file must contain a list of static configs, using this format:

  1. [
  2. {
  3. "targets": [ "<host>", ... ],
  4. "labels": {
  5. "<labelname>": "<labelvalue>", ...
  6. }
  7. },
  8. ...
  9. ]

As a fallback, the file contents are also re-read periodically at the specifiedrefresh interval.

Each target has a meta label __meta_filepath during therelabeling phase. Its value is set to thefilepath from which the target was extracted.

There is a list ofintegrations with thisdiscovery mechanism.

  1. # Patterns for files from which target groups are extracted.
  2. files:
  3. [ - <filename_pattern> ... ]
  4. # Refresh interval to re-read the files.
  5. [ refresh_interval: <duration> | default = 5m ]

Where <filenamepattern> may be a path ending in .json, .yml or .yaml. The last path segmentmay contain a single * that matches any character sequence, e.g. my/path/tg*.json.

<gce_sd_config>

GCE SD configurations allow retrieving scrape targets from GCP GCE instances.The private IP address is used by default, but may be changed to the public IPaddress with relabeling.

The following meta labels are available on targets during relabeling:

  • __meta_gce_instance_id: the numeric id of the instance
  • __meta_gce_instance_name: the name of the instance
  • _meta_gce_label<name>: each GCE label of the instance
  • __meta_gce_machine_type: full or partial URL of the machine type of the instance
  • _meta_gce_metadata<name>: each metadata item of the instance
  • __meta_gce_network: the network URL of the instance
  • __meta_gce_private_ip: the private IP address of the instance
  • __meta_gce_project: the GCP project in which the instance is running
  • __meta_gce_public_ip: the public IP address of the instance, if present
  • __meta_gce_subnetwork: the subnetwork URL of the instance
  • __meta_gce_tags: comma separated list of instance tags
  • __meta_gce_zone: the GCE zone URL in which the instance is runningSee below for the configuration options for GCE discovery:
  1. # The information to access the GCE API.
  2. # The GCP Project
  3. project: <string>
  4. # The zone of the scrape targets. If you need multiple zones use multiple
  5. # gce_sd_configs.
  6. zone: <string>
  7. # Filter can be used optionally to filter the instance list by other criteria
  8. # Syntax of this filter string is described here in the filter query parameter section:
  9. # https://cloud.google.com/compute/docs/reference/latest/instances/list
  10. [ filter: <string> ]
  11. # Refresh interval to re-read the instance list
  12. [ refresh_interval: <duration> | default = 60s ]
  13. # The port to scrape metrics from. If using the public IP address, this must
  14. # instead be specified in the relabeling rule.
  15. [ port: <int> | default = 80 ]
  16. # The tag separator is used to separate the tags on concatenation
  17. [ tag_separator: <string> | default = , ]

Credentials are discovered by the Google Cloud SDK default client by lookingin the following places, preferring the first location found:

  • a JSON file specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable
  • a JSON file in the well-known path $HOME/.config/gcloud/application_default_credentials.json
  • fetched from the GCE metadata serverIf Prometheus is running within GCE, the service account associated with theinstance it is running on should have at least read-only permissions to thecompute resources. If running outside of GCE make sure to create an appropriateservice account and place the credential file in one of the expected locations.

<kubernetes_sd_config>

Kubernetes SD configurations allow retrieving scrape targets fromKubernetes' REST API and always staying synchronized withthe cluster state.

One of the following role types can be configured to discover targets:

node

The node role discovers one target per cluster node with the address defaultingto the Kubelet's HTTP port.The target address defaults to the first existing address of the Kubernetesnode object in the address type order of NodeInternalIP, NodeExternalIP,NodeLegacyHostIP, and NodeHostName.

Available meta labels:

  • __meta_kubernetes_node_name: The name of the node object.
  • _meta_kubernetes_node_label<labelname>: Each label from the node object.
  • _meta_kubernetes_node_labelpresent<labelname>: true for each label from the node object.
  • _meta_kubernetes_node_annotation<annotationname>: Each annotation from the node object.
  • _meta_kubernetes_node_annotationpresent<annotationname>: true for each annotation from the node object.
  • _meta_kubernetes_node_address<address_type>: The first address for each node address type, if it exists.In addition, the instance label for the node will be set to the node nameas retrieved from the API server.

service

The service role discovers a target for each service port for each service.This is generally useful for blackbox monitoring of a service.The address will be set to the Kubernetes DNS name of the service and respectiveservice port.

Available meta labels:

  • __meta_kubernetes_namespace: The namespace of the service object.
  • _meta_kubernetes_service_annotation<annotationname>: Each annotation from the service object.
  • _meta_kubernetes_service_annotationpresent<annotationname>: "true" for each annotation of the service object.
  • __meta_kubernetes_service_cluster_ip: The cluster IP address of the service. (Does not apply to services of type ExternalName)
  • __meta_kubernetes_service_external_name: The DNS name of the service. (Applies to services of type ExternalName)
  • _meta_kubernetes_service_label<labelname>: Each label from the service object.
  • _meta_kubernetes_service_labelpresent<labelname>: true for each label of the service object.
  • __meta_kubernetes_service_name: The name of the service object.
  • __meta_kubernetes_service_port_name: Name of the service port for the target.
  • __meta_kubernetes_service_port_protocol: Protocol of the service port for the target.

pod

The pod role discovers all pods and exposes their containers as targets. For each declaredport of a container, a single target is generated. If a container has no specified ports,a port-free target per container is created for manually adding a port via relabeling.

Available meta labels:

  • __meta_kubernetes_namespace: The namespace of the pod object.
  • __meta_kubernetes_pod_name: The name of the pod object.
  • __meta_kubernetes_pod_ip: The pod IP of the pod object.
  • _meta_kubernetes_pod_label<labelname>: Each label from the pod object.
  • _meta_kubernetes_pod_labelpresent<labelname>: truefor each label from the pod object.
  • _meta_kubernetes_pod_annotation<annotationname>: Each annotation from the pod object.
  • _meta_kubernetes_pod_annotationpresent<annotationname>: true for each annotation from the pod object.
  • __meta_kubernetes_pod_container_init: true if the container is an InitContainer
  • __meta_kubernetes_pod_container_name: Name of the container the target address points to.
  • __meta_kubernetes_pod_container_port_name: Name of the container port.
  • __meta_kubernetes_pod_container_port_number: Number of the container port.
  • __meta_kubernetes_pod_container_port_protocol: Protocol of the container port.
  • __meta_kubernetes_pod_ready: Set to true or false for the pod's ready state.
  • __meta_kubernetes_pod_phase: Set to Pending, Running, Succeeded, Failed or Unknownin the lifecycle.
  • __meta_kubernetes_pod_node_name: The name of the node the pod is scheduled onto.
  • __meta_kubernetes_pod_host_ip: The current host IP of the pod object.
  • __meta_kubernetes_pod_uid: The UID of the pod object.
  • __meta_kubernetes_pod_controller_kind: Object kind of the pod controller.
  • __meta_kubernetes_pod_controller_name: Name of the pod controller.

endpoints

The endpoints role discovers targets from listed endpoints of a service. For each endpointaddress one target is discovered per port. If the endpoint is backed by a pod, alladditional container ports of the pod, not bound to an endpoint port, are discovered as targets as well.

Available meta labels:

  • __meta_kubernetes_namespace: The namespace of the endpoints object.
  • __meta_kubernetes_endpoints_name: The names of the endpoints object.
  • For all targets discovered directly from the endpoints list (those not additionally inferredfrom underlying pods), the following labels are attached:
    • __meta_kubernetes_endpoint_hostname: Hostname of the endpoint.
    • __meta_kubernetes_endpoint_node_name: Name of the node hosting the endpoint.
    • __meta_kubernetes_endpoint_ready: Set to true or false for the endpoint's ready state.
    • __meta_kubernetes_endpoint_port_name: Name of the endpoint port.
    • __meta_kubernetes_endpoint_port_protocol: Protocol of the endpoint port.
    • __meta_kubernetes_endpoint_address_target_kind: Kind of the endpoint address target.
    • __meta_kubernetes_endpoint_address_target_name: Name of the endpoint address target.
  • If the endpoints belong to a service, all labels of the role: service discovery are attached.
  • For all targets backed by a pod, all labels of the role: pod discovery are attached.

ingress

The ingress role discovers a target for each path of each ingress.This is generally useful for blackbox monitoring of an ingress.The address will be set to the host specified in the ingress spec.

Available meta labels:

  • __meta_kubernetes_namespace: The namespace of the ingress object.
  • __meta_kubernetes_ingress_name: The name of the ingress object.
  • _meta_kubernetes_ingress_label<labelname>: Each label from the ingress object.
  • _meta_kubernetes_ingress_labelpresent<labelname>: true for each label from the ingress object.
  • _meta_kubernetes_ingress_annotation<annotationname>: Each annotation from the ingress object.
  • _meta_kubernetes_ingress_annotationpresent<annotationname>: true for each annotation from the ingress object.
  • __meta_kubernetes_ingress_scheme: Protocol scheme of ingress, https if TLSconfig is set. Defaults to http.
  • __meta_kubernetes_ingress_path: Path from ingress spec. Defaults to /.See below for the configuration options for Kubernetes discovery:
  1. # The information to access the Kubernetes API.
  2. # The API server addresses. If left empty, Prometheus is assumed to run inside
  3. # of the cluster and will discover API servers automatically and use the pod's
  4. # CA certificate and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/.
  5. [ api_server: <host> ]
  6. # The Kubernetes role of entities that should be discovered.
  7. role: <role>
  8. # Optional authentication information used to authenticate to the API server.
  9. # Note that `basic_auth`, `bearer_token` and `bearer_token_file` options are
  10. # mutually exclusive.
  11. # password and password_file are mutually exclusive.
  12. # Optional HTTP basic authentication information.
  13. basic_auth:
  14. [ username: <string> ]
  15. [ password: <secret> ]
  16. [ password_file: <string> ]
  17. # Optional bearer token authentication information.
  18. [ bearer_token: <secret> ]
  19. # Optional bearer token file authentication information.
  20. [ bearer_token_file: <filename> ]
  21. # Optional proxy URL.
  22. [ proxy_url: <string> ]
  23. # TLS configuration.
  24. tls_config:
  25. [ <tls_config> ]
  26. # Optional namespace discovery. If omitted, all namespaces are used.
  27. namespaces:
  28. names:
  29. [ - <string> ]

Where <role> must be endpoints, service, pod, node, oringress.

See this example Prometheus configuration filefor a detailed example of configuring Prometheus for Kubernetes.

You may wish to check out the 3rd party Prometheus Operator,which automates the Prometheus setup on top of Kubernetes.

<marathon_sd_config>

Marathon SD configurations allow retrieving scrape targets using theMarathon REST API. Prometheuswill periodically check the REST endpoint for currently running tasks andcreate a target group for every app that has at least one healthy task.

The following meta labels are available on targets during relabeling:

  • __meta_marathon_app: the name of the app (with slashes replaced by dashes)
  • __meta_marathon_image: the name of the Docker image used (if available)
  • __meta_marathon_task: the ID of the Mesos task
  • _meta_marathon_app_label<labelname>: any Marathon labels attached to the app
  • _meta_marathon_port_definition_label<labelname>: the port definition labels
  • _meta_marathon_port_mapping_label<labelname>: the port mapping labels
  • __meta_marathon_port_index: the port index number (e.g. 1 for PORT1)See below for the configuration options for Marathon discovery:
  1. # List of URLs to be used to contact Marathon servers.
  2. # You need to provide at least one server URL.
  3. servers:
  4. - <string>
  5. # Polling interval
  6. [ refresh_interval: <duration> | default = 30s ]
  7. # Optional authentication information for token-based authentication
  8. # https://docs.mesosphere.com/1.11/security/ent/iam-api/#passing-an-authentication-token
  9. # It is mutually exclusive with `auth_token_file` and other authentication mechanisms.
  10. [ auth_token: <secret> ]
  11. # Optional authentication information for token-based authentication
  12. # https://docs.mesosphere.com/1.11/security/ent/iam-api/#passing-an-authentication-token
  13. # It is mutually exclusive with `auth_token` and other authentication mechanisms.
  14. [ auth_token_file: <filename> ]
  15. # Sets the `Authorization` header on every request with the
  16. # configured username and password.
  17. # This is mutually exclusive with other authentication mechanisms.
  18. # password and password_file are mutually exclusive.
  19. basic_auth:
  20. [ username: <string> ]
  21. [ password: <string> ]
  22. [ password_file: <string> ]
  23. # Sets the `Authorization` header on every request with
  24. # the configured bearer token. It is mutually exclusive with `bearer_token_file` and other authentication mechanisms.
  25. # NOTE: The current version of DC/OS marathon (v1.11.0) does not support standard Bearer token authentication. Use `auth_token` instead.
  26. [ bearer_token: <string> ]
  27. # Sets the `Authorization` header on every request with the bearer token
  28. # read from the configured file. It is mutually exclusive with `bearer_token` and other authentication mechanisms.
  29. # NOTE: The current version of DC/OS marathon (v1.11.0) does not support standard Bearer token authentication. Use `auth_token_file` instead.
  30. [ bearer_token_file: /path/to/bearer/token/file ]
  31. # TLS configuration for connecting to marathon servers
  32. tls_config:
  33. [ <tls_config> ]
  34. # Optional proxy URL.
  35. [ proxy_url: <string> ]

By default every app listed in Marathon will be scraped by Prometheus. If not allof your services provide Prometheus metrics, you can use a Marathon label andPrometheus relabeling to control which instances will actually be scraped.See the Prometheus marathon-sd configuration filefor a practical example on how to set up your Marathon app and your Prometheusconfiguration.

By default, all apps will show up as a single job in Prometheus (the one specifiedin the configuration file), which can also be changed using relabeling.

<nerve_sd_config>

Nerve SD configurations allow retrieving scrape targets from AirBnB's Nerve which are stored inZookeeper.

The following meta labels are available on targets during relabeling:

  • __meta_nerve_path: the full path to the endpoint node in Zookeeper
  • __meta_nerve_endpoint_host: the host of the endpoint
  • __meta_nerve_endpoint_port: the port of the endpoint
  • __meta_nerve_endpoint_name: the name of the endpoint
  1. # The Zookeeper servers.
  2. servers:
  3. - <host>
  4. # Paths can point to a single service, or the root of a tree of services.
  5. paths:
  6. - <string>
  7. [ timeout: <duration> | default = 10s ]

<serverset_sd_config>

Serverset SD configurations allow retrieving scrape targets from Serversets which arestored in Zookeeper. Serversets are commonlyused by Finagle andAurora.

The following meta labels are available on targets during relabeling:

  • __meta_serverset_path: the full path to the serverset member node in Zookeeper
  • __meta_serverset_endpoint_host: the host of the default endpoint
  • __meta_serverset_endpoint_port: the port of the default endpoint
  • _meta_serverset_endpoint_host<endpoint>: the host of the given endpoint
  • _meta_serverset_endpoint_port<endpoint>: the port of the given endpoint
  • __meta_serverset_shard: the shard number of the member
  • __meta_serverset_status: the status of the member
  1. # The Zookeeper servers.
  2. servers:
  3. - <host>
  4. # Paths can point to a single serverset, or the root of a tree of serversets.
  5. paths:
  6. - <string>
  7. [ timeout: <duration> | default = 10s ]

Serverset data must be in the JSON format, the Thrift format is not currently supported.

<triton_sd_config>

Triton SD configurations allow retrievingscrape targets from Container Monitordiscovery endpoints.

The following meta labels are available on targets during relabeling:

  • __meta_triton_groups: the list of groups belonging to the target joined by a comma separator
  • __meta_triton_machine_alias: the alias of the target container
  • __meta_triton_machine_brand: the brand of the target container
  • __meta_triton_machine_id: the UUID of the target container
  • __meta_triton_machine_image: the target containers image type
  • __meta_triton_server_id: the server UUID for the target container
  1. # The information to access the Triton discovery API.
  2. # The account to use for discovering new target containers.
  3. account: <string>
  4. # The DNS suffix which should be applied to target containers.
  5. dns_suffix: <string>
  6. # The Triton discovery endpoint (e.g. 'cmon.us-east-3b.triton.zone'). This is
  7. # often the same value as dns_suffix.
  8. endpoint: <string>
  9. # A list of groups for which targets are retrieved. If omitted, all containers
  10. # available to the requesting account are scraped.
  11. groups:
  12. [ - <string> ... ]
  13. # The port to use for discovery and metric scraping.
  14. [ port: <int> | default = 9163 ]
  15. # The interval which should be used for refreshing target containers.
  16. [ refresh_interval: <duration> | default = 60s ]
  17. # The Triton discovery API version.
  18. [ version: <int> | default = 1 ]
  19. # TLS configuration.
  20. tls_config:
  21. [ <tls_config> ]

<static_config>

A static_config allows specifying a list of targets and a common label setfor them. It is the canonical way to specify static targets in a scrapeconfiguration.

  1. # The targets specified by the static config.
  2. targets:
  3. [ - '<host>' ]
  4. # Labels assigned to all metrics scraped from the targets.
  5. labels:
  6. [ <labelname>: <labelvalue> ... ]

<relabel_config>

Relabeling is a powerful tool to dynamically rewrite the label set of a target beforeit gets scraped. Multiple relabeling steps can be configured per scrape configuration.They are applied to the label set of each target in order of their appearancein the configuration file.

Initially, aside from the configured per-target labels, a target's joblabel is set to the jobname value of the respective scrape configuration.The address label is set to the <host>:<port> address of the target.After relabeling, the instance label is set to the value of address by default ifit was not set during relabeling. The scheme and metrics_path labelsare set to the scheme and metrics path of the target respectively. The __param<name>label is set to the value of the first passed URL parameter called <name>.

Additional labels prefixed with _meta may be available during therelabeling phase. They are set by the service discovery mechanism that providedthe target and vary between mechanisms.

Labels starting with __ will be removed from the label set after targetrelabeling is completed.

If a relabeling step needs to store a label value only temporarily (as theinput to a subsequent relabeling step), use the __tmp label name prefix. Thisprefix is guaranteed to never be used by Prometheus itself.

  1. # The source labels select values from existing labels. Their content is concatenated
  2. # using the configured separator and matched against the configured regular expression
  3. # for the replace, keep, and drop actions.
  4. [ source_labels: '[' <labelname> [, ...] ']' ]
  5. # Separator placed between concatenated source label values.
  6. [ separator: <string> | default = ; ]
  7. # Label to which the resulting value is written in a replace action.
  8. # It is mandatory for replace actions. Regex capture groups are available.
  9. [ target_label: <labelname> ]
  10. # Regular expression against which the extracted value is matched.
  11. [ regex: <regex> | default = (.*) ]
  12. # Modulus to take of the hash of the source label values.
  13. [ modulus: <uint64> ]
  14. # Replacement value against which a regex replace is performed if the
  15. # regular expression matches. Regex capture groups are available.
  16. [ replacement: <string> | default = $1 ]
  17. # Action to perform based on regex matching.
  18. [ action: <relabel_action> | default = replace ]

<regex> is any validRE2 regular expression. It isrequired for the replace, keep, drop, labelmap,labeldrop and labelkeep actions. The regex isanchored on both ends. To un-anchor the regex, use .<regex>..

<relabel_action> determines the relabeling action to take:

  • replace: Match regex against the concatenated source_labels. Then, settarget_label to replacement, with match group references(${1}, ${2}, …) in replacement substituted by their value. If regexdoes not match, no replacement takes place.
  • keep: Drop targets for which regex does not match the concatenated source_labels.
  • drop: Drop targets for which regex matches the concatenated source_labels.
  • hashmod: Set target_label to the modulus of a hash of the concatenated source_labels.
  • labelmap: Match regex against all label names. Then copy the values of the matching labelsto label names given by replacement with match group references(${1}, ${2}, …) in replacement substituted by their value.
  • labeldrop: Match regex against all label names. Any label that matches will beremoved from the set of labels.
  • labelkeep: Match regex against all label names. Any label that does not match will beremoved from the set of labels.Care must be taken with labeldrop and labelkeep to ensure that metrics arestill uniquely labeled once the labels are removed.

<metric_relabel_configs>

Metric relabeling is applied to samples as the last step before ingestion. Ithas the same configuration format and actions as target relabeling. Metricrelabeling does not apply to automatically generated timeseries such as up.

One use for this is to blacklist time series that are too expensive to ingest.

<alert_relabel_configs>

Alert relabeling is applied to alerts before they are sent to the Alertmanager.It has the same configuration format and actions as target relabeling. Alertrelabeling is applied after external labels.

One use for this is ensuring a HA pair of Prometheus servers with differentexternal labels send identical alerts.

<alertmanager_config>

An alertmanager_config section specifies Alertmanager instances the Prometheusserver sends alerts to. It also provides parameters to configure how tocommunicate with these Alertmanagers.

Alertmanagers may be statically configured via the static_configs parameter ordynamically discovered using one of the supported service-discovery mechanisms.

Additionally, relabelconfigs allow selecting Alertmanagers from discoveredentities and provide advanced modifications to the used API path, which is exposedthrough the _alerts_path label.

  1. # Per-target Alertmanager timeout when pushing alerts.
  2. [ timeout: <duration> | default = 10s ]
  3. # The api version of Alertmanager.
  4. [ api_version: <version> | default = v1 ]
  5. # Prefix for the HTTP path alerts are pushed to.
  6. [ path_prefix: <path> | default = / ]
  7. # Configures the protocol scheme used for requests.
  8. [ scheme: <scheme> | default = http ]
  9. # Sets the `Authorization` header on every request with the
  10. # configured username and password.
  11. # password and password_file are mutually exclusive.
  12. basic_auth:
  13. [ username: <string> ]
  14. [ password: <string> ]
  15. [ password_file: <string> ]
  16. # Sets the `Authorization` header on every request with
  17. # the configured bearer token. It is mutually exclusive with `bearer_token_file`.
  18. [ bearer_token: <string> ]
  19. # Sets the `Authorization` header on every request with the bearer token
  20. # read from the configured file. It is mutually exclusive with `bearer_token`.
  21. [ bearer_token_file: /path/to/bearer/token/file ]
  22. # Configures the scrape request's TLS settings.
  23. tls_config:
  24. [ <tls_config> ]
  25. # Optional proxy URL.
  26. [ proxy_url: <string> ]
  27. # List of Azure service discovery configurations.
  28. azure_sd_configs:
  29. [ - <azure_sd_config> ... ]
  30. # List of Consul service discovery configurations.
  31. consul_sd_configs:
  32. [ - <consul_sd_config> ... ]
  33. # List of DNS service discovery configurations.
  34. dns_sd_configs:
  35. [ - <dns_sd_config> ... ]
  36. # List of EC2 service discovery configurations.
  37. ec2_sd_configs:
  38. [ - <ec2_sd_config> ... ]
  39. # List of file service discovery configurations.
  40. file_sd_configs:
  41. [ - <file_sd_config> ... ]
  42. # List of GCE service discovery configurations.
  43. gce_sd_configs:
  44. [ - <gce_sd_config> ... ]
  45. # List of Kubernetes service discovery configurations.
  46. kubernetes_sd_configs:
  47. [ - <kubernetes_sd_config> ... ]
  48. # List of Marathon service discovery configurations.
  49. marathon_sd_configs:
  50. [ - <marathon_sd_config> ... ]
  51. # List of AirBnB's Nerve service discovery configurations.
  52. nerve_sd_configs:
  53. [ - <nerve_sd_config> ... ]
  54. # List of Zookeeper Serverset service discovery configurations.
  55. serverset_sd_configs:
  56. [ - <serverset_sd_config> ... ]
  57. # List of Triton service discovery configurations.
  58. triton_sd_configs:
  59. [ - <triton_sd_config> ... ]
  60. # List of labeled statically configured Alertmanagers.
  61. static_configs:
  62. [ - <static_config> ... ]
  63. # List of Alertmanager relabel configurations.
  64. relabel_configs:
  65. [ - <relabel_config> ... ]

<remote_write>

write_relabel_configs is relabeling applied to samples before sending themto the remote endpoint. Write relabeling is applied after external labels. Thiscould be used to limit which samples are sent.

There is a small demo of how to usethis functionality.

  1. # The URL of the endpoint to send samples to.
  2. url: <string>
  3. # Timeout for requests to the remote write endpoint.
  4. [ remote_timeout: <duration> | default = 30s ]
  5. # List of remote write relabel configurations.
  6. write_relabel_configs:
  7. [ - <relabel_config> ... ]
  8. # Sets the `Authorization` header on every remote write request with the
  9. # configured username and password.
  10. # password and password_file are mutually exclusive.
  11. basic_auth:
  12. [ username: <string> ]
  13. [ password: <string> ]
  14. [ password_file: <string> ]
  15. # Sets the `Authorization` header on every remote write request with
  16. # the configured bearer token. It is mutually exclusive with `bearer_token_file`.
  17. [ bearer_token: <string> ]
  18. # Sets the `Authorization` header on every remote write request with the bearer token
  19. # read from the configured file. It is mutually exclusive with `bearer_token`.
  20. [ bearer_token_file: /path/to/bearer/token/file ]
  21. # Configures the remote write request's TLS settings.
  22. tls_config:
  23. [ <tls_config> ]
  24. # Optional proxy URL.
  25. [ proxy_url: <string> ]
  26. # Configures the queue used to write to remote storage.
  27. queue_config:
  28. # Number of samples to buffer per shard before we block reading of more
  29. # samples from the WAL. It is recommended to have enough capacity in each
  30. # shard to buffer several requests to keep throughput up while processing
  31. # occasional slow remote requests.
  32. [ capacity: <int> | default = 500 ]
  33. # Maximum number of shards, i.e. amount of concurrency.
  34. [ max_shards: <int> | default = 1000 ]
  35. # Minimum number of shards, i.e. amount of concurrency.
  36. [ min_shards: <int> | default = 1 ]
  37. # Maximum number of samples per send.
  38. [ max_samples_per_send: <int> | default = 100]
  39. # Maximum time a sample will wait in buffer.
  40. [ batch_send_deadline: <duration> | default = 5s ]
  41. # Initial retry delay. Gets doubled for every retry.
  42. [ min_backoff: <duration> | default = 30ms ]
  43. # Maximum retry delay.
  44. [ max_backoff: <duration> | default = 100ms ]

There is a list ofintegrationswith this feature.

<remote_read>

  1. # The URL of the endpoint to query from.
  2. url: <string>
  3. # An optional list of equality matchers which have to be
  4. # present in a selector to query the remote read endpoint.
  5. required_matchers:
  6. [ <labelname>: <labelvalue> ... ]
  7. # Timeout for requests to the remote read endpoint.
  8. [ remote_timeout: <duration> | default = 1m ]
  9. # Whether reads should be made for queries for time ranges that
  10. # the local storage should have complete data for.
  11. [ read_recent: <boolean> | default = false ]
  12. # Sets the `Authorization` header on every remote read request with the
  13. # configured username and password.
  14. # password and password_file are mutually exclusive.
  15. basic_auth:
  16. [ username: <string> ]
  17. [ password: <string> ]
  18. [ password_file: <string> ]
  19. # Sets the `Authorization` header on every remote read request with
  20. # the configured bearer token. It is mutually exclusive with `bearer_token_file`.
  21. [ bearer_token: <string> ]
  22. # Sets the `Authorization` header on every remote read request with the bearer token
  23. # read from the configured file. It is mutually exclusive with `bearer_token`.
  24. [ bearer_token_file: /path/to/bearer/token/file ]
  25. # Configures the remote read request's TLS settings.
  26. tls_config:
  27. [ <tls_config> ]
  28. # Optional proxy URL.
  29. [ proxy_url: <string> ]

There is a list ofintegrationswith this feature.