Reputation: 19660
I am running a node applications locally. It runs on http://localhost:3002
using prom-client i can see the metrics at the following endpoint http://localhost:3002/metrics.
I've setup prometheus in a docker container and ran it.
Dockerfile
FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/
prometheus.yml
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:3002']
labels:
service: 'my-service'
group: 'production'
rule_files:
- 'alert.rules'
docker build -t my-prometheus .
docker run -p 9090:9090 my-prometheus
When i navigate to http://localhost:9090/targets
it shows
Get http://localhost:3002/metrics: dial tcp 127.0.0.1:3002: connect: connection refused
Can you please tell me what im doing wrong here. node app is running on localhost at that port becasue when i go to http://localhost:3002/metrics
i can see the metrics.
Upvotes: 3
Views: 3225
Reputation: 652
I do this to localhost...success
global: scrape_interval: 5s scrape_timeout: 5s evaluation_interval: 1s scrape_configs:
Upvotes: 0
Reputation: 571
The applications are not in the same network. Firstly, you can create docker image from your node application too. When running docker images, network( --net
) parameter should be passed to both images.
Run prometheus app:
docker run --net basic -p 9090:9090 my-prometheus
Run nodejs app:
docker run --net basic -p 8080:8080 my-node-app
Now, the applications run in the same network that is called basic
. So the prometheus application can access the http://localhost:3002/metric
endpoint.
Upvotes: 0
Reputation: 1663
and for windows, it would be
- job_name: 'spring-actuator'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['docker.for.win.localhost:8082']
Upvotes: 1
Reputation: 31
When you are inside a container, you cannot access the localhost directly. You will need to add docker.for.mac.localhost to your prometheus.yml file. See below:
Your Job in prometheus.yml file. - job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- targets: ['docker.for.mac.localhost:3002']
Upvotes: 3