|
| 1 | +# M-Lab Prometheus configuration. |
| 2 | + |
| 3 | +global: |
| 4 | + scrape_interval: 60s # Set the scrape interval to every 60 seconds. |
| 5 | + evaluation_interval: 60s # Evaluate rules every 60 seconds. |
| 6 | + # scrape_timeout is set to the global default (10s). |
| 7 | + |
| 8 | + # These labels are attached to any time series or alert sent to external |
| 9 | + # systems (federation, remote storage, Alertmanager). |
| 10 | + # TODO(soltesz): use this when M-Lab adds federation or alertmanager. |
| 11 | + external_labels: |
| 12 | + cluster: {{CLUSTER}} |
| 13 | + |
| 14 | + |
| 15 | +# Load rules once and periodically evaluate them according to the global |
| 16 | +# 'evaluation_interval'. |
| 17 | +rule_files: |
| 18 | + # - /etc/prometheus/rules.yml |
| 19 | + |
| 20 | +# Scrape configurations. |
| 21 | +# |
| 22 | +# Each job name defines monitoring targets (or a method for discovering |
| 23 | +# targets). |
| 24 | +# |
| 25 | +# The M-Lab Prometheus configuration uses three config types: |
| 26 | +# * automatically discovered services via kubernetes (kubernetes_sd_config) |
| 27 | +# * automatically discovered services via file (file_sd_config) |
| 28 | +# * static targets (static_config) |
| 29 | +# |
| 30 | +# Kubernetes targets are discovered automatically by querying the kubernetes |
| 31 | +# master API. The configuration for this is simplest when Prometheus runs in |
| 32 | +# the same cluster as the kubernetes master being monitored. In particular, |
| 33 | +# the master CA certificates and an authentication token are mounted |
| 34 | +# automatically in every container's filesystem for easy access. |
| 35 | +# |
| 36 | +# Discovery of legacy targets occurs by reading a configuration file. This |
| 37 | +# configuration file can be updated out of band after start and Prometheus will |
| 38 | +# periodically re-read the contents, adding new targets or removing old ones. |
| 39 | +# |
| 40 | +# Static targets cannot change after Prometheus starts. They are the least |
| 41 | +# flexible. Because of this, only well known, or long lived targets, or |
| 42 | +# singleton targets that need special relabeling rules should be static. |
| 43 | +scrape_configs: |
| 44 | + |
| 45 | + # Kubernetes configurations were inspired by: |
| 46 | + # https://github.com/prometheus/prometheus/blob/main/documentation/examples |
| 47 | + # |
| 48 | + # The four kubernetes scrape configs correspond to specific cluster |
| 49 | + # components. |
| 50 | + # * master API |
| 51 | + # * cluster nodes |
| 52 | + # * pods |
| 53 | + # * service endpoints |
| 54 | + # |
| 55 | + # The separation allows each component to use different authentication |
| 56 | + # configs, or apply different relabeling rules. |
| 57 | + |
| 58 | + # Scrape config for kubernetes master API server. |
| 59 | + # |
| 60 | + # The kubernetes API is exposed as an "endpoint". Since kubernetes may have |
| 61 | + # many endpoints, this configuration restricts the targets monitored to the |
| 62 | + # default/kubernetes service. The relabeling rules ignore other endpoints. |
| 63 | + - job_name: 'kubernetes-apiservers' |
| 64 | + kubernetes_sd_configs: |
| 65 | + - role: endpoints |
| 66 | + |
| 67 | + # The kubernetes API requires authentication and uses a privately signed |
| 68 | + # certificate. The tls_config specifies the private CA cert and an |
| 69 | + # auth token. Kubernetes automatically mounts these files in the container |
| 70 | + # filesystem. |
| 71 | + scheme: https |
| 72 | + tls_config: |
| 73 | + ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt |
| 74 | + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token |
| 75 | + |
| 76 | + # The source_labels are concatenated with ';'. The regex matches a single |
| 77 | + # value for the default kubernetes service endpoint. If there are |
| 78 | + # multiple API servers, all will match this pattern. |
| 79 | + relabel_configs: |
| 80 | + - source_labels: [__meta_kubernetes_namespace, |
| 81 | + __meta_kubernetes_service_name, |
| 82 | + __meta_kubernetes_endpoint_port_name] |
| 83 | + action: keep |
| 84 | + regex: default;kubernetes;https |
| 85 | + |
| 86 | + |
| 87 | + # Scrape config for kubernetes nodes. |
| 88 | + # |
| 89 | + # A kubernetes cluster consists of one or more nodes. Each reports metrics |
| 90 | + # related to the whole machine. |
| 91 | + - job_name: 'kubernetes-nodes' |
| 92 | + kubernetes_sd_configs: |
| 93 | + - role: node |
| 94 | + |
| 95 | + scheme: https |
| 96 | + tls_config: |
| 97 | + ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt |
| 98 | + |
| 99 | + # Nodes are discovered and scrapped using the kubernetes internal network |
| 100 | + # IP. Unfortunately, the certificates do not validate on requests: |
| 101 | + # |
| 102 | + # "x509: cannot validate certificate for 10.0.4.126 because it doesn't |
| 103 | + # contain any IP SANs" |
| 104 | + # |
| 105 | + # This is a known issue without a likely solution for private APIs: |
| 106 | + # https://github.com/prometheus/prometheus/issues/1822 |
| 107 | + # |
| 108 | + # Since these IPs are internal to the kubernetes virtual network, it |
| 109 | + # should be safe to skip certificate verification. |
| 110 | + insecure_skip_verify: true |
| 111 | + # TODO(soltesz): if we skip_verify, do we still need the bearer token? |
| 112 | + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token |
| 113 | + |
| 114 | + # Copy node labels from kubernetes to labels on the Prometheus metrics. |
| 115 | + # TODO(soltesz): There are many labels. Some look unnecessary. Restrict |
| 116 | + # pattern to match helpful labels. |
| 117 | + relabel_configs: |
| 118 | + - action: labelmap |
| 119 | + regex: __meta_kubernetes_node_label_(.+) |
| 120 | + # Node /metrics in v1.6+ are accessible via a proxy through the |
| 121 | + # kubernetes api server. So, we must update the target and metric path. |
| 122 | + - target_label: __address__ |
| 123 | + replacement: kubernetes.default.svc:443 |
| 124 | + - source_labels: [__meta_kubernetes_node_name] |
| 125 | + regex: (.+) |
| 126 | + target_label: __metrics_path__ |
| 127 | + replacement: /api/v1/nodes/${1}/proxy/metrics |
| 128 | + |
| 129 | + |
| 130 | + # Scrape config for kubernetes pods. |
| 131 | + # |
| 132 | + # Kubernetes pods are scraped when they have an annotation: |
| 133 | + # `prometheus.io/scrape=true`. |
| 134 | + # |
| 135 | + # Only container that include an explicit containerPort declaration are |
| 136 | + # scraped. For example: |
| 137 | + # |
| 138 | + # ports: |
| 139 | + # - containerPort: 9090 |
| 140 | + # |
| 141 | + # Configuration expects the default HTTP protocol scheme. |
| 142 | + # Configuration expects the default path of /metrics on targets. |
| 143 | + - job_name: 'kubernetes-pods' |
| 144 | + kubernetes_sd_configs: |
| 145 | + - role: pod |
| 146 | + |
| 147 | + relabel_configs: |
| 148 | + # For inventory, record whether a pod is ready. This helps distinguish |
| 149 | + # between: missing from inventory, not ready and failing, ready but |
| 150 | + # failing, ready and working. |
| 151 | + # and working. |
| 152 | + - source_labels: [__meta_kubernetes_pod_ready] |
| 153 | + action: replace |
| 154 | + target_label: ready |
| 155 | + |
| 156 | + # Check for the prometheus.io/scrape=true annotation. |
| 157 | + - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] |
| 158 | + action: keep |
| 159 | + regex: true |
| 160 | + |
| 161 | + # Only keep containers that have a declared container port. |
| 162 | + - source_labels: [__meta_kubernetes_pod_container_port_number] |
| 163 | + action: keep |
| 164 | + regex: (\d+) |
| 165 | + |
| 166 | + # Copy all pod labels from kubernetes to the Prometheus metrics. |
| 167 | + - action: labelmap |
| 168 | + regex: __meta_kubernetes_pod_label_(.+) |
| 169 | + |
| 170 | + # Add the kubernetes namespace as a Prometheus label. |
| 171 | + - source_labels: [__meta_kubernetes_namespace] |
| 172 | + action: replace |
| 173 | + target_label: namespace |
| 174 | + |
| 175 | + # Extract the "<cluster>-<node-pool>" name from the GKE node name. |
| 176 | + - source_labels: [__meta_kubernetes_pod_node_name] |
| 177 | + action: replace |
| 178 | + regex: gke-(.*)(-[^-]+){2} |
| 179 | + replacement: $1 |
| 180 | + target_label: nodepool |
| 181 | + |
| 182 | + # Identify the deployment name for replica set or daemon set. Pods |
| 183 | + # created by deployments or daemon sets are processed here. The |
| 184 | + # following two rules recognize these two cases. |
| 185 | + # |
| 186 | + # 1: For DaemonSet, remove the last 5-digit pod name hash. |
| 187 | + # e.g. node-exporter-ltxgz |
| 188 | + - source_labels: [__meta_kubernetes_pod_controller_kind, __meta_kubernetes_pod_name] |
| 189 | + action: replace |
| 190 | + regex: DaemonSet;(.*)(-[^-]{5}) |
| 191 | + replacement: $1 |
| 192 | + target_label: deployment |
| 193 | + |
| 194 | + # 2: For ReplicaSet, remove the last 10-digit + 5-digit pod name hash. |
| 195 | + # In the case of a daemon set that does not have the trailing hash, the |
| 196 | + # regex will not match and deployment remains unchanged. |
| 197 | + # e.g. prometheus-server-3165440997-ppf9w |
| 198 | + - source_labels: [__meta_kubernetes_pod_controller_kind, __meta_kubernetes_pod_name] |
| 199 | + action: replace |
| 200 | + regex: ReplicaSet;(.*)(-[^-]+)(-[^-]{5}) |
| 201 | + replacement: $1 |
| 202 | + target_label: deployment |
| 203 | + |
| 204 | + # TODO(soltesz): evaluate and remove from config if no-pod name is helpful |
| 205 | + # in practice. |
| 206 | + # |
| 207 | + # Add the kubernetes pod name. |
| 208 | + #- source_labels: [__meta_kubernetes_pod_name] |
| 209 | + # action: replace |
| 210 | + # target_label: pod |
| 211 | + |
| 212 | + # Add the kubernetes pod container name. |
| 213 | + - source_labels: [__meta_kubernetes_pod_container_name] |
| 214 | + action: replace |
| 215 | + target_label: container |
| 216 | + |
| 217 | + |
| 218 | + # Scrape config for kubernetes service endpoints. |
| 219 | + # |
| 220 | + # Service endpoints are scraped when they have an annotation: |
| 221 | + # `prometheus.io/scrape=true`. |
| 222 | + # |
| 223 | + # Port 80 is sraped by default. To use a different port, use the annotation: |
| 224 | + # `prometheus.io/port=9090`. |
| 225 | + # |
| 226 | + # Configuration expects the default HTTP protocol scheme. |
| 227 | + # Configuration expects the default path of /metrics on targets. |
| 228 | + - job_name: 'kubernetes-service-endpoints' |
| 229 | + kubernetes_sd_configs: |
| 230 | + - role: endpoints |
| 231 | + |
| 232 | + relabel_configs: |
| 233 | + # Check for the prometheus.io/scrape=true annotation. |
| 234 | + - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape] |
| 235 | + action: keep |
| 236 | + regex: true |
| 237 | + # Check for the prometheus.io/port=<port> annotation. |
| 238 | + - source_labels: [__address__, |
| 239 | + __meta_kubernetes_service_annotation_prometheus_io_port] |
| 240 | + action: replace |
| 241 | + target_label: __address__ |
| 242 | + # A google/re2 regex, matching addresses with or without default ports. |
| 243 | + # NB: this will not work with IPv6 addresses. But, atm, kubernetes uses |
| 244 | + # IPv4 addresses for internal network and GCE doesn not support IPv6. |
| 245 | + regex: ([^:]+)(?::\d+)?;(\d+) |
| 246 | + replacement: $1:$2 |
| 247 | + # Copy all service labels from kubernetes to the Prometheus metrics. |
| 248 | + - action: labelmap |
| 249 | + regex: __meta_kubernetes_service_label_(.+) |
| 250 | + # Add the kubernetes namespace as a Prometheus label. |
| 251 | + - source_labels: [__meta_kubernetes_namespace] |
| 252 | + action: replace |
| 253 | + target_label: kubernetes_namespace |
| 254 | + # Add the kubernetes service name as a Prometheus label. |
| 255 | + - source_labels: [__meta_kubernetes_service_name] |
| 256 | + action: replace |
| 257 | + target_label: kubernetes_name |
| 258 | + |
| 259 | + |
| 260 | + # Scrape byos-nodes every minute. |
| 261 | + - job_name: 'byos-nodes' |
| 262 | + scrape_timeout: 40s |
| 263 | + file_sd_configs: |
| 264 | + - files: |
| 265 | + - /byos-nodes/*.json |
| 266 | + # Attempt to re-read files every five minutes. |
| 267 | + refresh_interval: 5m |
| 268 | + scheme: http |
0 commit comments