使用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是實時的,所以這個是我已經開了一天的圖.


如果轉載,需加出處.

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