https://github.com/rahul-0000-code/server-grafana-integration
Integrating grafan for my server for various debugging
https://github.com/rahul-0000-code/server-grafana-integration
Last synced: about 1 year ago
JSON representation
Integrating grafan for my server for various debugging
- Host: GitHub
- URL: https://github.com/rahul-0000-code/server-grafana-integration
- Owner: rahul-0000-code
- Created: 2024-08-21T18:32:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-23T19:36:09.000Z (almost 2 years ago)
- Last Synced: 2025-01-29T08:44:31.284Z (over 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# server-monitoring in nodejs-grafana
## Goal
Setup monitoring with Prometheus and Grafana on localhost.
## Requirements
Nodejs, Docker. Grafana and some libraries
## Demo architecture

## Steps
1. Run Nodejs server: `npm install` and `node index.js`. Open http://localhost:9090. Show metrics with http://localhost:3000
2. Update file config prometheus-config.yml and **CHANGE TO YOUR IP**
3. Visit your running Prometheus and run [queries](https://prometheus.io/docs/prometheus/latest/querying/basics/).

**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. 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:
- name: DS_PROMETHEUS
- type: prometheus
- url: http://localhost:9090
- access: browser
**Create dashboard**
- [Import](https://grafana.com/docs/grafana/latest/dashboards/export-import/#import-dashboard) from grafana-dashboard.json.

## Reference
[1] Prometheus Docs - https://prometheus.io/docs
[2] Grafana Docs - https://grafana.com/docs/
[3] Prom-client - https://www.npmjs.com/package/prom-client