Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
*/wsgi.py
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ FROM python:3.13-slim AS runtime

WORKDIR /app
ENV PYTHONUNBUFFERED=1
ENV APP_MODE=start
EXPOSE 8000

COPY scripts/entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

ARG APP_VERSION='undefined'
ENV APP_VERSION=${APP_VERSION}
Expand All @@ -25,4 +30,4 @@ COPY --from=builder /build/dist/*.whl ./dist/

RUN pip install ./dist/*.whl

CMD ["start"]
ENTRYPOINT ["/app/entrypoint.sh"]
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,63 @@ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -ti glefer/docker-v
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -ti glefer/docker-volumes-analyzer:0.1.0
```

## Running the Application in Different Modes

The application supports multiple modes of operation. You can specify the mode using the `APP_MODE` environment variable. The available modes are:

- **CLI mode** (`start`): Runs the application in command-line interface mode.
- **Web development mode** (`web`): Starts the application in web development mode.
- **Gunicorn mode** (`gunicorn`): Runs the application using Gunicorn as the WSGI server.

### Using Docker
You can run the application in different modes by setting the `APP_MODE` environment variable when running the Docker container.

#### CLI mode
```bash
docker run -e APP_MODE=start -v /var/run/docker.sock:/var/run/docker.sock glefer/docker-volumes-analyzer:latest
```

#### Web development mode
```bash
docker run -e APP_MODE=web -v /var/run/docker.sock:/var/run/docker.sock glefer/docker-volumes-analyzer:latest
```

#### Web production mode (gunicorn)
```bash
docker run -e APP_MODE=gunicorn -v /var/run/docker.sock:/var/run/docker.sock glefer/docker-volumes-analyzer:latest
```

### Using python locally
If you prefer to run the application locally without Docker, you can use the entrypoint.sh script directly. Make sure you have all dependencies installed via Poetry.


#### CLI mode
```bash
APP_MODE=start scripts/entrypoint.sh
```

#### Web development mode
```bash
APP_MODE=web scripts/entrypoint.sh
```

#### Web production mode (gunicorn)
```bash
APP_MODE=gunicorn scripts/entrypoint.sh
```

## Prometheus

When running the application in **web** or **gunicorn** mode, it exposes a Prometheus metrics endpoint at `/metrics`. This endpoint provides detailed metrics about Docker volumes, such as:

- Total number of Docker volumes.
- Size of individual Docker volumes (in bytes).

![Metrics](./doc/assets/metrics-endpoint.png)


For more information about the metrics exposed and how to integrate them with Prometheus, refer to the [Prometheus documentation](./doc/prometheus.md).

---

## Run tests
Expand All @@ -88,7 +145,6 @@ poetry shell
```

Formatting and checks:

```bash
poetry run pre-commit run --all-files
```
Expand Down
Binary file added doc/assets/metrics-endpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions doc/prometheus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Prometheus metrics endpoint
The following metrics are exposed by the Prometheus metrics endpoint:

- **`docker_volumes_total`**: The total number of Docker volumes currently available.
- **Type**: Gauge
- **Labels**: None
- **Example**: `docker_volumes_total 42`

- **`docker_volume_size_bytes`**: The size of each Docker volume in bytes.
- **Type**: Gauge
- **Labels**:
- `volume`: The name of the Docker volume.
- **Example**: `docker_volume_size_bytes{volume="my_volume"} 104857600`

## Accessing the Metrics Endpoint

The Prometheus metrics are exposed at the `/metrics` endpoint. Depending on the mode in which the application is running, you can access the endpoint as follows:

- **Web mode**: `http://<host>:8000/metrics`
- **Gunicorn mode**: `http://<host>:8000/metrics`

Replace `<host>` with the hostname or IP address where the application is running.

## Integrating with Prometheus

To scrape the metrics exposed by the application, add the following job configuration to your Prometheus configuration file (`prometheus.yml`):

```yaml
scrape_configs:
- job_name: "docker_volume_analyzer"
static_configs:
- targets: ["<host>:8000"]
194 changes: 193 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading