# Instalación de Telegraf con Docker Compose

1. **Instalar Docker Desktop (si no está instalado)**
2. **Instalar InfluxDB 2.7 (si no está instalado)**
3. **Prepara una carpeta de trabajo**
   * Crea una carpeta sencilla en cualquier espacio que consideres oportuno, por ejemplo:\
     `C:\Users\TU_USUARIO\Desktop\docker\telegraf`
4. **Crea el archivo de configuración `telegraf.conf`**
   * Copia este contenido en un archivo llamado `telegraf.conf` dentro de esa carpeta:

{% code title="text" overflow="wrap" %}

```
[agent]
  interval = "10s"
  flush_interval = "10s"

[[inputs.cpu]]
  percpu = true
  totalcpu = true

[[inputs.mem]]
[[inputs.disk]]
[[inputs.diskio]]
[[inputs.net]]
[[inputs.system]]
[[inputs.processes]]
[[inputs.docker]]  # Solo si necesitas métricas de Docker (requiere montar el socket)

[[outputs.influxdb_v2]]
  urls = ["http://host.docker.internal:8086"]
  token = "mi_token_admin"
  organization = "imagina"
  bucket = "mi_bucket"
```

{% endcode %}

4. **Crea el Dockerfile**
   * Copia este contenido en un archivo llamado `Dockerfile` dentro de la misma carpeta (Cambia la versión si lo necesitas):

{% code title="text" overflow="wrap" %}

```
FROM telegraf:1.30.2

COPY telegraf.conf /etc/telegraf/telegraf.conf
```

{% endcode %}

5. **Crea el archivo `docker-compose.yml`**

Copia este contenido en un archivo llamado `docker-compose.yml` dentro de esa carpeta:

{% code title="text" overflow="wrap" %}

```
version: '3.8'

services:
  telegraf:
    build: .
    container_name: telegraf
    restart: unless-stopped
    environment:
      - HOST_PROC=/rootfs/proc
      - HOST_SYS=/rootfs/sys
      - HOST_ETC=/rootfs/etc
      - HOST_MOUNT_PREFIX=/rootfs
    volumes:
      - /:/rootfs:ro
      - /proc:/rootfs/proc:ro
      - /sys:/rootfs/sys:ro
      - /etc:/rootfs/etc:ro

```

{% endcode %}

4. **Construye y levanta el servicio**

   Abre una terminal (PowerShell o CMD) en la carpeta y ejecuta:

{% code title="Shell" overflow="wrap" %}

```sh
docker compose build
docker compose up -d
```

{% endcode %}

5. **Verifica que llegan los datos a InfluxDB**
   * Accede a la interfaz web de InfluxDB 2.7 ([`http://localhost:8086`](http://localhost:8086/)).
   * Ve a "Explore" y selecciona el bucket `mi_bucket`.
   * Deberías ver mediciones como `cpu`, `mem`, `disk`, etc.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://darioaplicano.gitbook.io/influxdb2.x/instalacion-y-configuracion-inicial/5.-telegraf/instalacion-de-telegraf-con-docker-compose.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
