【发布时间】:2020-07-03 01:18:09
【问题描述】:
我正在学习使用 Prometheus 和 Grafana 监控我的 Fastify 应用程序。首先,我安装了fastify-metrics 包并在 Fastify 应用中注册。
// app.ts
import metrics from 'fastify-metrics'
...
app.register(metrics, {
endpoint: '/metrics',
})
然后我在docker-compose.yml中设置Prometheus和Grafana:
version: "3.7"
services:
prometheus:
image: prom/prometheus:latest
volumes:
- prometheus_data:/prometheus
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
network_mode: host
ports:
- '9090:9090'
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
# - ./grafana/provisioning:/etc/grafana/provisioning
# - ./grafana/config.ini:/etc/grafana/config.ini
# - ./grafana/dashboards:/var/lib/grafana/dashboards
environment:
- GF_SECURITY_ADMIN_PASSWORD=ohno
depends_on:
- prometheus
network_mode: host
ports:
- '3000:3000'
volumes:
prometheus_data: {}
grafana_data: {}
我添加了network_mode=host,因为 Fastfy 应用程序将在 localhost:8081 运行。
这是 Prometheus 配置:
# prometheus.yml
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 1m
scrape_configs:
- job_name: 'prometheus'
# metrics_path: /metrics
static_configs:
- targets: [
'app:8081',
]
- job_name: 'node_exporter'
static_configs:
- targets: [
'localhost:8081',
]
在docker-compose up 和npm run dev 之后,Fastify 应用程序已启动并运行,并且在 Prometheus 仪表板localhost:9090 中目标localhost:8081 是UP,我尝试执行一些指标。
我导入了 Node Exporter Full 和 Node Exporter Server Metrics 仪表板。并添加了Prometheus数据源localhost:9090,命名为Fastify,并保存成功,显示Data source is working。
但是,当我转到 Node Exporter Full 仪表板时,它没有显示任何数据。我在数据源中选择了Fastify,但它在左上角的其他选择中显示无。
请帮忙,我做错了什么?
【问题讨论】:
-
检查仪表板中的部分变量。
标签: node.js docker docker-compose prometheus grafana