kubelet-cadvisor-servmon.yaml 3.02 KB
Newer Older
Vũ Hoàng Nam's avatar
Vũ Hoàng Nam committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
{{- if and ((.Values.metaMonitoring).grafanaAgent).enabled .Values.metaMonitoring.grafanaAgent.metrics.scrapeK8s.enabled }}
{{- with .Values.metaMonitoring.serviceMonitor }}
{{- if .enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "tempo.resourceName" (dict "ctx" $ "component" "k8s-kubelet-cadvisor") }}
  namespace: {{ .namespace | default $.Release.Namespace | quote }}
  labels:
    {{- include "tempo.labels" (dict "ctx" $ "component" "meta-monitoring") | nindent 4 }}
    {{- with .labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  endpoints:
    - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
      {{- with .interval }}
      interval: {{ . }}
      {{- end }}
      {{- with .scrapeTimeout }}
      scrapeTimeout: {{ . }}
      {{- end }}
      port: https-metrics
      honorLabels: true # retain namespace label from kubelet
      relabelings:
        - replacement: kubelet # add so that e.g. up{} metric doesn't get clashes with the other endpoint
          targetLabel: source
        {{- with .relabelings }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      metricRelabelings:
        - action: keep
          regex: storage-{{ include "tempo.resourceName" (dict "ctx"  $) }}.*
          sourceLabels:
            - persistentvolumeclaim # present on kubelet_volume_stats* metrics
        - targetLabel: instance # replace so that the metrics work with the default metrics mixin
          sourceLabels:
            - node
      scheme: https
      tlsConfig:
        caFile: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
      {{- with .interval }}
      interval: {{ . }}
      {{- end }}
      {{- with .scrapeTimeout }}
      scrapeTimeout: {{ . }}
      {{- end }}
      path: /metrics/cadvisor
      port: https-metrics
      honorLabels: true # retain namespace label from cadvisor
      relabelings:
        - replacement: cadvisor # add so that e.g. up{} metric doesn't get clashes with the other endpoint
          targetLabel: source
        - targetLabel: instance # replace so that the metrics work with the default metrics mixin
          sourceLabels:
            - node
        {{- with .relabelings }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      metricRelabelings:
        - action: keep
          regex: {{ include "tempo.resourceName" (dict "ctx"  $) }}.*
          sourceLabels:
            - pod
      scheme: https
      tlsConfig:
        caFile: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  namespaceSelector:
    matchNames:
        # "default" is the default namespace in which the operator creates the kubelet service.
      - default
  selector:
    matchLabels:
      # This is a service added by the agent operator, so this labels is hardcoded to what the operator creates.
      app.kubernetes.io/name: kubelet
{{- end -}}
{{- end -}}
{{- end -}}