它提供了豐富多樣、靈活的圖形選項。此外,針對數據源,它支持許多不一樣的存儲後端。每一個數據源都有針對特定數據源的特性和功能所定製的查詢編輯器。Grafana 提供了對下述數據源的正式支持:Graphite、InfluxDB、OpenTSDB、 Prometheus、Elasticsearch 和 Cloudwatch。html
每一個數據源的查詢語言和能力顯然是不一樣的,你能夠未來自多個數據源的數據混合到一個單一的儀表盤上,但每一個面板被綁定到屬於一個特定組織的特定數據源上。它支持驗證登陸和基於角色的訪問控制方案。它是做爲一個獨立軟件部署,使用 Go 和 JavaScript 編寫的。linux
在這篇文章,我將講解如何在 Ubuntu 16.04 上安裝 Grafana 並使用這個軟件配置 Docker 監控。sql
先決條件docker
安裝 Grafana數據庫
咱們能夠在 Docker 中構建咱們的 Grafana。 有一個官方提供的 Grafana Docker 鏡像。請運行下述命令來構建Grafana 容器。ubuntu
root@ubuntu:~# docker run -i -p 3000:3000 grafana/grafana Unable to find image 'grafana/grafana:latest' locally latest: Pulling from grafana/grafana 5c90d4a2d1a8: Pull complete b1a9a0b6158e: Pull complete acb23b0d58de: Pull complete Digest: sha256:34ca2f9c7986cb2d115eea373083f7150a2b9b753210546d14477e2276074ae1 Status: Downloaded newer image for grafana/grafana:latest t=2016-07-27T15:20:19+0000 lvl=info msg="Starting Grafana" logger=main version=3.1.0 commit=v3.1.0 compiled=2016-07-12T06:42:28+0000 t=2016-07-27T15:20:19+0000 lvl=info msg="Config loaded from" logger=settings file=/usr/share/grafana/conf/defaults.ini t=2016-07-27T15:20:19+0000 lvl=info msg="Config loaded from" logger=settings file=/etc/grafana/grafana.ini t=2016-07-27T15:20:19+0000 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.data=/var/lib/grafana" t=2016-07-27T15:20:19+0000 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.logs=/var/log/grafana" t=2016-07-27T15:20:19+0000 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.plugins=/var/lib/grafana/plugins" t=2016-07-27T15:20:19+0000 lvl=info msg="Path Home" logger=settings path=/usr/share/grafana t=2016-07-27T15:20:19+0000 lvl=info msg="Path Data" logger=settings path=/var/lib/grafana t=2016-07-27T15:20:19+0000 lvl=info msg="Path Logs" logger=settings path=/var/log/grafana t=2016-07-27T15:20:19+0000 lvl=info msg="Path Plugins" logger=settings path=/var/lib/grafana/plugins t=2016-07-27T15:20:19+0000 lvl=info msg="Initializing DB" logger=sqlstore dbtype=sqlite3 t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="create playlist table v2" t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="create playlist item table v2" t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="drop preferences table v2" t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="drop preferences table v3" t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="create preferences table v3" t=2016-07-27T15:20:20+0000 lvl=info msg="Created default admin user: [admin]" t=2016-07-27T15:20:20+0000 lvl=info msg="Starting plugin search" logger=plugins t=2016-07-27T15:20:20+0000 lvl=info msg="Server Listening" logger=server address=0.0.0.0:3000 protocol=http subUrl=
咱們能夠經過運行此命令確認 Grafana 容器的工做狀態 "docker ps -a"或經過這個URL訪問 http://Docker IP:3000。後端
全部的 Grafana 配置設置都使用環境變量定義,在使用容器技術時這個是很是有用的。Grafana 配置文件路徑爲 /etc/grafana/grafana.ini。瀏覽器
理解配置項服務器
Grafana 能夠在它的 ini 配置文件中指定幾個配置選項,或可使用前面提到的環境變量來指定。cookie
配置文件位置
一般配置文件路徑:
PS:當你使用 deb、rpm 或 docker 鏡像安裝 Grafana 時,你的配置文件在/etc/grafana/grafana.ini。
理解配置變量
如今咱們看一些配置文件中的變量:
設置監控的重要組件
咱們可使用下面的組件來建立咱們的 Docker 監控系統。
Docker 監控的安裝
咱們須要一步一步的在咱們的 Docker 系統中安裝如下每個組件:
安裝 InfluxDB
咱們可使用這個命令來拉取 InfluxDB 鏡像,並部署了 influxDB 容器。
root@ubuntu:~# docker run -d -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 -e PRE_CREATE_DB=cadvisor --name influxsrv tutum/influxdb:0.8.8 Unable to find image 'tutum/influxdb:0.8.8' locally 0.8.8: Pulling from tutum/influxdb a3ed95caeb02: Already exists 23efb549476f: Already exists aa2f8df21433: Already exists ef072d3c9b41: Already exists c9f371853f28: Already exists a248b0871c3c: Already exists 749db6d368d0: Already exists 7d7c7d923e63: Pull complete e47cc7808961: Pull complete 1743b6eeb23f: Pull complete Digest: sha256:8494b31289b4dbc1d5b444e344ab1dda3e18b07f80517c3f9aae7d18133c0c42 Status: Downloaded newer image for tutum/influxdb:0.8.8 d3b6f7789e0d1d01fa4e0aacdb636c221421107d1df96808ecbe8e241ceb1823 -p 8083:8083 : user interface, log in with username-admin, pass-admin -p 8086:8086 : interaction with other application --name influxsrv : container have name influxsrv, use to cAdvisor link it.
你能夠測試 InfluxDB 是否安裝好,經過訪問這個 URL http://你的 IP 地址:8083,用戶名和密碼都是 」root「。
咱們能夠在這個界面上建立咱們所需的數據庫。
安裝 cAdvisor
咱們的下一個步驟是安裝 cAdvisor 容器,並將其連接到 InfluxDB 容器。你可使用此命令來建立它。
root@ubuntu:~# docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --link influxsrv:influxsrv --name=cadvisor google/cadvisor:latest -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086 Unable to find image 'google/cadvisor:latest' locally latest: Pulling from google/cadvisor 09d0220f4043: Pull complete 151807d34af9: Pull complete 14cd28dce332: Pull complete Digest: sha256:8364c7ab7f56a087b757a304f9376c3527c8c60c848f82b66dd728980222bd2f Status: Downloaded newer image for google/cadvisor:latest 3bfdf7fdc83872485acb06666a686719983a1172ac49895cd2a260deb1cdde29 root@ubuntu:~# --publish=8080:8080 : user interface --link=influxsrv:influxsrv: link to container influxsrv -storage_driver=influxdb: set the storage driver as InfluxDB Specify what InfluxDB instance to push data to: -storage_driver_host=influxsrv:8086: The ip:port of the database. Default is ‘localhost:8086’ -storage_driver_db=cadvisor: database name. Uses db ‘cadvisor’ by default
你能夠經過訪問這個地址來測試安裝 cAdvisor 是否正常 http://你的 IP 地址:8080。 這將爲你的 Docker 主機和容器提供統計信息。
安裝 Grafana 控制面板
最後,咱們須要安裝 Grafana 儀表板並鏈接到 InfluxDB,你能夠執行下面的命令來設置它。
root@ubuntu:~# docker run -d -p 3000:3000 -e INFLUXDB_HOST=localhost -e INFLUXDB_PORT=8086 -e INFLUXDB_NAME=cadvisor -e INFLUXDB_USER=root -e INFLUXDB_PASS=root --link influxsrv:influxsrv --name grafana grafana/grafana f3b7598529202b110e4e6b998dca6b6e60e8608d75dcfe0d2b09ae408f43684a
如今咱們能夠登陸 Grafana 來配置數據源. 訪問 http://你的 IP 地址:3000 或http://你的 IP 地址(若是你在前面作了端口映射的話):
一旦咱們安裝好了 Grafana,咱們能夠鏈接 InfluxDB。登陸到儀表盤而且點擊面板左上方角落的 Grafana 圖標(那個火球)。點擊數據源來配置。
如今你能夠添加新的圖形到咱們默認的數據源 InfluxDB。
咱們能夠經過在測量頁面編輯和調整咱們的查詢以調整咱們的圖形。
關於 Docker 監控,你可用今後瞭解更多信息。 感謝你的閱讀。我但願你能夠留下有價值的建議和評論。但願你有個美好的一天。