grafana使用Prometheus數據源監控mongo數據庫

數據庫改用mongo後,監控需求就須要整合進grafana裏,因爲一直在堅持docker化部署,那麼這次也不例外。linux

1. 安裝Prometheus:git

What is Prometheus?github

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project's governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.web

Prometheus is a monitoring platform that collects metrics from monitored targets by scraping metrics HTTP endpoints on these targets.mongodb

主要的意思就是Prometheus是一個開源的系統監控和告警工具包,經過HTTP endpoints來收集要監控的系統的指標。跟着官網的first step,只須要下載最新版本,配置prometheus.yml,啓動便可,比較的簡單, 所以咱們docker化安裝也較爲容易。docker

  1) 安裝鏡像數據庫

[root@vhost18 prometheus]# docker search prometheus
NAME DESCRIPTION STARS OFFICIAL AUTOMATED prom
/prometheus 605 [OK] basi/prometheus-swarm A sample image that can be used as a base fo… 7 [OK] infinityworks/prometheus-rancher-exporter Exposes Service/Stack/Host status from the R… 7 [OK] linuxtips/prometheus_alpine Image to run Prometheus on Alpine Linux. #VA… 6 [OK] sscaling/jmx-prometheus-exporter A docker image containing a released version… 5 [OK] argussecurity/cassandra-prometheus Docker Official Cassandra image, with Promet… 4 [OK]

  安裝STARS最多的那個就是了。api

  2)編寫配置文件,參考官網工具

# 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). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # 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']

  3)啓動容器ui

docker run -d --name prom -p 9090:9090 -v /data/prometheus/:/etc/prometheus/ prom/prometheus

  4)看下日誌是否啓動成功

docker logs -f prom

level=info ts=2018-12-11T11:39:08.73690446Z caller=main.go:244 msg="Starting Prometheus" version="(version=2.5.0, branch=HEAD, revision=67dc912ac8b24f94a1fc478f352d25179c94ab9b)" level=info ts=2018-12-11T11:39:08.737024426Z caller=main.go:245 build_context="(go=go1.11.1, user=root@578ab108d0b9, date=20181106-11:40:44)" level=info ts=2018-12-11T11:39:08.737054274Z caller=main.go:246 host_details="(Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 72be1c67c847 (none))" level=info ts=2018-12-11T11:39:08.737077772Z caller=main.go:247 fd_limits="(soft=1048576, hard=1048576)" level=info ts=2018-12-11T11:39:08.737095504Z caller=main.go:248 vm_limits="(soft=unlimited, hard=unlimited)" level=info ts=2018-12-11T11:39:08.757770232Z caller=main.go:562 msg="Starting TSDB ..." level=info ts=2018-12-11T11:39:08.757939887Z caller=web.go:399 component=web msg="Start listening for connections" address=0.0.0.0:9090 level=info ts=2018-12-11T11:39:08.769272192Z caller=main.go:572 msg="TSDB started" level=info ts=2018-12-11T11:39:08.769349241Z caller=main.go:632 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml level=info ts=2018-12-11T11:39:08.772044947Z caller=main.go:658 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml level=info ts=2018-12-11T11:39:08.77209973Z caller=main.go:531 msg="Server is ready to receive web requests."

  5) 訪問http://ip:9090

    成功的話會出現如下頁面

prmetheus

2. 安裝mongodb_exporter

剛說到Prometheus是根據endpoints來獲取指標數據的,因爲grafana沒有直接的插件來獲取mongo數據庫的指標數據,這時候就能夠用得上mongodb_exporter了,參考1參考2

  1)安裝鏡像

能夠直接build剛剛參考1和參考2的Dockerfile,也能夠像安裝Prometheus同樣直接search,我這邊爲了簡單採用直接search的方式,方式重複不累贅描述。

  2)啓動鏡像

docker run -d --name mongo-explorer -p 9104:9104 eses/mongodb_exporter --mongodb.uri mongodb://monitor:monitor@ip:port

參數須要的mongo地址直接命令傳入,無需export 。

如何知道端口和參數呢,一種是看官方說明,另外一種直接啓動一個空鏡像看日誌就知道了。

  3) 檢查下日誌

[root@vhost18 prometheus]# docker logs -f mongo-explorer ### Warning: the exporter is in beta/experimental state and field names are very ### likely to change in the future and features may change or get removed! ### See: https://github.com/percona/mongodb_exporter for updates
mongodb_exporter version: unknown, git commit hash: unknown Listening on :9104

  4)訪問http://ip:9090

    成功的話會出現如下頁面

3. mongodb_exporter整合進Prometheus

  1)  修改配置

    只須要在prometheus.yml上添加以下框

  2) 重啓prometheus

docker restart prom

  3) 檢查

    訪問http://172.28.64.10:9090/targets,能看到數據源就表示成功了。

4. grafana中添加數據源

5. 安裝儀表盤

  到grafana官網直接搜mongo,找到本身須要的儀表盤就能夠了,後續在本身改造。

相關文章
相關標籤/搜索