Prometheus 和 Grafana 安装部署

Prometheus 是一套开源的系统监控报警框架。Prometheus 作为生态圈 Cloud Native Computing Foundation(简称:CNCF)中的重要一员,其活跃度仅次于 Kubernetes, 现已广泛用于 Kubernetes 集群的监控系统中。

每个人都应该使用Prometheus,它提供了自定义的时序监控功能,允许你instrument代码并在Grafana中以图形化的方式进行监视。你还可以搭建告警功能,当生产环境崩溃或延迟让顾客感到不满时,你能得到提醒。它同时还需要Grafana和kube-state-metrics chart。

Prometheus

网址

官方网址:https://prometheus.io/
GitHub网址:https://github.com/prometheus/prometheus
软件下载地址:https://prometheus.io/download/
第三方中文介绍:https://github.com/1046102779/prometheus

架构图

特点:

多维数据模型(有metric名称和键值对确定的时间序列)
灵活的查询语言
不依赖分布式存储
通过pull方式采集时间序列,通过http协议传输
支持通过中介网关的push时间序列的方式
监控数据通过服务或者静态配置来发现
支持图表和dashboard等多种方式

组件

Prometheus 主程序,主要是负责存储、抓取、聚合、查询方面。
Alertmanager 程序,主要是负责实现报警功能。
Pushgateway 程序,主要是实现接收由Client push过来的指标数据,在指定的时间间隔,由主程序来抓取。
*_exporter 这类是不同系统已经实现了的集成。

prometheus部署

wget https://github.com/prometheus/prometheus/releases/download/v1.6.2/prometheus-1.6.2.linux-amd64.tar.gz
tar -xvf prometheus-1.6.2.linux-amd64.tar.gz
cd prometheus-1.6.2.linux-amd64

配置prometheus.yml
scrape_interval: 15s # 默认15秒到目标处抓取数据

启动
nohup ./prometheus -config.file=prometheus.yml &

nohup /opt/prometheus-1.6.2.linux-amd64/prometheus &

5、WEB页面访问 http://10.211.55.4:9090/graph ,可以看到Prometheus的graph页面。

grafana 部署

1、安装

wget wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.3-1.x86_64.rpm
yum install grafana-4.4.3-1.x86_64.rpm
2、启动服务
systemctl start grafana-server
systemctl enable grafana-server

3、访问页面
curl http://localhost:3000
,默认账号、密码admin/admin

4、Prometheus 和 Grafana 的对接

https://prometheus.io/docs/visualization/grafana/

填入数据源

安装好后

登陆后

MySQL的dashboards(Grafana)

git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana/dashboards

编辑Grafana配置文件
vi /etc/grafana/grafana.ini
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards

重启
service grafana-server restart

mysql监控部署

wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz
tar -xvf node_exporter-0.14.0.linux-amd64.tar.gz
cd node_exporter-0.14.0.linux-amd64
nohup ./node_exporter &

vi .my.cnf
[client]
user=root
password=root

./mysqld_exporter -config.my-cnf=".my.cnf" &

服务端配置,文件prometheus.yml

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

  • job_name: 'mysql'
    static_configs:
    • targets: ['10.10.83.162:9104']
      labels:
      instance: db-10.10.83.162

redis监控部署

wget https://github.com/oliver006/redis_exporter/releases/download/v0.11.1/redis_exporter-v0.11.1.linux-amd64.tar.gz
tar -xvf redis_exporter-v0.11.linux-amd64.tar.gz
nohup /opt/redis_exporter -redis.addr "redis://10.10.83.162:16379" &

tar -xvf redis_exporter-0.11.tar.gz
cd redis_exporter-0.11
cp *json /var/lib/grafana/dashboards/

服务端配置,文件prometheus.yml

scrape_configs:
# The job name is added as a label job=<job_name> to any timeseries scraped from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
  - targets: ['localhost:9090']
  • job_name: 'mysql'
    static_configs:

    • targets: ['10.10.83.162:9104']
      labels:
      instance: db-10.10.83.162
  • job_name: redis_exporter
    static_configs:

    • targets: ['10.10.83.162:9121']
      labels:
      instance: redis-10.10.83.162

总结

  1. Prometheus 9090
  2. Grafana 3000
  3. 3方的基本介绍,1注入2作为数据源,做展示

参考

prometheus + grafana安装部署(centos6.8)

Go!!!
原文地址:https://www.cnblogs.com/shliujing/p/Prometheus-he-Grafana-an-zhuang-bu-shu.html