Grafana+prometheus监控部署

1、软件介绍
1.1、Prometheus
Prometheus是一个开源的服务监控系统,它通过HTTP协议从远程的机器收集数据并存储在本地的时序数据库上。它提供了一个简单的网页界面、一个功能强大的查询语言以及HTTP接口等等。Prometheus通过安装在远程机器上的exporter来收集监控数据。
特点:多维数据模型(有metric名称和键值对确定的时间序列) 灵活的查询语言 不依赖分布式存储 通过pull方式采集时间序列,通过http协议传输 支持通过中介网关的push时间序列的方式 监控数据通过服务或者静态配置来发现 支持图表和dashboard等多种方式。

1.2、Grafana
Grafana是一个可视化面板(Dashboard),有着非常漂亮的图表和布局展示,功能齐全的度量仪表盘和图形编辑器,支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB作为数据源。
特性:灵活丰富的图形化选项 可以混合多种风格 支持白天和夜间模式 支持多个数据源

Prometheus Server: Prometheus服务端,由于存储及收集数据,提供相关api对外查询用。
Exporter: 类似传统意义上的被监控端的agent,有区别的是,它不会主动推送监控数据到server端,而是等待server端定时来手机数据,即所谓的主动监控。
Pushagateway: 用于网络不可直达而居于exporter与server端的中转站。
Alertmanager: 报警组件,将报警的功能单独剥离出来放在alertmanager。
Web UI: Prometheus的web接口,可用于简单可视化,及语句执行或者服务状态监控。

2、安装

建议:prometheus server、grafana安装到一个单独的Linux执行机上,node_exporter安装到ceph节点上。

2.1 Exporter安装
在ceph界面上开启ceph-mgr的prometheus模块,ceph节点上的exporter功能会收集信息整理为prometheus格式

ceph mgr module enable prometheus
ceph mgr module ls

安装node_exporter,收集系统信息整理为prometheus格式

wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
tar -zxvf node_exporter-0.16.0.linux-amd64.tar.gz
cd node_exporter-0.16.0.linux-amd64
nohup ./node_exporter &  //启动node_exporter,做成开机启动

2.2、Prometheus安装
官方下载地址:https://prometheus.io/download/

wget https://github.com/prometheus/prometheus/releases/download/v2.2.1/prometheus-2.2.1.linux-amd64.tar.gz
tar -zxvf  prometheus-2.2.1.linux-amd64.tar.gz
cd prometheus-2.2.1.linux-amd64/

修改prometheus配置文件,指定ceph节点信息,在prometheus.yml文件中scrape_configs部分添加

scrape_configs:
  - job_name: 'ceph'
    static_configs:
      - targets: ['xxx.xxx.xxx.xxx:9283']
        labels:
          instance: ceph
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'node_exporter'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ['xxx.xxx.xxx.xxx:9100']
        labels:
          instance: node_export_instance
  - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    #     # scheme defaults to 'http'.
    #
    static_configs:
      - targets: ['localhost:9090']

[root@localhost prometheus-2.2.1.linux-amd64]# nohup ./prometheus & 

启动prometheus进程,同样建议做成开机启动
使用浏览器登录http://prometheus节点IP:9090(xxx.xxx.xxx.xxx:9090),使用浏览器登陆target下的metrics地址可以查看能否正常收集数据。此页面后续可以测试信息收集命令是否可用。

在出现的界面中点击status---targets查看各实例状态

如果状态有down的,说明端口没有打开,在节点查看你的防火墙状态:sudo ufw status,应该是inactive的,如果不是,请关闭:sudo  ufw disable

2.3、Grafana安装——在另一台机器上安装
官方下载地址:http://docs.grafana.org/installation/
Ubuntu安装

[root@localhost ~]# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.1.4_amd64.deb
[root@localhost ~]# sudo apt-get install -y adduser libfontconfig
[root@localhost ~]# sudo dpkg -i grafana_5.1.4_amd64.deb
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start grafana-server
[root@localhost ~]# systemctl status grafana-server
[root@localhost ~]# systemctl enable grafana-server.service

安装完后,就可以使用浏览器登录了,默认端口是3000,默认账号是admin/admin

  • 在界面右边设置按钮下面找到data sources ,设置数据源,配置名称和prometheus数据源地址,其他默认即可
  • 设置dashboard,即设置面板显示,一般操作是从官方下载一个模板,然后在基础上修改。
    官方地址:https://grafana.com/dashboards?utm_source=grafana_search
  • 在界面右边的“+”号添加dashboard,import json(可以在官网上下载),并选择刚刚配置的数据源,然后就可以查看相关监控信息了。

如果没有显示,这是因为grafana显示的命令和prometheus收集的命令不一致导致。可以手动编辑每一部分的grafana端显示命令,点击其中一个显示块选择编辑。

具体的显示内容可以在prometheus 的meitrics中查看。

猜你喜欢

转载自blog.csdn.net/u012114090/article/details/81453957