Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot read file nginxlog-exporter.conf #390

Open
scottie1996 opened this issue Jun 14, 2024 · 0 comments
Open

cannot read file nginxlog-exporter.conf #390

scottie1996 opened this issue Jun 14, 2024 · 0 comments
Labels

Comments

@scottie1996
Copy link

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:

  1. Environment Details:

    • OS: CentOS 7
    • Prometheus Nginxlog Exporter version: 1.11.0
  2. 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
  3. 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
  4. Errors Encountered:

    • When starting the service, the following error is logged:
      config file '/opt/nginxlog-exporter.conf' has unsupported file type
      

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:

  1. Identified Issue with File Format:

    • Realized that the prometheus-nginxlog-exporter expects an HCL (HashiCorp Configuration Language) formatted configuration file.
  2. 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]
          }
        }
      }
  3. Manual Testing:

    • Ran the exporter manually to verify configuration:

      /opt/prometheus-nginxlog-exporter -config-file /opt/nginxlog-exporter.conf
    • This command worked without errors.

  4. Restarted Service:

    • Restarted the systemd service:

      sudo systemctl start nginxlog-exporter
      sudo systemctl status nginxlog-exporter
  5. Verified Prometheus Target:

    • Checked Prometheus targets at http://10.0.89.39:9090/targets and confirmed that the nginxlog-exporter is now running and reporting metrics.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant