apiVersion: v1
kind: ConfigMap
metadata:
  name: adapter-config
  namespace: monitoring
data:
  config.yaml: |
    rules:

    - seriesQuery: '{__name__="process_cpu_seconds_total",container_name!="POD",pod!="",job=~".*pods"}'
      seriesFilters:
      - is: ^process_cpu_seconds_total$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^process_cpu_seconds_total$
        as: "cpu_avg_ratio"
      metricsQuery: max(rate(process_cpu_seconds_total{<<.LabelMatchers>>}[5m])) by (<<.GroupBy>>)

    - seriesQuery: '{__name__=~"jvm_gc_collection_seconds_(count|sum)",container_name!="POD",pod!="",gc=~"(Copy|PS Scavenge)",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_gc_collection_seconds_(count|sum)$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_gc_collection_seconds_(count|sum)$
        as: "gc_minor_avg_seconds"
      metricsQuery: max(rate(jvm_gc_collection_seconds_sum{<<.LabelMatchers>>,gc=~"(Copy|PS Scavenge)"}[5m])/rate(jvm_gc_collection_seconds_count{<<.LabelMatchers>>,gc=~"(Copy|PS Scavenge)"}[5m])) by (<<.GroupBy>>)

    - seriesQuery: '{__name__=~"jvm_gc_collection_seconds_(count|sum)",container_name!="POD",pod!="",gc=~"(MarkSweepCompact|PS MarkSweep)",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_gc_collection_seconds_(count|sum)$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_gc_collection_seconds_(count|sum)$
        as: "gc_major_avg_seconds"
      metricsQuery: max(rate(jvm_gc_collection_seconds_sum{<<.LabelMatchers>>,gc=~"(MarkSweepCompact|PS MarkSweep)"}[5m])/rate(jvm_gc_collection_seconds_count{<<.LabelMatchers>>,gc=~"(MarkSweepCompact|PS MarkSweep)"}[5m])) by (<<.GroupBy>>)


    - seriesQuery: '{__name__=~"jvm_memory_bytes_(used|max)",container_name!="POD",pod!="",area="heap",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_memory_bytes_(used|max)$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_memory_bytes_(used|max)$
        as: "on_heap_ratio"
      metricsQuery: max(jvm_memory_bytes_used{<<.LabelMatchers>>}/jvm_memory_bytes_max{<<.LabelMatchers>>}) by (<<.GroupBy>>)

    - seriesQuery: '{__name__="GemFire_CacheServer_CurrentClients",container_name!="POD",namespace!="",pod!="",job=~".*pods"}'
      seriesFilters: []
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^GemFire_CacheServer_CurrentClients$
        as: "client_connections"
      metricsQuery: max(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>)

    - seriesQuery: '{__name__="jvm_memory_bytes_used",container_name!="POD",container_name!="POD",pod!="",area="nonheap",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_memory_bytes_used$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_memory_bytes_used$
        as: "off_heap"
      metricsQuery: max(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>)

    - seriesQuery: '{__name__="jvm_memory_bytes_max",container_name!="POD",container_name!="POD",pod!="",area="nonheap",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_memory_bytes_max$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_memory_bytes_max$
        as: "off_heap_max"
      metricsQuery: max(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>)

    - seriesQuery: '{__name__="jvm_memory_bytes_used",container_name!="POD",container_name!="POD",pod!="",area="heap",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_memory_bytes_used$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_memory_bytes_used$
        as: "on_heap"
      metricsQuery: max(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>)

    - seriesQuery: '{__name__="jvm_memory_bytes_max",container_name!="POD",container_name!="POD",pod!="",area="heap",job=~".*pods"}'
      seriesFilters:
      - is: ^jvm_memory_bytes_max$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod:
            resource: pod
          service:
            resource: service
      name:
        matches: ^jvm_memory_bytes_max$
        as: "on_heap_max"
      metricsQuery: max(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>)



    - seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}'
      seriesFilters: []
      resources:
        overrides:
          namespace:
            resource: namespace
          pod_name:
            resource: pod
      name:
        matches: ^container_(.*)_seconds_total$
        as: ""
      metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[1m])) by (<<.GroupBy>>)
    - seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}'
      seriesFilters:
      - isNot: ^container_.*_seconds_total$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod_name:
            resource: pod
      name:
        matches: ^container_(.*)_total$
        as: ""
      metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}[1m])) by (<<.GroupBy>>)
    - seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}'
      seriesFilters:
      - isNot: ^container_.*_total$
      resources:
        overrides:
          namespace:
            resource: namespace
          pod_name:
            resource: pod
      name:
        matches: ^container_(.*)$
        as: ""
      metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>,container_name!="POD"}) by (<<.GroupBy>>)
    - seriesQuery: '{namespace!="",__name__!~"^container_.*"}'
      seriesFilters:
      - isNot: .*_total$
      resources:
        template: <<.Resource>>
      name:
        matches: ""
        as: ""
      metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
    - seriesQuery: '{namespace!="",__name__!~"^container_.*"}'
      seriesFilters:
      - isNot: .*_seconds_total
      resources:
        template: <<.Resource>>
      name:
        matches: ^(.*)_total$
        as: ""
      metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)
    - seriesQuery: '{namespace!="",__name__!~"^container_.*"}'
      seriesFilters: []
      resources:
        template: <<.Resource>>
      name:
        matches: ^(.*)_seconds_total$
        as: ""
      metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)

    resourceRules:
      cpu:
        containerQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)
        nodeQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>, id='/'}[1m])) by (<<.GroupBy>>)
        resources:
          overrides:
            instance:
              resource: node
            namespace:
              resource: namespace
            pod_name:
              resource: pod
        containerLabel: container_name
      memory:
        containerQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>}) by (<<.GroupBy>>)
        nodeQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>,id='/'}) by (<<.GroupBy>>)
        resources:
          overrides:
            instance:
              resource: node
            namespace:
              resource: namespace
            pod_name:
              resource: pod
        containerLabel: container_name
      window: 1m
