zabbix_export:
  version: '6.0'
  date: '2021-12-06T13:28:14Z'
  groups:
    -
      uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
      name: Templates/Applications
  templates:
    -
      uuid: 85ce114c802e4e28a5f3597e07d07032
      template: 'APP Kubernetes API server by HTTP'
      name: 'APP Kubernetes API server by HTTP'
      description: |
        Get Kubernetes API server metrics by HTTP agent from Prometheus metrics endpoint.
        For organization discovery template need to use Authorization via API token.
        
        Don't forget change macros {$KUBE.API.SERVER.URL}, {$KUBE.API.TOKEN}.
        Some metrics may not be collected depending on your Kubernetes API server instance version and configuration.
        
        You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback
        
        Template tooling version used: 0.39
      groups:
        -
          name: Templates/Applications
      items:
        -
          uuid: 28944ee2c0a3478e84612cd5650f3cd5
          name: 'Kubernetes_API: Request terminations, rate'
          type: DEPENDENT
          key: kubernetes.api.apiserver_request_terminations
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Number of requests which apiserver terminated in self-defense (Kubernetes 1.17+).'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "apiserver_request_terminations_total")].value.sum()'
              error_handler: DISCARD_VALUE
            -
              type: CHANGE_PER_SECOND
              parameters:
                - ''
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 54723f57a20a47a698fbf47cbec0f7a1
          name: 'Kubernetes_API: Audit events, total'
          type: DEPENDENT
          key: kubernetes.api.audit_event_total
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Accumulated number audit events generated and sent to the audit backend.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "apiserver_audit_event_total")].value.sum()'
              error_handler: DISCARD_VALUE
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: e4e3c570a55a48689c145c4a2310c597
          name: 'Kubernetes_API: Get API instance metrics json'
          type: HTTP_AGENT
          key: kubernetes.api.get_metrics
          history: '0'
          trends: '0'
          value_type: TEXT
          preprocessing:
            -
              type: PROMETHEUS_TO_JSON
              parameters:
                - ''
          timeout: 15s
          url: '{$KUBE.API.SERVER.URL}'
          headers:
            -
              name: Authorization
              value: 'Bearer {$KUBE.API.TOKEN}'
          tags:
            -
              tag: data
              value: raw
            -
              tag: target
              value: 'Kubernets API'
            -
              tag: transport
              value: http
        -
          uuid: e173bb0f5c454cdcad9c1421de27b1c8
          name: 'Kubernetes_API: Raw data'
          type: HTTP_AGENT
          key: kubernetes.api.get_metrics_raw
          history: '0'
          trends: '0'
          value_type: TEXT
          timeout: 15s
          url: '{$KUBE.API.SERVER.URL}'
          headers:
            -
              name: Authorization
              value: 'Bearer {$KUBE.API.TOKEN}'
          tags:
            -
              tag: data
              value: raw
            -
              tag: target
              value: 'Kubernets API'
            -
              tag: transport
              value: http
        -
          uuid: 79db985ac8f645999fe8aa73b4073bfb
          name: 'Kubernetes_API: Goroutines'
          type: DEPENDENT
          key: kubernetes.api.go_goroutines
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Number of goroutines that currently exist.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "go_goroutines")].value.sum()'
              error_handler: DISCARD_VALUE
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 2022d65c2f7a4f07bc1cba435a2be1e9
          name: 'Kubernetes_API: Go threads'
          type: DEPENDENT
          key: kubernetes.api.go_threads
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Number of OS threads created.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "go_threads")].value.first()'
              error_handler: DISCARD_VALUE
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 837c546cb3bc400ab7a62a672792f88b
          name: 'Kubernetes_API: gRPCs messages ressived, rate'
          type: DEPENDENT
          key: kubernetes.api.grpc_client_msg_received.rate
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Total number of gRPC stream messages received by the client.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "grpc_client_msg_received_total")].value.sum()'
              error_handler: DISCARD_VALUE
            -
              type: CHANGE_PER_SECOND
              parameters:
                - ''
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 353559f3b9684647a74bd429d80731b9
          name: 'Kubernetes_API: gRPCs messages sent, rate'
          type: DEPENDENT
          key: kubernetes.api.grpc_client_msg_sent.rate
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Total number of gRPC stream messages sent by the client.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "grpc_client_msg_sent_total")].value.sum()'
              error_handler: DISCARD_VALUE
            -
              type: CHANGE_PER_SECOND
              parameters:
                - ''
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 0850afe759684950be79135ed4f32c79
          name: 'Kubernetes_API: gRPCs client started, rate'
          type: DEPENDENT
          key: kubernetes.api.grpc_client_started.rate
          delay: '0'
          history: 7d
          value_type: FLOAT
          description: 'Total number of RPCs started on the client per second.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "grpc_client_started_total")].value.sum()'
              error_handler: DISCARD_VALUE
            -
              type: CHANGE_PER_SECOND
              parameters:
                - ''
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 53fd5211b6da47d3b3fc87ab8a2d0c33
          name: 'Kubernetes_API: Resident memory, bytes'
          type: DEPENDENT
          key: kubernetes.api.process_resident_memory_bytes
          delay: '0'
          history: 7d
          value_type: FLOAT
          units: B
          description: 'Virtual memory size in bytes.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "process_resident_memory_bytes")].value.first()'
              error_handler: DISCARD_VALUE
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
        -
          uuid: 010a983426c9407eb4b6bf7822b411ce
          name: 'Kubernetes_API: Virtual memory, bytes'
          type: DEPENDENT
          key: kubernetes.api.process_virtual_memory_bytes
          delay: '0'
          history: 7d
          value_type: FLOAT
          units: B
          description: 'Virtual memory size in bytes.'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "process_virtual_memory_bytes")].value.first()'
              error_handler: DISCARD_VALUE
          master_item:
            key: kubernetes.api.get_metrics
          tags:
            -
              tag: Application
              value: 'Kubernetes API'
      discovery_rules:
        -
          uuid: 7c5ffdbafc5e4e349cc62ed0d0c0f20f
          name: apiserver_request_duration_seconds_bucket
          type: DEPENDENT
          key: kubernetes.api.requests_bucket.discovery
          delay: '0'
          item_prototypes:
            -
              uuid: e14c1d8fd78643c5a8e84681afd85341
              name: 'Kubernetes_API: Requests bucket[{#RESOURCE}][{#SUBRESOURCE}][{#GROUP}][{#SCOPE}][{#VERB}][{#VERSION}]: {#LE}'
              type: DEPENDENT
              key: 'kubernetes.api.request_duration_seconds_bucket["{#SUBRESOURCE}","{#RESOURCE}","{#GROUP}","{#SCOPE}","{#VERB}","{#VERSION}","{#LE}"]'
              delay: '0'
              history: 7d
              value_type: FLOAT
              preprocessing:
                -
                  type: PROMETHEUS_PATTERN
                  parameters:
                    - 'apiserver_request_duration_seconds_bucket{le="{#LE}",subresource="{#SUBRESOURCE}",version="{#VERSION}",scope="{#SCOPE}",group="{#GROUP}",resource="{#RESOURCE}",verb="{#VERB}"}'
                    - value
                    - ''
              master_item:
                key: kubernetes.api.get_metrics_raw
              tags:
                -
                  tag: Application
                  value: 'Kubernetes API'
          master_item:
            key: kubernetes.api.get_metrics
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[?(@.name == "apiserver_request_duration_seconds_bucket")]'
              error_handler: DISCARD_VALUE
            -
              type: JAVASCRIPT
              parameters:
                - |
                  output = JSON.parse(value).map(function(item){
                       return {
                           "{#GROUP}": item.labels.group,
                           "{#RESOURCE}":item.labels.resource,
                           "{#SUBRESOURCE}":item.labels.subresource,
                           "{#LE}": item.labels.le,
                           "{#SCOPE}":item.labels.scope,
                           "{#VERB}":item.labels.verb,
                           "{#VERSION}":item.labels.version,
                  
                       }})
                    return JSON.stringify({"data": output})
            -
              type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - 1h
      macros:
        -
          macro: '{$KUBE.API.SERVER.URL}'
          value: 'http://localhost:8080'
          description: 'instance URL'
        -
          macro: '{$KUBE.API.TOKEN}'
          description: 'API Authorization Token'
      valuemaps:
        -
          uuid: 8cfed5f70a124df0a2457d7eef0a44d0
          name: healthcheck
          mappings:
            -
              value: '0'
              newvalue: Failed
            -
              value: '1'
              newvalue: Ok
