|
| 1 | +# Monitoring Docker Containers with OpenTelemetry and Last9 |
| 2 | + |
| 3 | +A guide for setting up Docker container monitoring using OpenTelemetry Collector with Last9. It collects container metrics, and logs from docker containers and sends them to Last9. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### 1. Prerequisites |
| 8 | + |
| 9 | +Ensure Docker and Docker Compose are installed on your system: |
| 10 | + |
| 11 | +```bash |
| 12 | +# Check Docker installation |
| 13 | +docker --version |
| 14 | + |
| 15 | +# Check Docker Compose installation |
| 16 | +docker compose version |
| 17 | +``` |
| 18 | + |
| 19 | +### 2. Configure OpenTelemetry Collector |
| 20 | + |
| 21 | +The setup uses the `otel-config.yaml` file which defines: |
| 22 | +- Docker stats receiver for container metrics |
| 23 | +- TCP log receiver for container logs |
| 24 | +- Processors for batch processing and resource detection |
| 25 | +- Last9 exporter configuration |
| 26 | + |
| 27 | +Before proceeding, update the Last9 authorization token: |
| 28 | + |
| 29 | +```bash |
| 30 | +# Edit the config file |
| 31 | +nano otel-config.yaml |
| 32 | +``` |
| 33 | + |
| 34 | +In the `exporters` section, replace `<Last9 Basic Auth Token>` with your actual Last9 authorization auth header. You can get the auth header from [Last9 Integrations](https://app.last9.io/integrations). |
| 35 | + |
| 36 | +### 3. Set Up with Docker Compose |
| 37 | + |
| 38 | +This setup demonstrates how to monitor multiple Docker containers using multiple Docker Compose files to create a complete monitoring stack: |
| 39 | + |
| 40 | +#### Start Apache Server |
| 41 | + |
| 42 | +```bash |
| 43 | +docker compose -f apache-compose.yaml up -d |
| 44 | +``` |
| 45 | + |
| 46 | +This launches an Apache httpd server on port 8002. |
| 47 | + |
| 48 | +#### Start Nginx Server (Optional) |
| 49 | + |
| 50 | +```bash |
| 51 | +docker compose -f nginx-compose.yaml up -d |
| 52 | +``` |
| 53 | + |
| 54 | +This launches an Nginx server on port 8000. |
| 55 | + |
| 56 | +#### Start OpenTelemetry Collector |
| 57 | + |
| 58 | +```bash |
| 59 | +docker compose -f otel-compose.yaml up -d |
| 60 | +``` |
| 61 | + |
| 62 | +This starts: |
| 63 | +- OpenTelemetry Collector with the configuration from `otel-config.yaml` |
| 64 | +- Logspout container that forwards logs from Docker containers to the collector |
| 65 | + |
| 66 | +## Understanding the Setup |
| 67 | + |
| 68 | +### Docker Networks |
| 69 | + |
| 70 | +The setup creates three Docker networks: |
| 71 | +- `nginx_network`: Network for Nginx server |
| 72 | +- `apache_network`: Network for Apache server |
| 73 | +- `otel_network`: Network for OpenTelemetry components |
| 74 | + |
| 75 | +Logspout connects to all three networks to collect logs. |
| 76 | + |
| 77 | +### Container Metrics |
| 78 | + |
| 79 | +The OpenTelemetry Collector is configured to collect various metrics: |
| 80 | +- CPU usage and utilization |
| 81 | +- Memory usage and limits |
| 82 | +- Network I/O statistics |
| 83 | +- Block I/O information |
| 84 | +- Container process information |
| 85 | + |
| 86 | +### Log Collection |
| 87 | + |
| 88 | +Container logs are collected using Logspout and sent to OpenTelemetry Collector for processing before being exported to Last9. |
| 89 | + |
| 90 | +## Verification |
| 91 | + |
| 92 | +1. Verify the containers are running: |
| 93 | +```bash |
| 94 | +docker ps |
| 95 | +``` |
| 96 | + |
| 97 | +2. Test Apache server: |
| 98 | +```bash |
| 99 | +curl http://localhost:8002 |
| 100 | +``` |
| 101 | + |
| 102 | +3. Test Nginx server (if installed): |
| 103 | +```bash |
| 104 | +curl http://localhost:8000 |
| 105 | +``` |
| 106 | + |
| 107 | +4. Check OpenTelemetry Collector logs: |
| 108 | +```bash |
| 109 | +docker logs otel-collector |
| 110 | +``` |
| 111 | + |
| 112 | +## Troubleshooting |
| 113 | + |
| 114 | +1. Container issues: |
| 115 | +```bash |
| 116 | +# Check container status |
| 117 | +docker ps -a |
| 118 | + |
| 119 | +# View container logs |
| 120 | +docker logs apache-server |
| 121 | +docker logs nginx-server |
| 122 | +docker logs otel-collector |
| 123 | +docker logs logspout |
| 124 | +``` |
| 125 | + |
| 126 | +2. Network issues: |
| 127 | +```bash |
| 128 | +# List networks |
| 129 | +docker network ls |
| 130 | + |
| 131 | +# Inspect a network |
| 132 | +docker network inspect apache_network |
| 133 | +docker network inspect nginx_network |
| 134 | +docker network inspect otel_network |
| 135 | +``` |
| 136 | + |
| 137 | +3. OpenTelemetry Collector issues: |
| 138 | +```bash |
| 139 | +# Check configuration |
| 140 | +docker exec otel-collector cat /etc/otel-collector-config.yaml |
| 141 | + |
| 142 | +# Restart collector |
| 143 | +docker compose -f otel-compose.yaml restart otel-collector |
| 144 | +``` |
| 145 | + |
| 146 | +## Stopping the Stack |
| 147 | + |
| 148 | +```bash |
| 149 | +docker compose -f otel-compose.yaml down |
| 150 | +docker compose -f nginx-compose.yaml down |
| 151 | +docker compose -f apache-compose.yaml down |
| 152 | +``` |
0 commit comments