Actually starting prometheus
Course: Prometheus and Grafana - chapter 10
Let’s start an actual prometheus process that scrapes the linux machine

Until now, we’ve exposed a /metrics endpoint but no one is scraping using it.
Prometheus actually scrapes (pulls) these metrics so you can visualise them over time (time series data)
For that, you need to start prometheus and give it the source of the metrics
- Add
prometheus.yml
global: scrape_interval: 15s # How frequently to scrape targets
scrape_configs: - job_name: 'nodejs-app' static_configs: - targets: ['localhost:3000']- Start prometheus locally
docker run -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus💡 You can start it w/o docker as well by installing it from source
- Try visiting localhost:9090 , you will notice a problem in the
status/targetssection

💡 The problem is that nothing is running on port 3000 on the prom container, and hence it cant discover our service
Containerising the app
Section titled “Containerising the app”- Create a Dockerfile for the Node app
FROM node:20
# Create app directoryWORKDIR /usr/src/app
# Install app dependenciesCOPY package*.json ./
RUN npm install
# Bundle app sourceCOPY . .
EXPOSE 3000CMD [ "node", "app.js" ]- Create a docker-compose that starts the nodejs app as well as the prom container
version: '3.8'
services: node-app: build: ./ ports: - "3000:3000" networks: - monitoring
prometheus: image: prom/prometheus:latest volumes: - ./:/etc/prometheus ports: - "9090:9090" networks: - monitoring
networks: monitoring:- Update prometheus.yml
global: scrape_interval: 15s # How frequently to scrape targets
scrape_configs: - job_name: 'nodejs-app' static_configs: - targets: ['node-app:3000']- Start docker compose
docker-compose up-
Try going to http://localhost:9090/

-
Try executing a query
http_requests_total