一、Promethus(普罗米修斯)监控系统
- 能够安装prometheus服务器
- 能够通过安装node_exporter监控远程linux
- 能够通过安装mysqld_exporter监控远程mysql数据库
- 能够安装grafana
- 能够在grafana添加prometheus数据源
- 能够在grafana添加监控cpu负载的图形
- 能够在grafana图形显示mysql监控数据
1.概述
Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数据库的组合。适合监控docker容器。因为kubernetes(俗称k8s)的流行带动了prometheus的发展。
它的服务过程是这样的Prometheus daemon负责定时去目标上抓取metrics(指标) 数据,每个抓取目标需要暴露一个http服务的接口给它定时抓取。
Prometheus:支持通过配置文件、文本文件、zookeeper、Consul、DNS SRV lookup等方式指定抓取目标。支持很多方式的图表可视化,例如十分精美的Grafana,自带的Promdash,以及自身提供的模版引擎等等,还提供HTTP API的查询方式,自定义所需要的输出。
Alertmanager:是独立于Prometheus的一个组件,可以支持Prometheus的查询语句,提供十分灵活的报警方式。
PushGateway:这个组件是支持Client主动推送metrics到PushGateway,而Prometheus只是定时去Gateway上抓取数据
2.时间序列数据
时间序列数据(TimeSeries Data) : 按照时间顺序记录系统、设备状态变化的数据被称为时序数据。
特点:
性能好
关系型数据库对于大规模数据的处理性能糟糕。NOSQL可以比较好的处理大规模数据,让依然比不上时间序列数据库。
成本低
高效的压缩算法,节省存储空间,有效降低IO
Prometheus有着非常高效的时间序列数据存储方法,每个采样数据仅仅占用3.5byte左右空间,上百万条时间序列,30秒间隔,保留60天,大概花了200多G(来自官方数据)
特征:
- 多维度数据模型
- 灵活的查询语言(PromQL)
- 不依赖分布式存储,单个服务器节点是自治的
- 以HTTP方式,通过pull模型拉去时间序列数据
- 也可以通过中间网关支持push模型
- 通过服务发现或者静态配置,来发现目标服务对象
- 支持多种多样的图表和界面展示
3.部署
从 //prometheus.io/download/ 下载相应版本,安装到服务器上官网提供的是二进制版,解压就能用,不需要编译。
4.启动
[root@gdx1 ~]# cd /usr/local/prometheus-2.25.0.linux-amd64/ [root@gdx1 prometheus-2.25.0.linux-amd64]# ./prometheus --config.file="prometheus.yml"5.监控远程Linux主机
#1.在远程主机(被监控端agent1)上安装node_exporter组件 [root@gdx2 ~]# tar xf node_exporter-1.1.1.linux-amd64.tar.gz -C /usr/local/ [root@gdx2 ~]# cd /usr/local/ [root@gdx2 local]# ll 总用量 0 drwxr-xr-x 2 3434 3434 56 2月 13 21:42 node_exporter-1.1.1.linux-amd64 [root@gdx2 local]# cd node_exporter-1.1.1.linux-amd64/ [root@gdx2 node_exporter-1.1.1.linux-amd64]# ll 总用量 18740 -rw-r--r-- 1 3434 3434 11357 2月 13 21:42 LICENSE -rwxr-xr-x 1 3434 3434 19170241 2月 13 21:31 node_exporter -rw-r--r-- 1 3434 3434 463 2月 13 21:42 NOTICE [root@gdx2 node_exporter-1.1.1.linux-amd64]# ./node_exporter #2.回到Prometheus服务器的配置文件里添加被监控机器的配置段 [root@gdx1 prometheus-2.25.0.linux-amd64]# vim prometheus.yml - job_name: 'Devops' static_configs: - targets: ['192.168.12.41:9100','192.168.12.12:9100'] #3.重启服务 [root@gdx1 ~]# cd /usr/local/prometheus-2.25.0.linux-amd64/ [root@gdx1 prometheus-2.25.0.linux-amd64]# ./prometheus --config.file="prometheus.yml" #注:可以通过浏览器访问`//被监控端IP:9100/metrics`就可以查看到node_exporter在被监控端收集的监控信息 #4.回到web管理界面 --> 点Status --> 点Targets --> 可以看到多了一台监控目标pv : 页面浏览量 6千万
uv : 独立用户浏览量 3~4千
QPS :每秒查询率 5~10万
6.监控MySQL
#1.在被监控端(被监控端agent1)安装mysqld_exporter组件 注:此处使用k8smaster节点部署MySQL容器来监控 [root@gdx1 ~]# wget //github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz [root@gdx1 ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/ [root@gdx1 ~]# cd /usr/local/mysqld_exporter-0.12.1.linux-amd64/ [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# ll 总用量 14484 -rw-r--r-- 1 3434 3434 11325 7月 29 2019 LICENSE -rwxr-xr-x 1 3434 3434 14813452 7月 29 2019 mysqld_exporter -rw-r--r-- 1 3434 3434 65 7月 29 2019 NOTICE #2.编写MySQL配置清单 部署pod [root@gdx1 yaml]# vim mysql.yaml kind: Deployment apiVersion: apps/v1 metadata: name: mysql spec: selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: nodeName: gdx1 containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "123456" --- kind: Service apiVersion: v1 metadata: name: mysql spec: ports: - port: 3306 targetPort: 3306 nodePort: 30306 selector: app: mysql type: NodePort [root@gdx1 yaml]# kubectl apply -f mysql.yaml #3.进入容器授权 [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# kubectl exec -it mysql-7b8d8b5cb4-wqwx4 -- bash mysql> grant select,replication client,process ON *.* to 'mysql_monitor'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #4.编写启动配置文件 [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# vim .my.cnf [client] user=mysql_monitor password=123456 port=30306 #5.启动监控 [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# ./mysqld_exporter --config.my-cnf=".my.cnf" #6.回到Prometheus服务器的配置文件里添加被监控机器的配置段 - job_name: 'mysql' static_configs: - targets: ['192.168.12.11:9104'] #7.重启服务 [root@gdx1 prometheus-2.25.0.linux-amd64]# ./prometheus --config.file="prometheus.yml"7.配置Grafana出图工具
1)什么是Grafana
Grafana是一个开源的度量分析和可视化工具,可以通过将采集的数据分析,查询,然后进行可视化的展示,并能实现报警。