使用grafana监控mongodb

说先说一下结构,由于grafana本身数据源没有mongodb,所以需要在中间加上Prometheus来对mongodb监控.

服务器端组件:

prometheus #服务端

Grafana #前端展示,

客户端组件:

node_exporter

mongodb_exporter


mongodb,Prometheus,node_exporter,node_exporter 都安装在192.168.23.10

grafana 安装在另外一台机器上


首先安装go

$ yum install go
$ go version
go version go1.6.3 linux/amd64

下载安装Prometheus(https://prometheus.io/download/)

$ 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 -C /usr/local/
$ ln -sv /usr/local/prometheus-1.6.2.linux-amd64/ /usr/local/prometheus
$ cd /usr/local/prometheus

然后在Prometheus里面修改配置文件prometheus.yml(添加你监管的ip地址):

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'codelab-monitor'

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
   #- "first.rules"
  # - "second.rules"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
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: 'mongo1'
    static_configs:
      - targets: ['192.168.23.10:9001']   #这里是mongodb_exporter监听端口,在后面会说.

启动Prometheus: nohup ./Prometheus &


Prometheus内置了一个web界面,我们可通过http://monitor_host:9090进行访问:



Status->Targets页面下,我们可以看到我们配置的mongo1,Target的StateUP。(up为Prometheus已经检测到数据,需要安装好

node_exporter,mongodb_exporter下面会说)


可以用我传上去的:

mongodb_exporter:

https://download.csdn.net/download/locky_lll/10366804

node_exporter:


https://download.csdn.net/download/locky_lll/10366812


下一步我们需要安装并运行exporter,下载exporters并解压到被监控端服务器:

$ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz
https://github.com/dcu/mongodb_exporter/releases/mongodb_exporter-linux-amd64(这个我是直接下导进去的)
安装运行node_exporter:

$ tar xvf node_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/
$ nohup /usr/local/node_exporter-0.14.0.linux-amd64/node_exporter &

安装运行mongodb_exporter:

$ nohup ./mongodb_exporter-linux-amd64 &

这时再返回Prometheus页面,你的mongodb Status就回变成 UP.


到这里,Prometheus监控mongoDB就完成了.


Grafana安装配置介绍(网上教程比较多,我就不一一写了)

编辑配置文件/etc/grafana/grafana.ini,修改dashboards.json段落下两个参数的值:

安装仪表盘(Percona提供)

运行以下命令为Grafana打个补丁,不然图表不能正常显示:

最后我们运行Grafana服务

grafana默认端口3000,可以访问ganfana.


然后我们到Data Sources页面添加数据源:


然后在添加表盘时,可以load一个辨认已经做好的表盘:

https://grafana.com/dashboards/2583

完成后:



因为grafana是实时的,所以这个是我已经开了一天的图.


如果转载,需加出处.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章