This guide provides instructions for deploying Logstash Exporter as a standalone application on a Linux system using systemd.
- A Linux server with systemd
- Access to download the Logstash Exporter binary
- Administrative privileges to create and manage systemd services
First, download the appropriate binary for your system from the GitHub releases page.
# Set the version and OS variables
VERSION="2.0.0" # Replace with the version you want to install
OS="linux" # Options: linux, darwin (macOS), windows
# Download the binary and checksum
wget "https://github.com/kuskoman/logstash-exporter/releases/download/v${VERSION}/logstash-exporter-${OS}"
wget "https://github.com/kuskoman/logstash-exporter/releases/download/v${VERSION}/logstash-exporter-${OS}.sha256"
# Verify the checksum
sha256sum -c logstash-exporter-${OS}.sha256
# Make the binary executable
chmod +x logstash-exporter-${OS}
# Move to /usr/local/bin for system-wide availability
sudo mv logstash-exporter-${OS} /usr/local/bin/logstash-exporter
Create a configuration file for the Logstash Exporter. The default location is config.yml
in the current directory, but you can specify a different location with the -config
flag.
# Create a directory for the configuration
sudo mkdir -p /etc/logstash-exporter
# Create a configuration file
sudo tee /etc/logstash-exporter/config.yml > /dev/null << 'EOF'
logstash:
instances:
- url: "http://localhost:9600" # Replace with your Logstash URL
timeout: 5s
server:
host: "0.0.0.0" # Listen on all interfaces
port: 9198 # Default port
logging:
level: "info" # Options: debug, info, warn, error
EOF
Create a systemd service file to manage the Logstash Exporter:
sudo tee /etc/systemd/system/logstash-exporter.service > /dev/null << 'EOF'
[Unit]
Description=Logstash Exporter
Documentation=https://github.com/kuskoman/logstash-exporter
After=network.target
[Service]
Type=simple
User=logstash-exporter
Group=logstash-exporter
ExecStart=/usr/local/bin/logstash-exporter -config /etc/logstash-exporter/config.yml
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
NoNewPrivileges=true
# Hardening
ProtectSystem=full
ProtectHome=true
ReadWritePaths=/var/log/logstash-exporter
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
For security reasons, it's best to run the Logstash Exporter as a non-privileged user:
# Create user and group
sudo useradd --system --shell /bin/false --home-dir /nonexistent logstash-exporter
# Create log directory if needed
sudo mkdir -p /var/log/logstash-exporter
sudo chown logstash-exporter:logstash-exporter /var/log/logstash-exporter
# Reload systemd to read the new service file
sudo systemctl daemon-reload
# Start the service
sudo systemctl start logstash-exporter
# Enable the service to start on boot
sudo systemctl enable logstash-exporter
# Check the status
sudo systemctl status logstash-exporter
You can verify that the Logstash Exporter is running correctly by checking its metrics endpoint:
curl http://localhost:9198/metrics
You should see Prometheus metrics in the response.
Add the following configuration to your Prometheus config to scrape metrics from the Logstash Exporter:
scrape_configs:
- job_name: 'logstash'
static_configs:
- targets: ['localhost:9198']
If the exporter is not working correctly, check the systemd logs:
sudo journalctl -u logstash-exporter -f
Ensure that the exporter can reach your Logstash instances:
curl http://localhost:9600
Make sure that port 9198 is open on your firewall:
sudo ufw status
# If using ufw, allow the port if needed
sudo ufw allow 9198/tcp
You can monitor multiple Logstash instances by adding them to your configuration file:
logstash:
instances:
- url: "http://logstash1:9600"
name: "logstash1" # Optional custom name
- url: "http://logstash2:9600"
name: "logstash2"
timeout: 5s
If you need to run the exporter on a different port:
server:
host: "0.0.0.0"
port: 8080 # Custom port
Update your systemd service if you change the port to ensure the correct ports are used.
To upgrade the Logstash Exporter:
- Download the new version
- Verify the checksum
- Stop the service:
sudo systemctl stop logstash-exporter
- Replace the binary:
sudo mv logstash-exporter-${OS} /usr/local/bin/logstash-exporter
- Start the service:
sudo systemctl start logstash-exporter
To completely remove the Logstash Exporter:
# Stop and disable the service
sudo systemctl stop logstash-exporter
sudo systemctl disable logstash-exporter
# Remove the service file
sudo rm /etc/systemd/system/logstash-exporter.service
sudo systemctl daemon-reload
# Remove the binary
sudo rm /usr/local/bin/logstash-exporter
# Remove the configuration
sudo rm -rf /etc/logstash-exporter
# Optionally remove the user
sudo userdel logstash-exporter
sudo rm -rf /var/log/logstash-exporter