disabled: no

name: 'docker'

discover:
  - discoverer: docker
    docker:
      tags: "unknown"
      address: "unix:///var/run/docker.sock"

classify:
  - name: "Skip"
    selector: "unknown"
    tags: "skip"
    match:
      - tags: "skip"
        expr: |
          {{ $netNOK := eq .NetworkMode "host" -}}
          {{ $protoNOK := not (eq .PortProtocol "tcp") -}}
          {{ $portNOK := empty .PrivatePort -}}
          {{ $addrNOK := or (empty .IPAddress) (glob .PublicPortIP "*:*") -}}
          {{ or $netNOK $protoNOK $portNOK $addrNOK }}
  - name: "Applications"
    selector: "!skip unknown"
    tags: "-unknown app"
    match:
      - tags: "apache"
        expr: '{{ match "sp" .Image "httpd httpd:* */apache */apache:* */apache2 */apache2:*" }}'
      - tags: "beanstalk"
        expr: '{{ match "sp" .Image "*/beanstalkd */beanstalkd:*" }}'
      - tags: "boinc"
        expr: '{{ match "sp" .Image "boinc/client boinc/client:* */boinc */boinc:*" }}'
      - tags: "cockroachdb"
        expr: '{{ match "sp" .Image "cockroachdb/cockroach cockroachdb/cockroach:*" }}'
      - tags: "consul"
        expr: '{{ match "sp" .Image "consul consul:* */consul */consul:*" }}'
      - tags: "coredns"
        expr: '{{ match "sp" .Image "*/coredns */coredns:*" }}'
      - tags: "couchbase"
        expr: '{{ or (eq .PrivatePort "8091") (match "sp" .Image "couchbase couchbase:*") }}'
      - tags: "couchdb"
        expr: '{{ or (eq .PrivatePort "5984") (match "sp" .Image "couchdb couchdb:*") }}'
      - tags: "dovecot"
        expr: '{{ or (eq .PrivatePort "24242") (match "sp" .Image "*/dovecot */dovecot:*") }}'
      - tags: "elasticsearch"
        expr: '{{ or (eq .PrivatePort "9200") (match "sp" .Image "elasticsearch elasticsearch:* */elasticsearch */elasticsearch:* */opensearch */opensearch:*") }}'
      - tags: "gearman"
        expr: '{{ and (eq .PrivatePort "4730") (match "sp" .Image "*/gearmand */gearmand:*") }}'
      - tags: "ipfs"
        expr: '{{ and (eq .PrivatePort "5001") (match "sp" .Image "ipfs/kubo ipfs/kubo:*") }}'
      - tags: "lighttpd"
        expr: '{{ match "sp" .Image "*/lighttpd */lighttpd:*" }}'
      - tags: "maxscale"
        expr: '{{ or (eq .PrivatePort "8989") (match "sp" .Image "mariadb/maxscale mariadb/maxscale:*") }}'
      - tags: "memcached"
        expr: '{{ or (eq .PrivatePort "11211") (match "sp" .Image "memcached memcached:* */memcached */memcached:*") }}'
      - tags: "mongodb"
        expr: '{{ or (eq .PrivatePort "27017") (match "sp" .Image "mongo mongo:* */mongodb */mongodb:* */mongodb-community-server */mongodb-community-server:*") }}'
      - tags: "mysql"
        expr: '{{ or (eq .PrivatePort "3306") (match "sp" .Image "mysql mysql:* */mysql */mysql:* mariadb mariadb:* */mariadb */mariadb:* percona percona:* */percona-mysql */percona-mysql:*") }}'
      - tags: "nats"
        expr: '{{ and (eq .PrivatePort "8222") (match "sp" .Image "nats nats:*") }}'
      - tags: "nginx"
        expr: '{{ match "sp" .Image "nginx nginx:*" }}'
      - tags: "nginxunit"
        expr: '{{ match "sp" .Image "nginx/unit nginx/unit:*" }}'
      - tags: "oracledb"
        expr: '{{ and (eq .PrivatePort "1521" "2484") (match "sp" .Image "oracle/database oracle/database:*") }}'
      - tags: "pgbouncer"
        expr: '{{ or (eq .PrivatePort "6432") (match "sp" .Image "*/pgbouncer */pgbouncer:*") }}'
      - tags: "pika"
        expr: '{{ match "sp" .Image "pikadb/pika pikadb/pika:*" }}'
      - tags: "postgres"
        expr: '{{ or (eq .PrivatePort "5432") (match "sp" .Image "postgres postgres:* */postgres */postgres:* */postgresql */postgresql:*") }}'
      - tags: "proxysql"
        expr: '{{ or (eq .PrivatePort "6032") (match "sp" .Image "*/proxysql */proxysql:*") }}'
      - tags: "puppet"
        expr: '{{ or (eq .PrivatePort "8140") (match "sp" .Image "puppet/puppetserver puppet/puppetserver:*") }}'
      - tags: "rabbitmq"
        expr: '{{ or (eq .PrivatePort "15672") (match "sp" .Image "rabbitmq rabbitmq:* */rabbitmq */rabbitmq:*") }}'
      - tags: "redis"
        expr: '{{ or (eq .PrivatePort "6379") (match "sp" .Image "redis redis:* */redis */redis:*") }}'
      - tags: "rethinkdb"
        expr: '{{ and (eq .PrivatePort "28015") (match "sp" .Image "rethinkdb rethinkdb:* */rethinkdb */rethinkdb:*") }}'
      - tags: "squid"
        expr: '{{ match "sp" .Image "*/squid */squid:*" }}'
      - tags: "tengine"
        expr: '{{ match "sp" .Image "*/tengine */tengine:*" }}'
      - tags: "tor"
        expr: '{{ and (eq .PrivatePort "9051") (match "sp" .Image "*/tor */tor:*") }}'
      - tags: "tomcat"
        expr: '{{ match "sp" .Image "tomcat tomcat:* */tomcat */tomcat:*" }}'
      - tags: "typesense"
        expr: '{{ match "sp" .Image "typesense/typesense typesense/typesense:*" }}'
      - tags: "varnish"
        expr: '{{ match "sp" .Image "varnish varnish:*" }}'
      - tags: "vernemq"
        expr: '{{ match "sp" .Image "*/vernemq */vernemq:*" }}'
      - tags: "zookeeper"
        expr: '{{ or (eq .PrivatePort "2181") (match "sp" .Image "*/zookeeper */zookeeper:*") }}'
compose:
  - name: "Applications"
    selector: "app"
    config:
      - selector: "apache"
        template: |
          module: apache
          name: docker_{{.Name}}
          url: http://{{.Address}}/server-status?auto
      - selector: "beanstalk"
        template: |
          module: beanstalk
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "boinc"
        template: |
          module: boinc
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "cockroachdb"
        template: |
          module: cockroachdb
          name: docker_{{.Name}}
          url: http://{{.Address}}/_status/vars
      - selector: "consul"
        template: |
          module: consul
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "coredns"
        template: |
          module: coredns
          name: docker_{{.Name}}
          url: http://{{.Address}}/metrics
      - selector: "coredns"
        template: |
          module: coredns
          name: docker_{{.Name}}
          url: http://{{.Address}}/metrics
      - selector: "couchbase"
        template: |
          module: couchbase
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "couchdb"
        template: |
          module: couchdb
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "dovecot"
        template: |
          module: dovecot
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "elasticsearch"
        template: |
          module: elasticsearch
          name: docker_{{.Name}}
          {{ if glob .Image "*elastic*" -}}
          url: http://{{.Address}}
          {{ else -}}
          url: https://{{.Address}}
          tls_skip_verify: yes
          username: admin
          password: admin
          {{ end -}}
      - selector: "gearman"
        template: |
          module: gearman
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "ipfs"
        template: |
          module: ipfs
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "lighttpd"
        template: |
          module: lighttpd
          name: docker_{{.Name}}
          url: http://{{.Address}}/server-status?auto
      - selector: "maxscale"
        template: |
          module: maxscale
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "memcached"
        template: |
          module: memcached
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "mongodb"
        template: |
          module: mongodb
          name: docker_{{.Name}}
          uri: mongodb://{{.Address}}
      - selector: "mysql"
        template: |
          module: mysql
          name: docker_{{.Name}}
          dsn: netdata@tcp({{.Address}})/
      - selector: "nats"
        template: |
          - module: nats
            name: docker_{{.Name}}
            url: http://{{.Address}}
      - selector: "nginx"
        template: |
          - module: nginx
            name: docker_{{.Name}}
            url: http://{{.Address}}/stub_status
          - module: nginx
            name: docker_{{.Name}}
            url: http://{{.Address}}/basic_status
          - module: nginx
            name: docker_{{.Name}}
            url: http://{{.Address}}/nginx_status
          - module: nginx
            name: docker_{{.Name}}
            url: http://{{.Address}}/status
      - selector: "nginxunit"
        template: |
          - module: nginxunit
            name: docker_{{.Name}}
            url: http://{{.Address}}
      - selector: "oracledb"
        template: |
          module: oracledb
          name: docker_{{.Name}}
          {{ if eq .PrivatePort "1521" -}}
          dsn: 'oracle://username:password@{{.Address}}/XE'
          {{ else -}}
          dsn: 'oracle://username:password@{{.Address}}/XE?ssl=true&ssl verify=false'
          {{ end -}}
      - selector: "pgbouncer"
        template: |
          module: pgbouncer
          name: docker_{{.Name}}
          dsn: postgres://netdata:postgres@{{.Address}}/pgbouncer
      - selector: "pika"
        template: |
          module: pika
          name: docker_{{.Name}}
          address: redis://@{{.Address}}
      - selector: "rethinkdb"
        template: |
          module: rethinkdb
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "postgres"
        template: |
          module: postgres
          name: docker_{{.Name}}
          dsn: postgres://netdata:postgres@{{.Address}}/postgres
      - selector: "proxysql"
        template: |
          module: proxysql
          name: docker_{{.Name}}
          dsn: stats:stats@tcp({{.Address}})/
      - selector: "puppet"
        template: |
          module: puppet
          name: docker_{{.Name}}
          url: https://{{.Address}}
          tls_skip_verify: yes
      - selector: "rabbitmq"
        template: |
          module: rabbitmq
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "redis"
        template: |
          module: redis
          name: docker_{{.Name}}
          address: redis://@{{.Address}}
      - selector: "squid"
        template: |
          module: squid
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "tengine"
        template: |
          module: tengine
          name: docker_{{.Name}}
          url: http://{{.Address}}/us
      - selector: "tomcat"
        template: |
          module: tomcat
          name: docker_{{.Name}}
          url: http://{{.Address}}
      - selector: "typesense"
        template: |
          module: typesense
          name: docker_{{.Name}}
          url: http://{{.Address}}
          api_key: {{ trimPrefix "--api-key=" (regexFind "--api-key=[^ ]+" .Command) -}}
      - selector: "tor"
        template: |
          module: tor
          name: docker_{{.Name}}
          address: {{.Address}}
      - selector: "varnish"
        template: |
          module: varnish
          name: docker_{{.Name}}
          docker_container: {{.Name}}
      - selector: "vernemq"
        template: |
          module: vernemq
          name: docker_{{.Name}}
          url: http://{{.Address}}/metrics
      - selector: "zookeeper"
        template: |
          module: zookeeper
          name: docker_{{.Name}}
          address: {{.Address}}
