【问题标题】:How to monitor Fastify app with Prometheus and Grafana?如何使用 Prometheus 和 Grafana 监控 Fastify 应用程序?
【发布时间】: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 upnpm run dev 之后,Fastify 应用程序已启动并运行,并且在 Prometheus 仪表板localhost:9090 中目标localhost:8081UP,我尝试执行一些指标。

我导入了 Node Exporter FullNode Exporter Server Metrics 仪表板。并添加了Prometheus数据源localhost:9090,命名为Fastify,并保存成功,显示Data source is working

但是,当我转到 Node Exporter Full 仪表板时,它没有显示任何数据。我在数据源中选择了Fastify,但它在左上角的其他选择中显示无。

请帮忙,我做错了什么?

【问题讨论】:

  • 检查仪表板中的部分变量。

标签: node.js docker docker-compose prometheus grafana


【解决方案1】:

您似乎正在使用一个用于 linux 统计信息的仪表板。为了在你的 Fastify 应用中使用 Prometheus/Grafana,你需要一个用于 Node.js 应用的仪表板。例如:

插入其中一个就可以了。

【讨论】:

    【解决方案2】:

    您应该在“fastify-metrics”端点中指定作业中的metrics_path,并更新目标参数:

    - job_name: 'node_exporter'
        scrape_interval: 5s
        metrics_path: /metrics
        scheme: http
        static_configs:
          - targets: ['localhost:8081']
            labels:
              group: 'node_exporter'
    

    【讨论】:

      猜你喜欢
      • 2021-06-17
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-12-30
      相关资源
      最近更新 更多