Prometheus&Grafana
的安装
Prometheus
下载地址:
https://prometheus.io/download/
Grafana
下载地址:
https://grafana.com/grafana/download
登录上面地址下载最新版本,因为旧版本可能对于比较新的dashbord不支持。
2.1
安装
Prometheus
Prometheus
基于
Golang
编写,编译后的软件包,不依赖于任何的第三方依赖。只需要
下载对应平台的二进制包,解压并且添加基本的配置即可正常启动
Prometheus Server
。
—————————————————————————————
2.1.1
上传安装包
上传
prometheus-2.26.0.linux-amd64.tar.gz
到虚拟机的
/opt/software
目录
2.1.2
解压安装包
(1)解压到
/opt/module
目录下
[atguigu@hadoop1 software]$ tar -zxvf prometheus-2.26.0.linux-amd64.tar.gz
-C /opt/module
(2)修改目录名
[atguigu@hadoop1 ~] cd /opt/module
[atguigu@hadoop1 module] mv prometheus-2.26.0.linux-amd64 prometheus-2.26.0
2.1.3
修改配置文件
prometheus.yml
[atguigu@hadoop1 prometheus-2.26.0]$ vim prometheus.yml
在
scrape_configs
配置项下添加配置:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['xx.xx.xx.xx:9090']
配置说明:
1
、
global
配置块:
控制
Prometheus
服务器的全局配置
➢
scrape_interval
:配置拉取数据的时间间隔,默认为
1
分钟。
➢
evaluation_interval
:规则验证(生成
alert
)的时间间隔,默认为
1
分钟。
2
、
rule_files
配置块:
规则配置文件
3
、
scrape_configs
配置块:
配置采集目标相关,
prometheus
监视的目标。
Prometheus
自身
的运行信息可以通过
HTTP
访问,所以
Prometheus
可以监控自己的运行数据。
➢
job_name
:监控作业的名称
➢
static_configs
:表示静态目标配置,就是固定从某个
target
拉取数据
➢
targets
: 指 定 监 控 的 目 标 , 其 实 就 是 从 哪 儿 拉 取 数 据 。
Prometheus
会 从
http://hadoop1:9090/metrics
上拉取数据。
Prometheus
是可以在运行时自动加载配置的。启动时需要添加:
--web.enable-lifecycle
2.1.4
启动
Prometheus Server
[atguigu@hadoop1 prometheus-2.26.0]$ nohup ./prometheus
--config.file=prometheus.yml > ./prometheus.log 2>&1 &
➢
浏览器输入:
http://xx.xx.xx.xx:9090/
➢
点击
Status
,选中
Targets
:
prometheus
是
up
状态,表示安装启动成功:
2.1.5 停止Prometheus
找到9090的进程杀掉即可
netstat -tlanp | grep 9090
2.2 Grafana
安装
2.2.1
上传并解压
(1)将
grafana-7.5.2.linux-amd64.tar.gz
上传至
/opt/software/
目录下,解压:
[atguigu@hadoop1 software]$ tar -zxvf grafana-7.5.2.linux-amd64.tar.gz -C
/opt/module/
(2)更改名字:
[atguigu@hadoop1 module]$ mv grafana-7.5.2.linux-amd64 grafana-7.5.2
2.2.2
启动
Grafana
[atguigu@hadoop1 grafana-7.5.2]$ nohup ./bin/grafana-server web > ./grafana.log 2>&1 &
打开
web
:
http://xx.xx.xx.xx:3000,
默认用户名和密码:
admin
2.3 Pushgateway安装
2.3.1下载Pushgateway
下载 pushgateway-1.2.0.linux-amd64.tar.gz 解压缩到指定目录
下载地址 https://github.com/prometheus/pushgateway/releases
2.3.2启动Pushgateway
nohup ./pushgateway > run.log 2>&1 &
2.3.3查看是否启动成功
http://xx.xx.xx.xx:9091/metrics
2.3.4把Pushgateway信息添加到Prometheus配置文件prometheus.yml中
- targets: ['xx.xx.xx.xx:9091']
service: pushgatewayservice