普罗米修斯的灵感来自于谷歌的Borgmon。它最初是由马特·t·普劳德(Matt T. Proud)做为一个研究项目开发的,普劳德曾是谷歌(google)的一名雇员。在普劳德加入SoundCloud以后,他与另外一位工程师朱利叶斯•沃尔兹(Julius Volz)合做, 认真开发普罗米修斯。其余开发人员也参与了这项工做,并继续在SoundCloud内部进行开发,最终于2015年1月公开 发布。node
Prometheus的基本原理是经过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就能够接入监控。不须要任何SDK或者其余的集成过程。这样作很是适合作虚拟化环境监控系统,好比VM、Docker、Kubernetes等。输出被监控组件信息的HTTP接口被叫作exporter 。目前互联网公司经常使用的组件大部分都有exporter能够直接使用,好比Varnish、Haproxy、Nginx、MySQL、Linux系统信息(包括磁盘、内存、CPU、网络等等)。linux
Prometheus Server端安装ios
1.下载: wget https://github.com/prometheus/prometheus/releases/download/v2.8.0/prometheus-2.8.0.linux-amd64.tar.gz tar xf prometheus-2.8.0.linux-amd64.tar.gz -C /usr/local/ mv /usr/local/prometheus-2.8.0.linux-amd64 /usr/local/prometheus mkdir /usr/local/prometheus/data #数据存放目录 2.使用screen来管理Prometheus yum -y install screen screen #打开一个新的窗口 /usr/local/prometheus/prometheus --web.listen-address="0.0.0.0:9090" --web.read-timeout=5m --web.max-connections=10 --storage.tsdb.retention=15d --storage.tsdb.path="data/" --query.max-concurrency=20 --query.timeout=2m #C-a d 退出窗口,screen -ls查看后台进程 3.启动参数说明 --web.read-timeout=5m #请求连接的最⼤等待时间,防⽌太多的空闲连接 占⽤资源 --web.max-connections=512 #最⼤连接数 --storage.tsdb.retention=15d #prometheus开始采集监控数据后,对于保留期限的设置 --storage.tsdb.path="data/" #存储数据路径,wal目录保存着按照⼀定间隔的内存中近期的监控数据 --query.timeout=2m #防⽌单个⽤户执⾏过慢的查询 --query.max-concurrency=20 #容许多少用户同时查询 注:prometheus 对系统时间⾮常敏感,⼀定要时刻保证系统时间同步,否则曲线是乱的
Prometheus Client端安装 node_export插件git
wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz tar xf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/ mv /usr/local/node_exporter-0.17.0.linux-amd64 /usr/local/node_exporter 2.使用screen来管理Prometheus yum -y install screen screen #打开一个新的窗口 ./node_exporter --collector.systemd
Prometheus配置文件说明github
# 全局配置 global: scrape_interval: 15s # 多长时间抓取一次数据 evaluation_interval: 15s # 多长时间评估一次报警规则 scrape_timeout: 10s # 每次抓取数据的超时时间 # 告警配置 alerting: ... #这里咱们不使用prometheus自带的告警,使用无需关注 # 告警规则 rule_files: ... #制定了规则所在的位置,prometheus能够根据这个配置加载规则 # 定义Promeetheus监控那些资源 scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] #监控prometheus自己的健康状况 #添加客户端监控 - job_name: 'test' static_configs: - targets: ['jenkins:9100','gitlab:9100'] #此处主机名须要在/etc/hosts上定义。
注: 修改完配置文件须要重启prometheus, web上输入PrometheusIP:Prot查看页面。
web
Pushgateway是Prometheus 生态中一个重要工具,使用它的缘由主要是:vim
Pushgateway缺点:bash
Pushgateway的客户端采用push方式将数据发送到服务端,Prometheus只须要到Pushgateway拉取数据便可。Pushgateway能够单独运⾏在任何节点上的插件(并不⼀定要在被监控客户端)服务器
wget http://github.com/prometheus/pushgateway/releases/download/v0.7.0/pushgateway-0.7.0.linux-amd64.tar.gz tar xf pushgateway-0.7.0.linux-amd64.tar.gz -C /usr/local/ mv /usr/local/pushgateway-0.7.0.linux-amd64 /usr/local/pushgateway screen /usr/local/pushgateway/pushgateway
[root@nagios ~]# tail -3 /usr/local/prometheus/prometheus.yml - job_name: 'pushgateway' static_configs: - targets: ['localhost:9091'] #由于我将pushgateway装到了prometheus机器上因此使用的主机名是localhost,端口默认是9091。 #须要重启prometheus。
咱们来写一个监控客户端主机登录用户数量的脚本,将数据推送到pushgateway [root@jenkins_test ~]# cat user_login.sh #!/bin/bash count=$(w| awk 'NR==1{print $4}') label="Count_login_users" instance_name=$(hostname) echo "$label $count" | curl --data-binary @- http://192.168.18.213:9091/metrics/job/pushgateway/instance/$instance_name #job/pushgateway 推送到prometheus.yml的哪个job⾥。 #instance/$instance_name 推送后显⽰的机器名是什么。
编写的监控bash脚本是⼀次性执⾏的bash,咱们须要按时间段反复执⾏,因此呢?⾃然就得结合contab了。可是crontab默认只能最短⼀分钟的间隔,若是但愿⼩于⼀分钟的间隔15s,可使用以下方法: [root@jenkins_test ~]# cat user_login.sh #!/bin/bash for((i=1;i<=4;i++)); do count=$(w| awk 'NR==1{print $4}') label="Count_login_users" instance_name=$(hostname) echo "$label $count" | curl --data-binary @- http://192.168.18.213:9091/metrics/job/pushgateway/instance/$instance_name sleep 15 #等待15秒 done [root@jenkins_test ~]# crontab -l * * * * * /bin/bash /root/user_login.sh &>/dev/null
Grafana是一个跨平台的开源的度量分析和可视化工具,能够经过将采集的数据查询而后可视化的展现,并及时通知。它主要有如下几个特色:网络
wget https://dl.grafana.com/oss/release/grafana-6.0.1-1.x86_64.rpm #最新版本 yum localinstall -y grafana-6.0.1-1.x86_64.rpm #安装饼图插件 cd /var/lib/grafana/plugins/ git clone https://github.com/grafana/piechart-panel.git #修改配置文件 vim /etc/grafana/grafana.ini root_url = http://192.168.18.213:3000 #将localhost改成grafana服务端地址 #启动Grafana systemctl start grafana-server.service systemctl enable grafana-server.service
注: 默认运行在3000端口,web上输入IP:Prot查看页面,初始帐号密码为admin/admin。
编辑仪表盘属性