prometheus-cfg.yaml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. ---
  2. kind: ConfigMap
  3. apiVersion: v1
  4. metadata:
  5. labels:
  6. app: prometheus
  7. name: prometheus-config
  8. namespace: monitoring
  9. data:
  10. prometheus.yml: |
  11. # A scrape configuration for running Prometheus on a Kubernetes cluster.
  12. # This uses separate scrape configs for cluster components (i.e. API server, node)
  13. # and services to allow each to use different authentication configs.
  14. #
  15. # Kubernetes labels will be added as Prometheus labels on metrics via the
  16. # `labelmap` relabeling action.
  17. #
  18. # If you are using Kubernetes 1.7.2 or earlier, please take note of the comments
  19. # for the kubernetes-cadvisor job; you will need to edit or remove this job.
  20. # Scrape config for API servers.
  21. #
  22. # Kubernetes exposes API servers as endpoints to the default/kubernetes
  23. # service so this uses `endpoints` role and uses relabelling to only keep
  24. # the endpoints associated with the default/kubernetes service using the
  25. # default named port `https`. This works for single API server deployments as
  26. # well as HA API server deployments.
  27. global:
  28. scrape_interval: 15s
  29. scrape_timeout: 10s
  30. evaluation_interval: 1m
  31. scrape_configs:
  32. - job_name: 'kubernetes-apiservers'
  33. kubernetes_sd_configs:
  34. - role: endpoints
  35. # Default to scraping over https. If required, just disable this or change to
  36. # `http`.
  37. scheme: https
  38. # This TLS & bearer token file config is used to connect to the actual scrape
  39. # endpoints for cluster components. This is separate to discovery auth
  40. # configuration because discovery & scraping are two separate concerns in
  41. # Prometheus. The discovery auth config is automatic if Prometheus runs inside
  42. # the cluster. Otherwise, more config options have to be provided within the
  43. # <kubernetes_sd_config>.
  44. tls_config:
  45. ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  46. # If your node certificates are self-signed or use a different CA to the
  47. # master CA, then disable certificate verification below. Note that
  48. # certificate verification is an integral part of a secure infrastructure
  49. # so this should only be disabled in a controlled environment. You can
  50. # disable certificate verification by uncommenting the line below.
  51. #
  52. # insecure_skip_verify: true
  53. bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  54. # Keep only the default/kubernetes service endpoints for the https port. This
  55. # will add targets for each API server which Kubernetes adds an endpoint to
  56. # the default/kubernetes service.
  57. relabel_configs:
  58. - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
  59. action: keep
  60. regex: default;kubernetes;https
  61. # Scrape config for nodes (kubelet).
  62. #
  63. # Rather than connecting directly to the node, the scrape is proxied though the
  64. # Kubernetes apiserver. This means it will work if Prometheus is running out of
  65. # cluster, or can't connect to nodes for some other reason (e.g. because of
  66. # firewalling).
  67. - job_name: 'kubernetes-nodes'
  68. # Default to scraping over https. If required, just disable this or change to
  69. # `http`.
  70. scheme: https
  71. # This TLS & bearer token file config is used to connect to the actual scrape
  72. # endpoints for cluster components. This is separate to discovery auth
  73. # configuration because discovery & scraping are two separate concerns in
  74. # Prometheus. The discovery auth config is automatic if Prometheus runs inside
  75. # the cluster. Otherwise, more config options have to be provided within the
  76. # <kubernetes_sd_config>.
  77. tls_config:
  78. ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  79. bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  80. kubernetes_sd_configs:
  81. - role: node
  82. relabel_configs:
  83. - action: labelmap
  84. regex: __meta_kubernetes_node_label_(.+)
  85. - target_label: __address__
  86. replacement: kubernetes.default.svc:443
  87. - source_labels: [__meta_kubernetes_node_name]
  88. regex: (.+)
  89. target_label: __metrics_path__
  90. replacement: /api/v1/nodes/${1}/proxy/metrics
  91. # Scrape config for Kubelet cAdvisor.
  92. #
  93. # This is required for Kubernetes 1.7.3 and later, where cAdvisor metrics
  94. # (those whose names begin with 'container_') have been removed from the
  95. # Kubelet metrics endpoint. This job scrapes the cAdvisor endpoint to
  96. # retrieve those metrics.
  97. #
  98. # In Kubernetes 1.7.0-1.7.2, these metrics are only exposed on the cAdvisor
  99. # HTTP endpoint; use "replacement: /api/v1/nodes/${1}:4194/proxy/metrics"
  100. # in that case (and ensure cAdvisor's HTTP server hasn't been disabled with
  101. # the --cadvisor-port=0 Kubelet flag).
  102. #
  103. # This job is not necessary and should be removed in Kubernetes 1.6 and
  104. # earlier versions, or it will cause the metrics to be scraped twice.
  105. - job_name: 'kubernetes-cadvisor'
  106. # Default to scraping over https. If required, just disable this or change to
  107. # `http`.
  108. scheme: https
  109. # This TLS & bearer token file config is used to connect to the actual scrape
  110. # endpoints for cluster components. This is separate to discovery auth
  111. # configuration because discovery & scraping are two separate concerns in
  112. # Prometheus. The discovery auth config is automatic if Prometheus runs inside
  113. # the cluster. Otherwise, more config options have to be provided within the
  114. # <kubernetes_sd_config>.
  115. tls_config:
  116. ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  117. bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  118. kubernetes_sd_configs:
  119. - role: node
  120. relabel_configs:
  121. - action: labelmap
  122. regex: __meta_kubernetes_node_label_(.+)
  123. - target_label: __address__
  124. replacement: kubernetes.default.svc:443
  125. - source_labels: [__meta_kubernetes_node_name]
  126. regex: (.+)
  127. target_label: __metrics_path__
  128. replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor
  129. # Scrape config for service endpoints.
  130. #
  131. # The relabeling allows the actual service scrape endpoint to be configured
  132. # via the following annotations:
  133. #
  134. # * `prometheus.io/scrape`: Only scrape services that have a value of `true`
  135. # * `prometheus.io/scheme`: If the metrics endpoint is secured then you will need
  136. # to set this to `https` & most likely set the `tls_config` of the scrape config.
  137. # * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
  138. # * `prometheus.io/port`: If the metrics are exposed on a different port to the
  139. # service then set this appropriately.
  140. - job_name: 'kubernetes-service-endpoints'
  141. kubernetes_sd_configs:
  142. - role: endpoints
  143. relabel_configs:
  144. - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
  145. action: keep
  146. regex: true
  147. - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
  148. action: replace
  149. target_label: __scheme__
  150. regex: (https?)
  151. - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
  152. action: replace
  153. target_label: __metrics_path__
  154. regex: (.+)
  155. - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
  156. action: replace
  157. target_label: __address__
  158. regex: ([^:]+)(?::\d+)?;(\d+)
  159. replacement: $1:$2
  160. - action: labelmap
  161. regex: __meta_kubernetes_service_label_(.+)
  162. - source_labels: [__meta_kubernetes_namespace]
  163. action: replace
  164. target_label: kubernetes_namespace
  165. - source_labels: [__meta_kubernetes_service_name]
  166. action: replace
  167. target_label: kubernetes_name
  168. # Example scrape config for pods
  169. #
  170. # The relabeling allows the actual pod scrape endpoint to be configured via the
  171. # following annotations:
  172. #
  173. # * `prometheus.io/scrape`: Only scrape pods that have a value of `true`
  174. # * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
  175. # * `prometheus.io/port`: Scrape the pod on the indicated port instead of the
  176. # pod's declared ports (default is a port-free target if none are declared).
  177. - job_name: 'kubernetes-pods'
  178. # if you want to use metrics on jobs, set the below field to
  179. # true to prevent Prometheus from setting the `job` label
  180. # automatically.
  181. honor_labels: false
  182. kubernetes_sd_configs:
  183. - role: pod
  184. # skip verification so you can do HTTPS to pods
  185. tls_config:
  186. insecure_skip_verify: true
  187. # make sure your labels are in order
  188. relabel_configs:
  189. # these labels tell Prometheus to automatically attach source
  190. # pod and namespace information to each collected sample, so
  191. # that they'll be exposed in the custom metrics API automatically.
  192. - source_labels: [__meta_kubernetes_namespace]
  193. action: replace
  194. target_label: namespace
  195. - source_labels: [__meta_kubernetes_pod_name]
  196. action: replace
  197. target_label: pod
  198. # these labels tell Prometheus to look for
  199. # prometheus.io/{scrape,path,port} annotations to configure
  200. # how to scrape
  201. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
  202. action: keep
  203. regex: true
  204. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
  205. action: replace
  206. target_label: __metrics_path__
  207. regex: (.+)
  208. - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
  209. action: replace
  210. regex: ([^:]+)(?::\d+)?;(\d+)
  211. replacement: $1:$2
  212. target_label: __address__
  213. - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme]
  214. action: replace
  215. target_label: __scheme__
  216. regex: (.+)