我正在学习用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应用程序已经启动并运行,目标localhost:8081
是Prometheus仪表板中的UP
,localhost:9090
,我试着执行一些指标。
我导入了节点出口商完整和节点出口商服务器仪表板。并添加Prometheus数据源localhost:9090
,命名为Fastify
,并成功保存,显示了Data source is working
。
然而,当我进入节点出口商完整的仪表板时,它没有显示任何数据。我在数据源中选择了Fastify
,但在左上角的其他选择中没有显示任何选项。
请帮帮忙,我做错什么了?
发布于 2020-05-31 15:20:20
您应该将作业中的metrics_path指定为在“fastify-量度”端点中定义的,并更新目标param:
- job_name: 'node_exporter'
scrape_interval: 5s
metrics_path: /metrics
scheme: http
static_configs:
- targets: ['localhost:8081']
labels:
group: 'node_exporter'
发布于 2020-07-30 21:34:21
看起来您正在使用一个用于linux统计的仪表板。为了将Prometheus/Grafana与您的Fastify应用程序结合使用,您将需要一个用于Node.js应用程序的仪表板。例如:
把其中一个插进去就行了。
https://stackoverflow.com/questions/60798957
复制相似问题