Skip to content

Prometheus monitoring and dashboard Grafana with Nodejs server.

Notifications You must be signed in to change notification settings

vinhhung263/prometheus-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prometheus-nodejs

Goal

Setup monitoring with Prometheus and Grafana on localhost.

Requirements

Nodejs, Docker.

Demo architecture

Architecture  Demo

Steps

  1. Run Nodejs server: npm install and npm run start. Open http://localhost:3001. Show metrics with http://localhost:3001/metrics.

  2. Install Prometheus and update file config prometheus.yml and file rule.yaml (copy from /config).

    Run ./prometheus --config.file=prometheus.yml from folder you installed. Open Prometheus: http://localhost:9090.

  3. Visit your running Prometheus and run queries.

    Untitled2

    Request Per Minute

    sum(rate(http_request_duration_ms_count[1m])) by (service, route, method, code) * 60

    Error rate

    sum(increase(http_request_duration_ms_count{code=~"^5..$"}[1m])) / sum(increase(http_request_duration_ms_count[1m]))

    Median Response Time

    histogram_quantile(0.5, sum(rate(http_request_duration_ms_bucket[1m])) by (le, service, route, method))

    Average Memory Usage

    avg(nodejs_external_memory_bytes / 1024 / 1024) by (service)

  4. Install Prometheus Alertmanager and update file alertmanager.yml.

    Untitled3

    Run ./alertmanager --config.file=alertmanager.yml and open http://localhost:9093.

    Spam requests to test alert: curl http://localhost:3001/?[1-100].

  5. Run Grafana by Docker

    docker run -i -p 3000:3000 grafana/grafana. Open http://localhost:3000.

    Username: admin
    Password: admin
    

    Setting datasource

    Create a Grafana datasource with this settings:

    Create dashboard

    • Import from grafana-dashboard.json.

      Untitled

Reference

[1] RisingStack - https://github.com/RisingStack/example-prometheus-nodejs/

[2] Prometheus Docs - https://prometheus.io/docs

[3] Grafana Docs - https://grafana.com/docs/

[4] Prom-client - https://www.npmjs.com/package/prom-client

About

Prometheus monitoring and dashboard Grafana with Nodejs server.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published