How to use Grafana to monitor Docker on Ubuntu _docker

Source: Internet
Author: User
Tags configuration settings docker ps grafana docker run influxdb cadvisor grafana docker

Objective

Grafana is a rich indicator of open source Control Panel. It is very useful when visualizing large-scale measurements of data. Based on different metrics data, it provides a powerful, elegant way to create, share, and browse data.

It provides a rich variety of flexible graphics options. In addition, for data source, it supports many different storage backend. Each data source has a query editor tailored to the characteristics and functionality of a particular data source. Grafana provides formal support for the following data sources: Graphite, influxdb, Opentsdb, Prometheus, Elasticsearch, and Cloudwatch.

The query language and capabilities of each data source are clearly different, and you can mix data from multiple data sources into a single dashboard, but each panel is bound to a specific data source that belongs to a specific organization (organization). It supports authentication logins and role-based access control scenarios. It is deployed as an independent software, written using go and JavaScript.

In this article, I'll explain how to install Grafana on Ubuntu 16.04 and use this software to configure Docker monitoring.

Prerequisite

Install the Docker server

Install Grafana

We can build our Grafana in the Docker. There is an official supply of grafana Docker mirrors.

Please run the following command to build the Grafana container.

root@ubuntu:~# Docker run-i-P 3000:3000 Grafana/grafana Unable to find image ' grafana/grafana:latest ' locally: Pulling from Grafana/grafana 5c90d4a2d1a8:pull complete b1a9a0b6158e:pull complete Acb23b0d58de:pull complete Dige ST: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 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" log Ger=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=" def

Ault.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 2016-07-27t15:20:19+0000 lvl=info msg= "Path Logs" Logger=settings Path=/var/log/grafana 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 msg= "Executing migration" logger=migrator id= "create preferences Table V3" t=2016-07-27t15:20:20+0000 lvl=info msg= "Cre Ated default Admin User: [admin] "t=2016-07-27t15:20:20+0000 lvl=info msg= starting plugin search" Logger=plugins -07-27t15:20:20+0000 lvl=info msg= "Server listening" Logger=server address=0.0.0.0:3000 protocol=http

By running this command, we can confirm the working status of the Grafana container Docker ps-a or access Http://Docker ip:3000 through this URL.

All Grafana configuration settings use the environment variable definition, which is useful when using container technology. The Grafana configuration file path is/etc/grafana/grafana.ini.

Understanding Configuration Items

Grafana can specify several configuration options in its INI configuration file, or it can be specified using the environment variables mentioned earlier.

Configuration file Location

Typically profile path:

Default profile path:$WORKING_DIR/conf/defaults.ini

Custom profile Path: $WORKING_DIR/conf/custom.ini

PS: When you use a deb, RPM, or Docker mirror to install Grafana, your profile is in/etc/grafana/grafana.ini.

Understanding Configuration Variables

Now let's look at some of the variables in the configuration file:

Instance_name: This is the name of the Grafana server instance. The default value ${HOSTNAME} is obtained from, the value is the environment variable hostname, if the variable is empty or does not exist, Grafana will attempt to use system calls to obtain the machine name.

[Paths]: These paths are usually specified by the command line in the INIT.D script or systemd service file.

Data: This is the path to the Grafana store Sqlite3 database (if used), file-based sessions (if used), and other data.

Logs: This is the path to the Grafana store log.

[Server]

HTTP_ADDR: Applies the IP address of the listener and, if it is empty, listens for all interfaces.

Http_port: Apply the Listening port, the default is 3000, you can use the following command to redirect your 80 port to 3000 ports:$iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000

Root_url: This URL is used to access Grafana from the browser.

Cert_file: The path to the certificate file (if the protocol is HTTPS).

Cert_key: The path to the certificate key file (if the protocol is HTTPS).

[Database]:grafana uses a database to store users and dashboards as well as other information, which is configured by default to use SQLite3 embedded in Grafana primary binaries.

Type: You can choose MySQL, Postgres, SQLite3 according to your requirements.

Path: This is the path stored by the database only when you select the SQLite3 database.

Host: Only MySQL or Postgres is available. It includes the IP address or host name and port. For example, Grafana and MySQL are running on the same host setting as: host = 127.0.0.1:3306 .

Name:grafana the name of the database, set it to Grafana or another name.

User: Database users (not applicable to SQLite3).

Password: Database user password (not applicable for SQLite3).

Ssl_mode: For Postgres, use Disable,require, or verify-full equivalent. For MySQL, use True,false, or skip-verify.

Ca_cert_path: (for MySQL only) CA certificate file path, in most Linux systems, certificates can be found in/etc/ssl/certs.

Client_key_path: (MySQL only) the path to the client key, which is used only when the server requires user-side authentication.

Client_cert_path: (for MySQL only) the path to the client certificate, which is used only when the server requires user-side authentication.

Server_cert_name: (for MySQL only) the Common name field for the certificate used by the MySQL server. If Ssl_mode is set to skip-verify, it may not be set.

[Security]

Admin_user: This is the user name of the Grafana default administrator user, and the default setting is Admin.

Admin_password: This is the Grafana default administrator user's password, set at the first run time, and the default is admin.

Login_remember_days: Remain logged in/Remember my last days.

Secret_key: Used to keep login/Remember the signature of my cookies.

Setting important components for monitoring

We can use the following components to create our Docker monitoring system.

Cadvisor: It is called Container Advisor. It provides users with an interpretation of resource utilization and performance characteristics. It collects, aggregates, processes, and exports information about the container in which it is running. You can learn more from this document.

Influxdb: This is a database containing time series, metrics, and analysis. We use this data source to set up our monitoring. Cadvisor only displays real-time information and does not save these metrics. Influx Db helps save the monitoring data provided by Cadvisor to show data that is not a certain period of time.

Grafana Dashboard: It can help us visually integrate all the information. This powerful dashboard allows us to query the INFLUXDB data store and put them in a reasonably well laid out chart.

Installation of Docker monitoring

We need to install each of the following components in our Docker system step-by-step:

Install Influxdb

We can use this command to pull the influxdb mirror and deploy the Influxdb container.

 root@ubuntu:~# Docker run-d-P 8083:8083-p 8086:8086--expose 8090--expose p Re_create_db=cadvisor--name influxsrv tutum/influxdb:0.8.8 Unable to find image ' tutum/influxdb:0.8.8 ' locally 0.8.8:p Ulling from Tutum/influxdb A3ed95caeb02:already exists 23efb549476f:already exists Aa2f8df21433:already exists ef07 2d3c9b41:already exists C9f371853f28:already exists A248b0871c3c:already exists 749db6d368d0:already exists 7d7c7d 923e63:pull Complete E47cc7808961:pull Complete 1743b6eeb23f:pull complete

Ab1dda3e18b07f80517c3f9aae7d18133c0c42 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 the other application--name Influxsrv:container have name infl 
Uxsrv, use to Cadvisor link it. 

You can test whether INFLUXDB is installed, by accessing this URL http://your IP address: 8083, username and password are "root".

Influxdb Administration 2016-08-01 14-10-08

We can create the database we need on this interface.

Createdb influx

Install Cadvisor

Our next step is to install the Cadvisor container and link it to the Influxdb container. You can use this command to create it.

root@ubuntu:~# Docker run--volume=/:/rootfs:ro--volume =/var/run:/var/run:rw--volume=/sys:/sys:ro--volume=/var/li B/docker/:/var/lib/docker:ro--publish=8080:8080--detach=true--link influxsrv:influxsrv--name=cadvisor 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 14CD28DC E332: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_DR Iver=influxdb:set the storage driver as influxdb specify what INFLUXDB to push data to: instance Nfluxsrv:8086:the Ip:port of the database. Default Is ' localhost:8086 '-storage_driver_db=cadvisor:database name. Uses db ' Cadvisor ' by default

You can access this address to test the installation cadvisor is normal http://your IP address: 8080. This will provide statistical information for your Docker hosts and containers.

Cadvisor-docker Containers 2016-08-01 14-24-18

Install Grafana Control Panel

Finally, we need to install the Grafana dashboard and connect to Influxdb, and you can set it by executing the following command.

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

Now we can log in to Grafana to configure the data source. Visit http://your IP address: 3000 or http://your IP address (if you have done a port mapping before):

User Name-Admin

Password-admin

Once we have Grafana installed, we can connect influxdb. Log on to the dashboard and click on the Grafana icon (the fireball) in the upper-left corner of the panel. Click the data source (Sources) to configure it.

Addingdatabsource

Now you can add new graphics (graph) to our default data source Influxdb.

Panelgraph

We can adjust our graphics by editing and adjusting our queries on the Measurement (Metric) page.

Grafana-grafana Dashboard 2016-08-01 14-53-40

Grafana-grafana Dashboard

Summarize

For more information about Docker monitoring, you can learn more from this. The above is the entire content of this article, if you have any questions or questions to pay attention to the message exchange, I hope you can leave valuable suggestions and comments. Thanks for the support of the cloud-dwelling community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.