How to monitor host machine by using elastic agent docker container

Container is isolated, which means i do not have enough privilege to access other container. What i did is to mount log files to elastic agent, but it does not solve metricbeat problem that can not access system stats.

This is my simple compose file, agent can collect postgres log but it can not retrieve postgres container system stats (e.g. cpu, network)

    hostname: agent-service-01
      - ...
      - logs:/var/logs:ro # collect logs
      - FLEET_ENROLL=1
      - FLEET_URL=https://efleet:8220
      - FLEET_CA=/usr/share/elastic-agent/certs/ca/ca.crt

    image: postgres:14.7
    hostname: pgsql-01
    command: postgres -c config_file=/usr/share/postgresql/postgresql.conf
      - ./elastic/logs/pgsql/:/var/log/postgresql/
      - ./elastic/config/postgresql.conf:/usr/share/postgresql/postgresql.conf
      - POSTGRES_USER=postgres

Im trying to avoid building dockerfile(docker image), so i wonder how let elastic agent can access system stats. Accessing Host Machine is a alternate solution since a host machine only install one application.

I read Run Elastic Agent on Kubernetes managed by Fleet | Fleet and Elastic Agent Guide [8.7] | Elastic, then i think if i can use install elastic agent outside container and it monitors host machine and docker container. But i need a couple of days to figure out if it works.

For now my expected is:


So many misunderstood in my last post. elastic-agent-managed-kubernetes.yaml almost solved all my questions. hostNetwork: true and hostPID: true are the keys to make everything go correctly.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.