Question: I'm running a web app with address 127.0.0.1:5000 and am using the python client library for Prometheus. I use `start_http_server(8000)` from the example in their [docs](https://github.com/prometheus/client_python) to expose the metrics on that port. The application runs, but I get `[Errno 48] Address already in use` and the localhost:8000 doesn't connect to anything when I try hitting it.

If I can't start two servers from one web app, then what port should I pass into `start_http_server()` in order to expose the metrics?

There is nothing already running on either port before I start the app.

Answer: 
Some other process is utilizing the port (8000). To kill the process that is running on the port (8000), simply find the process\_id [pid] of the process.

```
lsof -i :8000

```

This will show you the processes running on the port 8000 like this: 

```
COMMAND   PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
python3 21271 hashed    3u  IPv4 1430288      0t0  TCP *:8000 (LISTEN)

```

You can kill the process using the kill command like this:

```
sudo kill -9 21271

```

Recheck if the process is killed using the same command

```
lsof -i :8000

```

There should be nothing on the stdout.
Port 8000 does not need to have a web server running on it for it to be already in use. Use your OS command line to find the process that is using up the port then kill it. If a service is also running that causes it to get spawned again, disable that process.

A simpler solution would be to use another port instead of 8000.

**EDIT:** Looks like it is a bug in Prometheus. [Github Issue](https://github.com/prometheus/client_python/issues/155)