prometheus 监控PM2中的nodejs服务 Grafana展示

场景:

近期生产nodejs服务是用pm2去管理的,那么该如何使用prometheus进行监控告警呢?说干就干

1、在github上发现一个开源的exporterGitHub - saikatharryc/pm2-prometheus-exporter: :rabbit: pm2 prometheus exporter

废话不多说直接试试看吧。

pm2 install pm2-metrics

# 下载完成以后启动

pm2 start pm2-metrics

暴露的是9209端口,我们访问一下看看

http://<HOST>:9209/metrics

下面我们配置一下prometheus 的配置文件,添加一个job,重启prometheus

# test pm2
  - job_name: 'nodejs-app'
    static_configs:
    - targets: ['172.19.143.3:9209']

访问prometheus的targets 检查一下,可以看到是没问题的

那么好,如何绘图呢?首先,我去grafana的官网看了下有没有能直接用的Dashboard。

很遗憾,并没有 (图中的两个用不了,可能是版本原因吧,只有一两个表有数据)。

经过一番查找,找个一个能看的,上json

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 4,
  "links": [
    {
      "asDropdown": false,
      "icon": "external link",
      "includeVars": false,
      "keepTime": false,
      "tags": [],
      "targetBlank": false,
      "title": "New link",
      "tooltip": "",
      "type": "dashboards",
      "url": ""
    }
  ],
  "liveNow": false,
  "panels": [
    {
      "datasource": "Prometheus",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "fillOpacity": 70,
            "lineWidth": 0,
            "spanNulls": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": null
              },
              {
                "color": "green",
                "value": 1
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 5,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "links": [],
      "options": {
        "alignValue": "left",
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "mergeValues": true,
        "rowHeight": 0.9,
        "showValue": "auto",
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "8.5.2",
      "targets": [
        {
          "datasource": "Prometheus",
          "editorMode": "code",
          "exemplar": false,
          "expr": "pm2_up{name!=\"pm2-metrics\"}",
          "format": "time_series",
          "instant": false,
          "interval": "",
          "intervalFactor": 2,
          "legendFormat": "{
  {name}}",
          "range": true,
          "refId": "A",
          "step": 120
        }
      ],
      "title": "Status",
      "type": "state-timeline"
    },
    {
      "datasource": "Prometheus",
      "description": "Количество запущенных процессов (если больше одного, что-то не так)",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值