Prometheus 是一款面向云原生应用程序的开源监控工具,常用于监控微服务、操作系统、MySQL、Redis、Flink、RocketMQ / RabbitMQ / Kafka、K8S 等。

这里 Linux 选择 CentOS 7.2。

1. Prometheus安装

1.1 单机版安装

$ wget -P /usr/local http://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/LatestRelease/prometheus-2.31.1.linux-amd64.tar.gz
$ tar -zxvf /usr/local/prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local
$ ln -s /usr/local/prometheus-2.31.1.linux-amd64 /usr/local/prometheus  # 软链接
$ vim /usr/local/prometheus/prometheus.yml

编辑 prometheus.yml,将 global.scrape_interval 和 global.evaluation_interval 设置为 10s。

Prometheus 的启停命令:

$ nohup /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle > /usr/local/prometheus/nohup.out 2>&1 &   # 后台启动
$ fuser -n tcp 9090                         # 通过端口查询进程号
$ kill -9 <Prometheus PID>                  # 停止

–web.enable-lifecycle 表示开启动态更新配置功能,变更配置后通过 curl -X POST http://机器IP:9090/-/reload 重新加载 prometheus.yml。

访问 http://机器IP:9090/graph,就进入到了 Prometheus Graph 面板。

Prometheus metrics 页面:http://机器IP:9090/metrics

查看版本:

$ /usr/local/prometheus/prometheus --version

2. Grafana安装

Grafana 是开源的,功能齐全的度量仪表盘和图形编辑器,支持 Graphite,InfluxDB 和 OpenTSDB。

$ wget -P /usr/local https://repo.huaweicloud.com/grafana/7.5.10/grafana-7.5.10.linux-amd64.tar.gz
$ tar -zxvf /usr/local/grafana-7.5.10.linux-amd64.tar.gz -C /usr/local
$ ln -s /usr/local/grafana-7.5.10 /usr/local/grafana  # 软链接

Grafana 的启停命令:

$ nohup /usr/local/grafana/bin/grafana-server > /usr/local/grafana/nohup.out 2>&1 &   # 后台启动
$ fuser -n tcp 3000                         # 通过端口查询进程号
$ kill -9 <Grafana PID>                     # 停止

访问 http://机器IP:3000,就进入到了 Grafana 面板,默认用户名/密码 admin/admin。

添加数据源:

点击 Grafana 面板左侧 Configuration -> Data Sources 添加即可。

添加监控大盘:

Grafana 有很多现成的监控大盘模版 https://grafana.com/grafana/dashboards/

我们可以使用现成的模版添加大盘,比如添加 Node Exporter for Prometheus Dashboard CN

首先将模版的 json 下载下来,然后点击 Grafana 面板左侧的 Create -> Import 按钮导入 json 即可。

常用模版:

模版名称地址
Node Exporter for Prometheus Dashboard CNhttps://grafana.com/grafana/dashboards/8919
JVM (Micrometer)https://grafana.com/grafana/dashboards/4701
Spring Boot HikariCP / JDBChttps://grafana.com/grafana/dashboards/6083
Druid Connection Pool Dashboardhttps://grafana.com/grafana/dashboards/11157
MySQL Overviewhttps://grafana.com/grafana/dashboards/7362
Java Metrics与Docker系统接口监控概览https://grafana.com/grafana/dashboards/10341
NGINX Ingress controllerhttps://grafana.com/grafana/dashboards/9614
K8S for Prometheus Dashboardhttps://grafana.com/grafana/dashboards/13105

3. AlertManager安装

参考:
https://prometheus.io/
https://grafana.com/

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐