How would I deploy Fortigate exporter for prometheus and integrate it into my existing…
- User
How would I deploy Fortigate exporter for prometheus and integrate it into my existing prometheus/grafana deployment?
- Assistant
How would I deploy Fortigate exporter for prometheus and integrate it into my existing prometheus/grafana deployment?
Deploying a FortiGate Exporter for Prometheus and integrating it into your existing Prometheus/Grafana setup involves several steps. This process enables you to monitor your FortiGate firewalls effectively by collecting metrics, scraping them with Prometheus, and visualizing them in Grafana. Below is a comprehensive guide to achieving this integration:
Before proceeding, ensure you have the following:
An Exporter is a tool that collects metrics from your application (in this case, FortiGate) and exposes them in a format that Prometheus can scrape. For FortiGate, exporters like fortigate_exporter are commonly used. This exporter interacts with the FortiGate API to gather metrics.
First, clone the exporter repository from GitHub. For this guide, we'll use andrewstuart/fortigate_exporter:
git clone https://github.com/andrewstuart/fortigate_exporter.git
cd fortigate_exporter
Ensure you have Go installed (preferably version 1.16 or higher). Build the exporter using:
go build -o fortigate_exporter main.go
Alternatively, you can download pre-built binaries from the releases page if available.
The exporter requires access to your FortiGate device. Set the necessary environment variables or use a configuration file. Common configurations include:
Example using environment variables:
export FORTIGATE_HOST=192.0.2.1
export FORTIGATE_PORT=443
export FORTIGATE_ACCESS_TOKEN=your_access_token_here
Ensure that the FortiGate API is enabled and properly configured to accept requests from the exporter’s IP.
Start the exporter:
./fortigate_exporter
By default, the exporter runs on port 9222. You can change this using command-line flags or environment variables as per the exporter’s documentation.
For production environments, it's advisable to run the exporter as a systemd service.
Create a service file /etc/systemd/system/fortigate_exporter.service:
[Unit]
Description=FortiGate Exporter
After=network.target
[Service]
User=exporter
Group=exporter
Environment="FORTIGATE_HOST=192.0.2.1"
Environment="FORTIGATE_PORT=443"
Environment="FORTIGATE_ACCESS_TOKEN=your_access_token_here"
ExecStart=/path/to/fortigate_exporter
Restart=always
[Install]
WantedBy=multi-user.target
Reload systemd and start the service:
sudo systemctl daemon-reload
sudo systemctl start fortigate_exporter
sudo systemctl enable fortigate_exporter
Add a new scrape job to your Prometheus prometheus.yml configuration file:
scrape_configs:
- job_name: 'fortigate'
static_configs:
- targets: ['<EXPORTER_HOST>:9222']
Replace <EXPORTER_HOST> with the hostname or IP address where the FortiGate Exporter is running.
If Prometheus is running with systemd:
sudo systemctl reload prometheus
Alternatively, send a SIGHUP to the Prometheus process or use the Prometheus web UI to reload the configuration.
Access the Prometheus web UI (usually at http://<prometheus_host>:9090) and navigate to Status > Targets to ensure the fortigate job is up and being scraped successfully.
To visualize FortiGate metrics, you can either:
Import Existing Dashboards:
Create Custom Dashboards:
Common metrics to display may include:
Example Prometheus Queries:
# Total inbound traffic
sum(rate(fortigate_traffic_in_bytes_total[5m])) by (interface)
# Total outbound traffic
sum(rate(fortigate_traffic_out_bytes_total[5m])) by (interface)
# CPU usage
fortigate_cpu_usage_percent
# Memory usage
fortigate_memory_usage_percent
Note: The actual metric names depend on the exporter’s implementation.
Using Prometheus alerting rules, you can set up alerts for critical metrics (e.g., high CPU usage, low memory). Configure these in your prometheus.yml or separate alerting files and integrate with Grafana Alerting if preferred.
9222) to trusted sources (e.g., Prometheus server).Exporter Not Reachable:
Authentication Errors:
No Metrics in Prometheus:
http://<EXPORTER_HOST>:9222/metrics in a browser or using curl.Grafana Dashboards Not Displaying Data:
By following these steps, you can successfully deploy a FortiGate Exporter, integrate it with your Prometheus server, and visualize FortiGate metrics in Grafana. This integration enhances your ability to monitor network security effectively and respond proactively to potential issues.
Not yet included in a published release.