The Snap package is deprecated and will not be updated beyond 4.x releases. Please consider using Docker images instead.
Query Exporter can be installed from the Snap Store on systems that support Snaps.
Installation
Install the snap
sudo snap install query-exporter
Verify installation
Check that Query Exporter is installed:
Supported Databases
The Snap package includes drivers for the following databases:
- PostgreSQL (
postgresql://)
- MySQL (
mysql://)
- SQLite (
sqlite://)
- Microsoft SQL Server (
mssql://)
- IBM DB2 (
db2://) - x86_64 architecture only
Running as a Command
You can run Query Exporter directly from the command line:
query-exporter --config /path/to/config.yaml
Running as a Daemon Service
The Snap provides a daemon instance managed by Systemd.
Configuring the Daemon
Create configuration file
Create or edit the configuration file at the snap’s current directory:sudo nano /var/snap/query-exporter/current/config.yaml
Example configuration:databases:
postgres:
dsn: postgresql://user:password@localhost:5432/mydb
labels:
env: production
metrics:
user_count:
type: gauge
description: Number of users in the database
queries:
users:
interval: 60
databases: [postgres]
metrics: [user_count]
sql: SELECT COUNT(*) as user_count FROM users
Create .env file (optional)
Optionally, create a .env file for environment variables:sudo nano /var/snap/query-exporter/current/.env
Example content:QE_LOG_LEVEL=debug
QE_PROCESS_STATS=true
QE_PORT=9560
Restart the service
After creating or modifying the configuration, restart the daemon:sudo snap restart query-exporter
Verify the service is running
Check the service status:sudo snap services query-exporter
Check the logs:sudo snap logs query-exporter
Configuration Directory
All configuration files for the daemon must be placed in:
/var/snap/query-exporter/current/
This directory is automatically created when the snap is installed.
Directory Structure
/var/snap/query-exporter/current/
├── config.yaml # Main configuration file (required)
└── .env # Environment variables (optional)
Service Management
Start the Service
sudo snap start query-exporter
Stop the Service
sudo snap stop query-exporter
Restart the Service
sudo snap restart query-exporter
Check Service Status
sudo snap services query-exporter
View Service Logs
sudo snap logs query-exporter
Follow logs in real-time:
sudo snap logs query-exporter -f
Accessing Metrics
By default, the daemon listens on localhost:9560. Access metrics at:
http://localhost:9560/metrics
Changing the Port
To change the port, add it to your .env file:
QE_PORT=8080
QE_HOST=0.0.0.0
Then restart the service:
sudo snap restart query-exporter
Environment Variables
You can configure the daemon using environment variables in /var/snap/query-exporter/current/.env:
# Logging
QE_LOG_LEVEL=info
QE_LOG_FORMAT=json
# Network
QE_HOST=localhost
QE_PORT=9560
QE_METRICS_PATH=/metrics
# Features
QE_PROCESS_STATS=false
# Configuration
QE_CONFIG=config.yaml
Troubleshooting
Check Service Status
sudo snap services query-exporter
View Detailed Logs
sudo snap logs query-exporter -n=100
Test Configuration
Run Query Exporter manually to test configuration:
query-exporter --config /var/snap/query-exporter/current/config.yaml --check-only
Permissions Issues
Ensure configuration files have correct permissions:
sudo chown root:root /var/snap/query-exporter/current/config.yaml
sudo chmod 644 /var/snap/query-exporter/current/config.yaml
Upgrading
Update the snap to the latest available version:
sudo snap refresh query-exporter
Remember that the Snap will only be updated to 4.x releases. For newer versions, migrate to Docker deployment.
Uninstalling
To remove Query Exporter:
sudo snap remove query-exporter
This will remove the application but preserve configuration files in /var/snap/query-exporter/.
To remove configuration as well:
sudo snap remove --purge query-exporter
Migration to Docker
Since the Snap is deprecated, consider migrating to Docker:
Export your configuration
Copy your configuration files:mkdir -p ~/query-exporter-config
sudo cp /var/snap/query-exporter/current/config.yaml ~/query-exporter-config/
sudo cp /var/snap/query-exporter/current/.env ~/query-exporter-config/
Stop the Snap service
sudo snap stop query-exporter
Run with Docker
docker run --rm -d \
-p 9560:9560/tcp \
-v "$HOME/query-exporter-config:/config" \
--name query-exporter \
adonato/query-exporter:latest
Verify Docker deployment
Check that metrics are available:curl http://localhost:9560/metrics
Remove the Snap (optional)
Once Docker deployment is verified:sudo snap remove query-exporter