Prometheus监控系统
Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数 据库的组合。
适合监控docker容器。因为kubernetes(俗称k8s)的流行带动 了prometheus的发展
Prometheus的主要特征
多维度数据模型 灵活的查询语言 不依赖分布式存储,单个服务器节点是自主的 以HTTP方式,通过pull模型拉去时间序列数据
也可以通过中间网关支持push模型 通过服务发现或者静态配置,来发现目标服务对象 支持多种多样的图表和界面展示
环境
Prometneus服务器 :192.168.81.130
被监控服务器 :192.168.81.131
grafana服务器 :192.168.81.130
- 可以连接外网
- 配置好hosts文件
# vim /etc/hosts
192.168.116.130 master
192.168.116.131 node
echo "
192.168.116.130 master
192.168.116.131 node">>/etc/hosts
- 时间同步
yum install -y ntpdate && ntpdate time.windows.com
- 关闭防火墙,selinux
# systemctl stop firewalld
# systemctl disable firewalld
# iptables -F
安装prometheus
下载上传二进制文件prometheus-2.5.0.linux-amd64.tar.gz和go1.8.3.linux-amd64.tar.gz的包
- 先安装和配置go语言
tar -xvf go1.8.3.linux-amd64.tar.gz -C /usr/local/go
vim /etc/profile
#配置环境变量
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
go version
出现下面版本,说明go语言安装成功
- 解压和移动prometheus
mkdir /usr/local/prometheus
tar -xvf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local/prometheus/
这个就是prometheus文件夹里面的文件
- 启动prometheus
#直接使用默认配置文件启动
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
#确认端口(9090)
netstat -tnlp |grep 9090
-
window访问页面
-
查看监控的服务器
只有本机服务一台服务
访问http://192.168.81.130:9090/metrics可以查看到监控的数据
在web主界面可以通过关键字查询监控项
- 监控远程Linux主机
node主机上面
在远程linux主机上安装node_exporter组件
下载地址: https://prometheus.io/download/
tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/exporter
如图,出现下图即可
master主机上面
修改vim /usr/local/prometheus/
- job_name: 'mysql' # 取一个job名称来代 表被监控的机器
static_configs:
- targets: ['192.168.81.131:9100'] # 这里改成被监控机器 的IP,后面端口接9100
#改完配置文件后,重启服务
pkill prometheus
#启动
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
有了另一个node节点,说明配置成功了
rate(node_network_receive_bytes_total[1m])查看网络连接状态