Description
Issue Summary
Title: Prometheus Nginxlog Exporter: Config File Unsupported File Type Error
Description:
I encountered an issue while setting up the prometheus-nginxlog-exporter
. Despite following the instructions to create a configuration file, the exporter fails to start, citing an "unsupported file type" error. Below are the detailed steps, error messages, and attempted resolutions.
Steps to Reproduce:
-
Environment Details:
- OS: CentOS 7
- Prometheus Nginxlog Exporter version: 1.11.0
-
Initial Configuration:
-
Created a configuration file
/opt/nginxlog-exporter.conf
in YAML format:log_file: /var/log/nginx/access.log metrics: - name: http_requests_total match: 'GET /' labels: method: GET - name: http_requests_total match: 'POST /' labels: method: POST
-
-
Service Configuration:
-
Created a systemd service file
/etc/systemd/system/nginxlog-exporter.service
:[Unit] Description=Prometheus Nginxlog Exporter After=network.target [Service] ExecStart=/opt/prometheus-nginxlog-exporter -config-file /opt/nginxlog-exporter.conf Restart=always [Install] WantedBy=multi-user.target
-
-
Errors Encountered:
- When starting the service, the following error is logged:
config file '/opt/nginxlog-exporter.conf' has unsupported file type
- When starting the service, the following error is logged:
Error Logs:
2024-06-14T17:33:07.870+0800 fatal prometheus-nginxlog-exporter/main.go:164 config file '/opt/nginxlog-exporter.conf' has unsupported file type
main.loadConfig
/home/runner/work/prometheus-nginxlog-exporter/prometheus-nginxlog-exporter/main.go:164
main.main
/home/runner/work/prometheus-nginxlog-exporter/prometheus-nginxlog-exporter/main.go:117
runtime.main
/opt/hostedtoolcache/go/1.18.10/x64/src/runtime/proc.go:250
Resolution Steps Taken:
-
Identified Issue with File Format:
- Realized that the
prometheus-nginxlog-exporter
expects an HCL (HashiCorp Configuration Language) formatted configuration file.
- Realized that the
-
Updated Configuration File to HCL Format:
-
Modified
/opt/nginxlog-exporter.conf
to the following HCL format:listen { port = 9113 } namespace "nginx" { format = "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\"" source { files = ["/var/log/nginx/access.log"] } labels { app = "nginx" } counters { request_count { help = "Number of HTTP requests" match = ".*" name = "http_requests_total" } } histograms { request_duration { help = "Histogram of request duration" match = ".*" name = "http_request_duration_seconds" buckets = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10] } } }
-
-
Manual Testing:
-
Ran the exporter manually to verify configuration:
/opt/prometheus-nginxlog-exporter -config-file /opt/nginxlog-exporter.conf
-
This command worked without errors.
-
-
Restarted Service:
-
Restarted the systemd service:
sudo systemctl start nginxlog-exporter sudo systemctl status nginxlog-exporter
-
-
Verified Prometheus Target:
- Checked Prometheus targets at
http://10.0.89.39:9090/targets
and confirmed that thenginxlog-exporter
is now running and reporting metrics.
- Checked Prometheus targets at
Conclusion:
The issue was caused by the incorrect file format for the configuration file. The exporter expects HCL format, not YAML. Updating the configuration file to HCL format resolved the issue.