# How to monitor host machine by using elastic agent docker container

**URL:** <https://discuss.elastic.co/t/how-to-monitor-host-machine-by-using-elastic-agent-docker-container/333938>\
**Category:** Elastic Agent\
**Tags:** filebeat, metricbeat\
**Created:** [May 21, 2023, 9:22am UTC](https://discuss.elastic.co/t/how-to-monitor-host-machine-by-using-elastic-agent-docker-container/333938 "2023-05-21T09:22:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kelvin\_Chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kelvin_chan/32/119470_2.png) [@Kelvin\_Chan](https://discuss.elastic.co/u/Kelvin_Chan)\
**Post date:** [May 21, 2023, 9:22am UTC](https://discuss.elastic.co/t/how-to-monitor-host-machine-by-using-elastic-agent-docker-container/333938/1 "2023-05-21T09:22:00Z")

</div>

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)

```yml
  agent:
    image: docker.elastic.co/beats/elastic-agent:${STACK_VERSION}
    hostname: agent-service-01
    volumes:
      - ...
      - logs:/var/logs:ro # collect logs
    environment:
      - FLEET_ENROLLMENT_TOKEN=<TOKEN>
      - FLEET_ENROLL=1
      - FLEET_URL=https://efleet:8220
      - FLEET_CA=/usr/share/elastic-agent/certs/ca/ca.crt

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

```

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.

---

<div class="post-metadata">

**Author:** ![Kelvin\_Chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kelvin_chan/32/119470_2.png) [@Kelvin\_Chan](https://discuss.elastic.co/u/Kelvin_Chan)\
**Post date:** [May 22, 2023, 5:34am UTC](https://discuss.elastic.co/t/how-to-monitor-host-machine-by-using-elastic-agent-docker-container/333938/2 "2023-05-22T05:34:33Z")

</div>

I read [Run Elastic Agent on Kubernetes managed by Fleet | Fleet and Elastic Agent Guide [8.7] | Elastic](https://www.elastic.co/guide/en/fleet/8.7/running-on-kubernetes-managed-by-fleet.html), 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:

![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/05a33d7c1deb7cc2c3ccde03da0a29226947eeb6.png)

---

<div class="post-metadata">

**Author:** ![Kelvin\_Chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kelvin_chan/32/119470_2.png) [@Kelvin\_Chan](https://discuss.elastic.co/u/Kelvin_Chan)\
**Post date:** [May 22, 2023, 9:05am UTC](https://discuss.elastic.co/t/how-to-monitor-host-machine-by-using-elastic-agent-docker-container/333938/3 "2023-05-22T09:05:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 19, 2023, 9:06am UTC](https://discuss.elastic.co/t/how-to-monitor-host-machine-by-using-elastic-agent-docker-container/333938/4 "2023-06-19T09:06:21Z")

</div>

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