A lightweight Go-based metrics collection service for Prometheus that monitors filesystem and directory sizes.
Image: ghcr.io/d0ugal/filesystem-exporter:v2.1.1
filesystem_exporter_volume_size_bytes: Total size of filesystem in bytesfilesystem_exporter_volume_available_bytes: Available space on filesystem in bytesfilesystem_exporter_volume_used_ratio: Ratio of used space (0.0 to 1.0)
filesystem_exporter_directory_size_bytes: Size of directory in bytes
filesystem_exporter_collection_duration_seconds: Duration of collection in secondsfilesystem_exporter_collection_success_total: Total number of successful collectionsfilesystem_exporter_collection_failed_total: Total number of failed collectionsfilesystem_exporter_collection_total: Total number of collections (successful and failed)
GET /: HTML dashboard with service status and metrics informationGET /metrics: Prometheus metrics endpointGET /health: Health check endpoint
version: '3.8'
services:
filesystem-exporter:
image: ghcr.io/d0ugal/filesystem-exporter:v2.1.1
ports:
- "8080:8080"
volumes:
- /:/host:ro
- ./config.yaml:/root/config.yaml:ro
restart: unless-stopped- Create a
config.yamlfile (see Configuration section) - Run:
docker-compose up -d - Access metrics:
curl http://localhost:8080/metrics
Create a config.yaml file to configure filesystems and directories to monitor:
server:
host: "0.0.0.0"
port: 8080
logging:
level: "info"
format: "json"
metrics:
collection:
default_interval: "5m"
filesystems:
- name: "root"
mount_point: "/"
device: "sda1"
interval: "1m"
directories:
home:
path: "/home"
subdirectory_levels: 1version: '3.8'
services:
filesystem-exporter:
image: ghcr.io/d0ugal/filesystem-exporter:v2.1.1
ports:
- "8080:8080"
volumes:
- /:/host:ro
environment:
- FILESYSTEM_EXPORTER_CONFIG_FROM_ENV=true
- FILESYSTEM_EXPORTER_FILESYSTEMS=root:/host:sda1:1m
- FILESYSTEM_EXPORTER_DIRECTORIES=home:/host/home:1:10m,logs:/host/var/log:0:5m
restart: unless-stoppedapiVersion: apps/v1
kind: Deployment
metadata:
name: filesystem-exporter
spec:
replicas: 1
selector:
matchLabels:
app: filesystem-exporter
template:
metadata:
labels:
app: filesystem-exporter
spec:
containers:
- name: filesystem-exporter
image: ghcr.io/d0ugal/filesystem-exporter:v2.1.1
ports:
- containerPort: 8080
env:
- name: FILESYSTEM_EXPORTER_CONFIG_FROM_ENV
value: "true"
- name: FILESYSTEM_EXPORTER_FILESYSTEMS
value: "root:/host:sda1:1m"
- name: FILESYSTEM_EXPORTER_DIRECTORIES
value: "home:/host/home:1:10m,logs:/host/var/log:0:5m"
volumeMounts:
- name: host-root
mountPath: /host
readOnly: true
volumes:
- name: host-root
hostPath:
path: /
type: Directory- Go 1.21 or later
- Docker (optional)
-
Install dependencies:
make deps
-
Run tests:
make test -
Build the application:
make build
-
Run the application:
make run
-
Build the Docker image:
make docker-build
-
Run the container:
make docker-run
Or build and run in one command:
make dockerRun all tests:
make testRun tests with coverage:
make test-coverageFormat code:
make fmtLint code:
make lintAdd to your prometheus.yml:
scrape_configs:
- job_name: 'filesystem-exporter'
static_configs:
- targets: ['filesystem-exporter:8080']- Permission Denied: Ensure the container has read access to the mounted volumes
- Command Not Found: The application requires
dfandducommands to be available - Configuration Errors: Check the YAML syntax in
config.yaml - High Memory Usage: Large directories with many subdirectories can consume significant memory
The application uses structured logging with JSON format. Log levels can be configured in the YAML configuration.
Enable debug logging to troubleshoot issues:
logging:
level: "debug"
format: "json"- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
This project is licensed under the MIT License.