本文共 2917 字,大约阅读时间需要 9 分钟。
prometheus 是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB),prometheus是一个监控采集与数据存储框架(监控server端),具体采集什么数据依赖于具体的exporter(监控client端)
grafana是一个高颜值的监控绘图程序,也是一个可视化面板(Dashboard),grafana的厉害之处除了高颜值,还支持多种数据源(支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB作为数据源)、支持灵活丰富的dashboard配置选项
一、安装prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gztar -zxvf prometheus-2.5.0.linux-amd64.tar.gz -C /data/mv /data/prometheus-2.5.0.linux-amd64 /data/prometheus#依次下载并解压node_exporter、mysql_exporter
# 规则global:alerting: alertmanagers: - static_configs: - targets:rule_files:scrape_configs:- file_sd_configs: - files: - host.yml job_name: Host metrics_path: /metrics relabel_configs: - source_labels: [__address__] regex: (.*) target_label: instance replacement: $1 - source_labels: [__address__] regex: (.*) target_label: __address__ replacement: $1:9100- file_sd_configs: - files: - mysql.yml job_name: MySQL metrics_path: /metrics relabel_configs: - source_labels: [__address__] regex: (.*) target_label: instance replacement: $1 - source_labels: [__address__] regex: (.*) target_label: __address__ replacement: $1:9104- job_name: prometheus static_configs: - targets: - localhost:9090
启动prometheus进程
/data/prometheus/prometheus --storage.tsdb.retention=30d &# 30d表示prometheus只保留30天以内的数据
控制台查看
http://172.20.2.214:9090#访问,点击Status->Targets,查看刚prometheus.yml配置文件创建的job_name
https://grafana.com/grafana/download# grafana程序包https://github.com/percona/grafana-dashboards/releases# grafana-dashboards包wget https://github.com/percona/grafana-dashboards/archive/v1.16.0.tar.gz
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.3.4-1.x86_64.rpmyum localinstall grafana-5.3.4-1.x86_64.rpmsystemctl start grafana-server
a、打开grafana页面(默认账户密码:admin/admin,默认端口3000),配置数据来源。
b、点击+Add data source,HTTP的URL填写prometheus服务所在的服务器ip及服务端口,然后点击保存并测试。
grafana中导入grafana-dashboards
解压grafana-dashboards包,该包提供了大量的json格式文件的grafana dashboards,根据需要自行选择。a、添加prometheus主机为例,解压exporter压缩包
tar zxvf node_exporter-0.15.2.linux-amd64.tarmv node_exporter-0.15.2.linux-amd64 node_exporter
b、启动node_exporter程序
cd node_exporternohup ./node_exporter &
c、配置prometheus.yml文件,如果其中已定义了监控主机的配置文件host.yml,则只需把主机IP信息填入即可动态生效。
如果需要在添加新的实例,可直接把实例IP放在同一个targets下即可。
d、添加mysql监控
tar -zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz
nohup ./mysqld_exporter &
注意事项:如果grafana中没获取到数据,可检查配置的Data Sources中的name是否与监控项的一致
转载于:https://blog.51cto.com/somethingshare/2381264