# Sample configuration file showing various configuration options
apiVersion: v1
kind: ConfigMap
metadata:
  name: collector-config
  namespace: wavefront-collector
data:
  collector.yaml: |
    clusterName: k8s-cluster
    enableDiscovery: true
    enableEvents: true
    flushInterval: 30s

    sinks:
    - proxyAddress: wavefront-proxy.default.svc.cluster.local:2878
      tags:
        env: non-production
        region: us-west-2

      filters:
        # Filter out infrequently used kube-state-metrics.
        metricBlacklist:
        - 'kube.configmap.annotations.gauge'
        - 'kube.configmap.metadata.resource.version.gauge'
        - 'kube.endpoint.*'
        - 'kube.job.owner.gauge'
        - 'kube.job.labels.gauge'
        - 'kube.job.spec.completions.gauge'
        - 'kube.job.spec.parallelism.gauge'
        - 'kube.job.status.start.time.gauge'
        - 'kube.limitrange.*'
        - 'kube.namespace.annotations.gauge'
        - 'kube.persistentvolume.*'
        - 'kube.persistentvolumeclaim.*'
        - 'kube.pod.container.resource.limits.*'
        - 'kube.pod.container.*.reason.gauge'
        - 'kube.pod.owner.gauge'
        - 'kube.pod.start.time.gauge'
        - 'kube.pod.status.scheduled.gauge'
        - 'kube.pod.status.scheduled.time.gauge'
        - 'kube.replicationcontroller.created.gauge'
        - 'kube.replicationcontroller.metadata.generation.gauge'
        - 'kube.replicationcontroller.spec.replicas.gauge'
        - 'kube.resourcequota.*'
        - 'kube.secret.*'
        - 'kube.statefulset.*'
        - 'kube.storageclass.*'
        # Filter out generated labels
        tagExclude:
        - 'label?controller?revision*'
        - 'label?pod?template*'
        - 'annotation_kubectl_kubernetes_io_last_applied_configuration'

    events:
      filters:
        tagWhitelist:
          namespace:
          - "default"

    sources:
      kubernetes_source:
        url: 'https://kubernetes.default.svc'
        kubeletPort: 10250
        kubeletHttps: true
        useServiceAccount: true
        insecure: true
        prefix: 'kubernetes.'

        filters:
          metricBlacklist:
          - 'kubernetes.sys_container.*'

      internal_stats_source:
        prefix: 'kubernetes.'

      kubernetes_state_source:
        prefix: 'kubernetes.'

      telegraf_sources:
      # empty list enables all host level telegraf plugins
      - plugins: []

      # example enabling a subset of host level telegraf plugins
      - plugins: [mem,net,netstat]

      # example enabling a single telegraf plugin with custom telegraf configuration
      - plugins: [disk]
        conf: |
          mount_points = ["/"]
          ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

      prometheus_sources:
      # collect metrics from the Kubernetes API server
      - url: 'https://kubernetes.default.svc.cluster.local:443/metrics'
        httpConfig:
          bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token'
          tls_config:
            ca_file: '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
            insecure_skip_verify: true
        prefix: 'kube.apiserver.'

        filters:
          metricWhitelist:
          - 'kube.apiserver.apiserver.*'
          - 'kube.apiserver.etcd.*'
          - 'kube.apiserver.process.*'

    # discovery rules for auto-discovery of pods and services
    discovery:
      plugins:

      ##########################################################################
      # Workload auto discovery
      ##########################################################################

      # activemq
      - name: activemq
        type: telegraf/activemq
        selectors:
          images:
          - "*activemq*"
        port: 8161
        conf: |
          server = "${host}"
          port = ${port}
          username = "admin"
          password = "admin"
          webadmin = "admin"

      # apache httpd
      - name: apache
        type: telegraf/apache
        selectors:
          images:
          - 'httpd*'
          - '*httpd*'
        port: 80
        conf: |
          urls = ["http://${host}:${port}/server-status?auto"]

      # consul
      - name: consul
        type: telegraf/consul
        selectors:
          images:
          - 'consul*'
        port: 8500
        conf: |
          address = "${host}:${port}"
          scheme = "http"

      # couchbase
      - name: couchbase
        type: telegraf/couchbase
        selectors:
          images:
          - 'couchbase/server:enterprise-6.0.1'
        port: 8091
        conf: |
          servers = ["http://Administrator:password@${host}:${port}"]

      # couchdb
      - name: couchdb
        type: telegraf/couchdb
        selectors:
          images:
          - '*couchdb*'
        port: 5984
        conf: |
          hosts = ["http://admin:password@${host}:${port}/_node/_local/_stats"]

      # elasticsearch
      - name: elasticsearch
        type: telegraf/elasticsearch
        selectors:
          images:
          - '*elastic*'
        port: 9200
        conf: |
          servers = ["http://${host}:${port}"]
          local = false
          cluster_health = true
          cluster_stats = true

      # HAProxy
      - name: haproxy
        type: telegraf/haproxy
        selectors:
          images:
          - "*haproxy*"
        port: 8181
        conf: |
          servers = ["http://username:password@${host}:${port}/haproxy?stats"]

      # memcached
      - name: memcached
        type: telegraf/memcached
        selectors:
          images:
          - 'memcached:*'
        port: 11211
        conf: |
          servers = ["${host}:${port}"]

      # mongodb
      - name: mongodb
        type: telegraf/mongodb
        selectors:
          images:
          - 'mongo*'
        port: 27017
        conf: |
          servers = ["mongodb://main_admin:abc123@${host}:${port}"]

      # mysql
      - name: mysql
        type: telegraf/mysql
        selectors:
          images:
          - "mysql*"
        collection:
          interval: "180s"
        port: 3306
        conf: |
          servers = ["root:password@tcp(${host}:${port})/?tls=false"]
          perf_events_statements_digest_text_limit  = 120
          perf_events_statements_limit              = 250
          perf_events_statements_time_limit         = 86400
          table_schema_databases                    = []
          gather_process_list                       = true
          gather_table_io_waits                     = true
          gather_table_lock_waits                   = true
          gather_index_io_waits                     = true
          gather_event_waits                        = true
          gather_file_events_stats                  = true
          interval_slow                             = "30m"

      # nginx
      - name: nginx
        type: telegraf/nginx
        selectors:
          images:
          - 'nginx*'
        port: 80
        conf: |
          urls = ["http://${host}:${port}/metrics"]

      # nginx_plus
      - name: nginx_plus
        type: telegraf/nginx_plus
        selectors:
          images:
          - 'nginxplus*'
        conf: |
          urls = ["http://${host}/api"]

      # rabbitmq
      - name: rabbitmq
        type: telegraf/rabbitmq
        selectors:
          images:
          - 'rabbitmq:*'
        port: 15672
        conf: |
          url = "http://${host}:${port}"
          username = "guest"
          password = "guest"

      # redis master and slaves
      - name: redis
        type: telegraf/redis
        selectors:
          images:
          - 'redis:*'
          - '*redis*'
        port: 6379
        scheme: "tcp"
        conf: |
          servers = ["${server}"]

      # riak
      - name: riak
        type: telegraf/riak
        selectors:
          images:
          - 'riak-kv:*'
          - '*riak-kv:*'
        port: 8098
        conf: |
          servers = ["http://${host}:${port}"]

      # zookeeper
      - name: zookeeper
        type: telegraf/zookeeper
        selectors:
          images:
          - '*zookeeper'
        port: 2181
        conf: |
          servers = ["${host}:${port}"]

      ##########################################################################
      # Kubernetes component auto discovery
      ##########################################################################

      # auto-discover kube DNS
      - name: kube-dns-discovery
        type: prometheus
        selectors:
          images:
          - '*kube-dns/sidecar*'
          labels:
            k8s-app:
            - kube-dns
        port: 10054
        path: /metrics
        scheme: http
        prefix: kube.dns.
        filters:
          metricWhitelist:
          - 'kube.dns.http.request.duration.microseconds'
          - 'kube.dns.http.request.size.bytes'
          - 'kube.dns.http.requests.total.counter'
          - 'kube.dns.http.response.size.bytes'
          - 'kube.dns.kubedns.dnsmasq.*'
          - 'kube.dns.process.*'

      # auto-discover coredns
      - name: coredns-discovery
        type: prometheus
        selectors:
          images:
          - '*coredns:*'
          labels:
            k8s-app:
            - kube-dns
        port: 9153
        path: /metrics
        scheme: http
        prefix: kube.coredns.
        filters:
          metricWhitelist:
          - 'kube.coredns.coredns.cache.*'
          - 'kube.coredns.coredns.dns.request.count.total.counter'
          - 'kube.coredns.coredns.dns.request.duration.seconds'
          - 'kube.coredns.coredns.dns.request.size.bytes'
          - 'kube.coredns.coredns.dns.request.type.count.total.counter'
          - 'kube.coredns.coredns.dns.response.rcode.count.total.counter'
          - 'kube.coredns.coredns.dns.response.size.bytes'
          - 'kube.coredns.process.*'
