Getting Error "Get Http://localhost:9443/metrics: Dial Tcp 127.0.0.1:9443: Connect: Connection Refused"

Better Stack Team
Updated on November 18, 2024

The error message "Get <http://localhost:9443/metrics:> dial tcp 127.0.0.1:9443: connect: connection refused" indicates that your application or service is trying to reach the Prometheus metrics endpoint at localhost:9443, but it is unable to establish a connection. This can happen for several reasons. Here’s how you can troubleshoot and resolve this issue:

Common Causes and Solutions

  1. Prometheus Not Running:

    • Check if Prometheus is Running: Ensure that the Prometheus server is running. You can check its status with the command:

       
      ps aux | grep prometheus
      
 
- **Start Prometheus**: If it’s not running, you can start it using:

    ```bash
    ./prometheus --config.file=prometheus.yml
    ```
  1. Incorrect Port:
    • Verify the Port: Confirm that Prometheus is configured to listen on port 9443. Check your prometheus.yml configuration file for the web.listen-address setting.
    • Change the Port: If Prometheus is set to run on a different port, either update your service to connect to the correct port or change the Prometheus configuration.
  2. Firewall or Security Group Issues:

    • Check Firewall Settings: Ensure that there are no firewall rules blocking access to port 9443. You can check firewall rules using:

       
      sudo iptables -L
      
 
- **Open the Port**: If necessary, open the port using the appropriate command, e.g., for UFW:

    ```bash
    sudo ufw allow 9443
    ```
  1. Incorrect URL or Endpoint:
    • Validate the URL: Make sure you are using the correct URL for the metrics endpoint. The default metrics endpoint for Prometheus is usually http://localhost:9090/metrics. If you have a different service or exporter running on port 9443, ensure it is set up correctly.
  2. Service Not Binding to localhost:

    • Check Binding: Sometimes, services may not bind to localhost. Ensure that the service you're trying to access is listening on 127.0.0.1 or 0.0.0.0.
    • Check Listening Ports: You can use the following command to see which ports are currently listening:

       
      netstat -tuln | grep 9443
      
  3. Application Configuration:

    • Review Application Settings: If your application is supposed to expose metrics on localhost:9443, verify that it is correctly configured to start an HTTP server on that port.
  4. Logs for Additional Insights:

    • Check Application Logs: Look at the logs for the application or service trying to connect to see if there are any additional error messages or issues reported.
    • Prometheus Logs: If Prometheus is running, check its logs for any errors that might indicate why it’s not accepting connections.

Conclusion

The "Connection Refused" error can stem from various issues, including the service not running, misconfiguration, or network/firewall settings. By systematically checking these areas, you should be able to identify and resolve the problem.

Got an article suggestion? Let us know
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github