docker: updated grafana image to continue to send API request to grafana
[barometer.git] / docs / release / userguide / docker.userguide.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. (c) <optionally add copywriters name>
4
5 ===================================
6 OPNFV Barometer Docker User Guide
7 ===================================
8
9 .. contents::
10    :depth: 3
11    :local:
12
13 The intention of this user guide is to outline how to install and test the
14 Barometer projects Collectd, Influxdb and Grafana docker images which can be built from the Dockerfiles
15 available within the barometer repository.
16
17
18 Barometer docker images description
19 -----------------------------------
20
21 .. Describe the specific features and how it is realised in the scenario in a brief manner
22 .. to ensure the user understand the context for the user guide instructions to follow.
23
24 Barometer Collectd Image
25 ^^^^^^^^^^^^^^^^^^^^^^^^
26 The barometer collectd docker image gives you a collectd installation that includes all
27 the barometer plugins.
28
29 .. note::
30    The Dockerfile is available in the docker/barometer-collectd directory in the barometer repo.
31    The Dockerfile builds a CentOS 7 docker image.
32    The container MUST be run as a privileged container.
33
34 Collectd is a daemon which collects system performance statistics periodically
35 and provides a variety of mechanisms to publish the collected metrics. It
36 supports more than 90 different input and output plugins. Input plugins
37 retrieve metrics and publish them to the collectd deamon, while output plugins
38 publish the data they receive to an end point. Collectd also has infrastructure
39 to support thresholding and notification.
40
41 Collectd docker image has enabled the following collectd plugins (in addition
42 to the standard collectd plugins):
43
44 * hugepages plugin
45 * Open vSwitch events Plugin
46 * Open vSwitch stats Plugin
47 * mcelog plugin
48 * PMU plugin
49 * RDT plugin
50 * virt
51 * SNMP Agent
52 * Kafka_write plugin
53
54 Plugins and third party applications in Barometer repository that will be available in the
55 docker image:
56
57 * Open vSwitch PMD stats
58 * ONAP VES application
59 * gnocchi plugin
60 * aodh plugin
61 * Legacy/IPMI
62
63 InfluxDB + Grafana Images
64 ^^^^^^^^^^^^^^^^^^^^^^^^^
65
66 The Barometer project's InfluxDB and Grafana docker images are 2 docker images that database and graph
67 statistics reported by the Barometer collectd docker. InfluxDB is an open-source time series database
68 tool which stores the data from collectd for future analysis via Grafana, which is a open-source
69 metrics anlytics and visualisation suite which can be accessed through any browser.
70
71 Installing Docker
72 -----------------
73 .. Describe the specific capabilities and usage for <XYZ> feature.
74 .. Provide enough information that a user will be able to operate the feature on a deployed scenario.
75
76 On Ubuntu
77 ^^^^^^^^^^
78 .. note::
79  * sudo permissions are required to install docker.
80  * These instructions are for Ubuntu 16.10
81
82 To install docker:
83
84 .. code:: bash
85
86     $ sudo apt-get install curl
87     $ sudo curl -fsSL https://get.docker.com/ | sh
88     $ sudo usermod -aG docker <username>
89     $ sudo systemctl status docker
90
91 Replace <username> above with an appropriate user name.
92
93 On CentOS
94 ^^^^^^^^^^
95 .. note::
96  * sudo permissions are required to install docker.
97  * These instructions are for CentOS 7
98
99 To install docker:
100
101 .. code:: bash
102
103     $ sudo yum remove docker docker-common docker-selinux docker-engine
104     $ sudo yum install -y yum-utils  device-mapper-persistent-data  lvm2
105     $ sudo yum-config-manager   --add-repo    https://download.docker.com/linux/centos/docker-ce.repo
106     $ sudo yum-config-manager --enable docker-ce-edge
107     $ sudo yum-config-manager --enable docker-ce-test
108     $ sudo yum install docker-ce
109     $ sudo usermod -aG docker <username>
110     $ sudo systemctl status docker
111
112 Replace <username> above with an appropriate user name.
113
114 .. note::
115    If this is the first time you are installing a package from a recently added
116    repository, you will be prompted to accept the GPG key, and the key’s
117    fingerprint will be shown. Verify that the fingerprint is correct, and if so,
118    accept the key. The fingerprint should match060A 61C5 1B55 8A7F 742B 77AA C52F
119    EB6B 621E 9F35.
120
121         Retrieving key from https://download.docker.com/linux/centos/gpg
122         Importing GPG key 0x621E9F35:
123          Userid     : "Docker Release (CE rpm) <docker@docker.com>"
124          Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
125          From       : https://download.docker.com/linux/centos/gpg
126         Is this ok [y/N]: y
127
128 Proxy Configuration:
129 ^^^^^^^^^^^^^^^^^^^^
130 .. note::
131    This applies for both CentOS and Ubuntu.
132
133 If you are behind an HTTP or HTTPS proxy server, you will need to add this
134 configuration in the Docker systemd service file.
135
136 1. Create a systemd drop-in directory for the docker service:
137
138 .. code:: bash
139
140    $ sudo mkdir -p /etc/systemd/system/docker.service.d
141
142 2. Create a file
143 called /etc/systemd/system/docker.service.d/http-proxy.conf that adds
144 the HTTP_PROXY environment variable:
145
146 .. code:: bash
147
148    [Service]
149    Environment="HTTP_PROXY=http://proxy.example.com:80/"
150
151 Or, if you are behind an HTTPS proxy server, create a file
152 called /etc/systemd/system/docker.service.d/https-proxy.conf that adds
153 the HTTPS_PROXY environment variable:
154
155 .. code:: bash
156
157     [Service]
158     Environment="HTTPS_PROXY=https://proxy.example.com:443/"
159
160 Or create a single file with all the proxy configurations:
161 /etc/systemd/system/docker.service.d/proxy.conf
162
163 .. code:: bash
164
165     [Service]
166     Environment="HTTP_PROXY=http://proxy.example.com:80/"
167     Environment="HTTPS_PROXY=https://proxy.example.com:443/"
168     Environment="FTP_PROXY=ftp://proxy.example.com:443/"
169     Environment="NO_PROXY=localhost"
170
171 3. Flush changes:
172
173 .. code:: bash
174
175     $ sudo systemctl daemon-reload
176
177 4. Restart Docker:
178
179 .. code:: bash
180
181     $ sudo systemctl restart docker
182
183 5. Check docker environment variables:
184
185 .. code:: bash
186
187     sudo systemctl show --property=Environment docker
188
189 Test docker installation
190 ^^^^^^^^^^^^^^^^^^^^^^^^
191 .. note::
192       This applies for both CentOS and Ubuntu.
193
194 .. code:: bash
195
196    $ sudo docker run hello-world
197
198 The output should be something like:
199
200 .. code:: bash
201
202    Unable to find image 'hello-world:latest' locally
203    latest: Pulling from library/hello-world
204    5b0f327be733: Pull complete
205    Digest: sha256:07d5f7800dfe37b8c2196c7b1c524c33808ce2e0f74e7aa00e603295ca9a0972
206    Status: Downloaded newer image for hello-world:latest
207
208    Hello from Docker!
209    This message shows that your installation appears to be working correctly.
210
211    To generate this message, Docker took the following steps:
212     1. The Docker client contacted the Docker daemon.
213     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
214     3. The Docker daemon created a new container from that image which runs the
215        executable that produces the output you are currently reading.
216     4. The Docker daemon streamed that output to the Docker client, which sent it
217        to your terminal.
218
219 To try something more ambitious, you can run an Ubuntu container with:
220
221 .. code:: bash
222
223     $ docker run -it ubuntu bash
224
225 Build the collectd docker image
226 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
227
228 .. code:: bash
229
230     $ git clone https://gerrit.opnfv.org/gerrit/barometer
231     $ cd barometer/docker/barometer-collectd
232     $ sudo docker build -t opnfv/barometer-collectd --build-arg http_proxy=`echo $http_proxy` \
233       --build-arg https_proxy=`echo $https_proxy` -f Dockerfile .
234
235 .. note::
236    In the above mentioned ``docker build`` command, http_proxy & https_proxy arguments needs to be
237    passed only if system is behind an HTTP or HTTPS proxy server.
238
239 Check the docker images:
240
241 .. code:: bash
242
243    $ sudo docker images
244
245 Output should contain a barometer-collectd image:
246
247 .. code::
248
249    REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
250    opnfv/barometer-collectd     latest              05f2a3edd96b        3 hours ago         1.2GB
251    centos                       7                   196e0ce0c9fb        4 weeks ago         197MB
252    centos                       latest              196e0ce0c9fb        4 weeks ago         197MB
253    hello-world                  latest              05a3bd381fc2        4 weeks ago         1.84kB
254
255 Download the collectd docker image
256 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
257 If you want to use a pre-built barometer image, you can pull the barometer
258 image from https://hub.docker.com/r/opnfv/barometer-collectd/
259
260 .. code:: bash
261
262     $ docker pull opnfv/barometer-collectd
263
264
265 Run the collectd docker image
266 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
267 .. code:: bash
268
269    $ sudo docker run -tid --net=host -v `pwd`/../src/collectd_sample_configs:/opt/collectd/etc/collectd.conf.d \
270     -v /var/run:/var/run -v /tmp:/tmp --privileged opnfv/barometer-collectd /run_collectd.sh
271
272 .. note::
273   The docker collectd image contains configuration for all the collectd plugins. In the command
274   above we are overriding /opt/collectd/etc/collectd.conf.d by mounting a host directory
275   `pwd`/../src/collectd_sample_configs that contains only the sample configurations we are interested
276   in running. *It's important to do this if you don't have DPDK, or RDT installed on the host*.
277   Sample configurations can be found at:
278   https://github.com/opnfv/barometer/tree/master/src/collectd/collectd_sample_configs
279
280 To make some changes when the container is running run:
281
282 .. code:: bash
283
284    sudo docker exec -ti opnfv/barometer-collectd /bin/bash
285
286 Check your docker image is running
287
288 .. code:: bash
289
290    sudo docker ps
291
292 Build the influxdb + Grafana docker images
293 ------------------------------------------
294
295 Overview
296 ^^^^^^^^
297 The barometer-influxdb image is based on the influxdb:1.3.7 image from the influxdb dockerhub. To
298 view detils on the base image please visit
299 `https://hub.docker.com/_/influxdb/  <https://hub.docker.com/_/influxdb/>`_ Page includes details of
300 exposed ports and configurable enviromental variables of the base image.
301
302 The barometer-grafana image is based on grafana:4.6.3 image from the grafana dockerhub. To view
303 details on the base image please visit
304 `https://hub.docker.com/r/grafana/grafana/ <https://hub.docker.com/r/grafana/grafana/>`_ Page
305 includes details on exposed ports and configurable enviromental variables of the base image.
306
307 The barometer-grafana image includes pre-configured source and dashboards to display statistics exposed
308 by the barometer-collectd image. The default datasource is an influxdb database running on localhost
309 but the address of the influxdb server can be modified when launching the image by setting the
310 environmental variables influxdb_host to IP or hostname of host on which influxdb server is running.
311
312 Additional dashboards can be added to barometer-grafana by mapping a volume to /opt/grafana/dashboards.
313 Incase where a folder is mounted to this volume only files included in this folder will be visible
314 inside barometer-grafana. To ensure all default files are also loaded please ensure they are included in
315 volume folder been mounted. Appropriate example are given in section ``Run the Grafana docker image``
316
317 Download the InfluxDB and Grafana docker image
318 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
319 If you wish to use pre-built barometer project's influxdb and grafana images, you can pull the
320 images from https://hub.docker.com/r/opnfv/barometer-influxdb/ and https://hub.docker.com/r/opnfv/barometer-grafana/
321
322 .. note::
323  If your preference is to build images locally please see sections `Build the InfluxDB Image`_ and
324  `Build the Grafana Image`_
325
326 .. code:: bash
327
328     $ docker pull opnfv/barometer-influxdb
329     $ docker pull opnfv/barometer-grafana
330
331 Build the InfluxDB Image
332 ^^^^^^^^^^^^^^^^^^^^^^^^^
333
334 Build influxdb image from Dockerfile
335
336 .. code:: bash
337
338   $ cd barometer/docker/barometer-influxdb
339   $ sudo docker build -t opnfv/barometer-influxdb --build-arg http_proxy=`echo $http_proxy` \
340       --build-arg https_proxy=`echo $https_proxy` -f Dockerfile .
341
342 .. note::
343       In the above mentioned ``docker build`` command, http_proxy & https_proxy arguments needs to
344       be passed only if system is behind an HTTP or HTTPS proxy server.
345
346 Check the docker images:
347
348 .. code:: bash
349
350    $ sudo docker images
351
352 Output should contain an influxdb image:
353
354 .. code::
355
356    REPOSITORY                   TAG                 IMAGE ID            CREATED            SIZE
357    opnfv/barometer-influxdb     latest              1e4623a59fe5        3 days ago         191MB
358
359 Build the Grafana Image
360 ^^^^^^^^^^^^^^^^^^^^^^^
361
362 Build Grafana image from Dockerfile
363
364 .. code:: bash
365
366   $ cd barometer/docker/barometer-grafana
367   $ sudo docker build -t opnfv/barometer-grafana --build-arg http_proxy=`echo $http_proxy` \
368       --build-arg https_proxy=`echo $https_proxy` -f Dockerfile .
369
370 .. note::
371          In the above mentioned ``docker build`` command, http_proxy & https_proxy arguments needs to be passed only if system is behind an HTTP or HTTPS proxy server.
372
373 Check the docker images:
374
375 .. code:: bash
376
377    $ sudo docker images
378
379 Output should contain an influxdb image:
380
381 .. code::
382
383    REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
384    opnfv/barometer-grafana      latest              05f2a3edd96b        3 hours ago         1.2GB
385
386 Run the Influxdb and Grafana Images
387 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
388 Run the InfluxDB  docker image
389 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
390 .. code:: bash
391
392    $ sudo docker run -tid --net=host -v /var/lib/influxdb:/var/lib/influxdb -p 8086:8086 -p 25826:25826  opnfv/barometer-influxdb
393
394 To make some changes when the container is running run:
395
396 .. code:: bash
397
398    sudo docker exec -ti opnfv/barometer-influxdb /bin/bash
399
400 Check your docker image is running
401
402 .. code:: bash
403
404    sudo docker ps
405
406 Run the Grafana docker image 
407 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
408
409 Connecting to an influxdb instance running on local system and adding own custom dashboards
410
411 .. code:: bash
412
413    $ sudo docker run -tid --net=host -v /var/lib/grafana:/var/lib/grafana -v ${PWD}/dashboards:/opt/grafana/dashboards -p 3000:3000 opnfv/barometer-grafana
414
415 Connecting to an influxdb instance running on remote system with hostname of someserver and IP address of 192.168.121.111
416
417 .. code:: bash
418
419    $ sudo docker run -tid --net=host -v /var/lib/grafana:/var/lib/grafana -p 3000:3000 -e influxdb_host=someserver --add-host someserver:192.168.121.111 opnfv/barometer-grafana
420
421 To make some changes when the container is running run:
422
423 .. code:: bash
424
425    sudo docker exec -ti opnfv/barometer-grafana /bin/bash
426
427 Check your docker image is running
428
429 .. code:: bash
430
431    sudo docker ps
432
433 Testing the docker image
434 ^^^^^^^^^^^^^^^^^^^^^^^^
435
436 TODO
437
438 References
439 ^^^^^^^^^^^
440 .. [1] https://docs.docker.com/engine/admin/systemd/#httphttps-proxy
441 .. [2] https://docs.docker.com/engine/installation/linux/docker-ce/centos/#install-using-the-repository
442 .. [3] https://docs.docker.com/engine/userguide/
443