Prometheus 是一种领先的开源监控解决方案,用于指标和提醒。支持将维度数据与指标的键值标识符结合使用,提供 PromQL 查询语言,并通过为其他产品提供导出器来支持多项集成。使用 Stackdriver 收集器与 Cloud Monitoring 集成。

https://prometheus.io/download/

Prometheus

https://github.com/prometheus/prometheus/releases/download/v2.38.0/prometheus-2.38.0.linux-amd64.tar.gz

./prometheus
./prometheus --config.file=prometheus.yml --storage.tsdb.path="/data/" #可选指定参数
默认监控9090端口,带web-ui

node_exporter 客户端数据源
https://github.com/prometheus/node_exporter/releases/download/v1.4.0-rc.0/node_exporter-1.4.0-rc.0.linux-amd64.tar.gz
./node_exporter --web.listen-address 127.0.0.1:8080
默认9100端口
http://localhost:8080/metrics #可查看所有监控数据

配置Prometheus监控数据源

    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "aws_jp-node1"
    static_configs:
      - targets: ["ip:9100"]

Grafana

Grafana 是一个用来展示各种各样数据的开源软件
https://grafana.com/grafana/download
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.1.2.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-9.1.2.linux-amd64.tar.gz
./grafana-server web
默认监听3000端口
默认账号密码admin/admin

添加数据源

设置 >> Data Sources / Prometheus

添加官网数据模板

https://grafana.com/orgs/starsliao/dashboards
Import the dashboard template: 复制ID 16098
到面板导入 /dashboard/import

docker

被监控节点:docker run -d -p 9100:9100 prom/node-exporter
管理节点:

docker run -d -p 9090:9090 --name=prometheus --restart=always \
        -v /home/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
        -v /home/docker/prometheus/prometheus:/prometheus prom/prometheus \
        --config.file=/etc/prometheus/prometheus.yml \
        --storage.tsdb.path=/prometheus \
        --web.enable-admin-api \
        --web.enable-lifecycle
Grafana: docker run -d --restart=always --name=grafana \
-p 3000:3000 \
-v /home/docker/grafana:/var/lib/grafana \
grafana/grafana