Ubuntu under Cadvisor+influxdb+grafana+supervisord Monitor host and Docker containers (running on the host)
Applies to the class Ubuntu system. AMD64.
1. INFLUXDB: (Consider converting Influxdb to Prometheus later)
Https://influxdb.com/docs/v0.8/introduction/installation.html#ubuntu-debian
(You can only choose the way the Deb is installed.) There's no way to compile the code. Go development is not mature and stable many library changes too fast too big cause a lot of package path has been changed 0.88 version down has been compiled, so I first install deb-and then copy out the Influxdb binary file-and finally clean the uninstall system influxdb)
$ wget Http://get.influxdb.org.s3.amazonaws.com/influxdb_0.8.9_amd64.deb
$ sudo dpkg-i influxdb_0.8.9_amd64.deb
Copy the two files and delete the others. Two files are:
/usr/bin/influxdb
/opt/influxdb/shared/config.toml
$ cd ... where/cigs
$ chown ${user}:${user} influxdb
$ chown ${user}:${user} config.toml
$ VI config.toml
A few paths can be changed.
In addition, an operation that is not necessary-increases the limit of the number of open files:
(The reason is not and necessary because the official said "pretend like we made it past 1999 and computers can actually handle more than the open files". Only 256 ...)
Https://influxdb.com/docs/v0.8/introduction/installation.html#file-limits
If you increase the number of open files, modify the config.toml so that it can be executed (note that the path in the configuration file must exist and the permissions are appropriate):
$ ulimit-n 40960 # # Valid only for the current terminal
$./influxdb-config=config.toml
I wrote a script that runs with sudo:
#!/bin/bash
Mkdir-p/data/influxdb/shared/data/raft
Mkdir-p/data/influxdb/shared/data/db
Mkdir-p/data/influxdb/shared/data/wal
Ulimit-n 40960
./influxdb-config=config.toml
Next, clean up the influxdb in the uninstall system:
Stop all influxdb processes, then su find/-name "*influx*" and then manually clear the Influxdb.
Clean up the files, and then clean up the influx user rights:
$ sudo userdel influxdb
$ sudo groupdel influxdb
Inspection: sudo cat/etc/group | grep influx found no influx.
If there is a row in Docker (this is a pit):
(Note: If you don't have it, don't make the following order.)
$ sudo groupdel Docker
$ sudo groupadd Docker
$ sudo gpasswd-a ${user} docker && sudo service docker restart
If there is also sudo vi/etc/group, for docker1.9.1,docker that line is: Docker:x:999:yourname
Note:
Verify that the influx and Docker permissions have been completely cleaned up:
$ docker Run--rm-it Redis
$ ps aux | grep Redis to see if there is influxdb this user.
Other:
It is said that Influxdb rely on these libraries, but I do not need, perhaps the system already has:
$ sudo apt-get install mercurial BZR Protobuf-compiler Flex Bison valgrind g++ make autoconf libtool libz-dev Libbz2-dev C URL build-essential git wget
Finally, about INFLUXDB, the process looks at the query statement, recorded as follows:
List Series//list all tables below the current DB
SELECT * FROM/.*/limit 10//list The first 10 data of all tables in the current DB
SELECT * FROM stats where container_name= ' Redis ' limit 10
SELECT * FROM stats where container_name =~/^[^\/]/limit 10//Not at/start (All Docker container)
2. Cadvisor:
Https://github.com/google/cadvisor/releases/latest download binaries directly.
$ chmod +x cadvisor
$ mv Cadvisor ... where/cigs/
Note: Cadvisor can only support influxdbv0.8 at this time.
Run (must sudo) and connect it to the Influxdb:
$ sudo./cadvisor-storage_driver=influxdb-storage_driver_host=localhost:8086-storage_driver_db= ' Cadvisor '
(See the meanings of each parameter: HTTPS://GITHUB.COM/GOOGLE/CADVISOR/BLOB/MASTER/DOCS/INFLUXDB.MD)
Note: Influxdb run up, first run to create a DB in (Cadvisor configured to write data to this db):
$ curl "Http://localhost:8086/db?u=root&p=root"-D "{\" name\ ": \" Cadvisor\ "}"
3. Grafana:
http://grafana.org/download/Download the tar package.
$ tar zxvf grafana-2.5.0.linux-x64.tar.gz
$ mv grafana-2.5.0 ... where/cigs/
Write a script in the CIGS directory:
#!/bin/bash
homepath=grafana-2.5.0
Mkdir-p/data/grafana/log
Mkdir-p/data/grafana/dashboards
$HOMEPATH/bin/grafana-server-homepath= $HOMEPATH-config=grafana.ini
sudo execution can be done. Then open the previous section to configure:
http://localhost:3000
Log in (see Configuration file for account): Data sources/add NEW:
Name:cadvisor default:√
Type:influxdb 0.8.x
url:http://localhost:8086 Access:proxy
Basic auth:enable (not checked, seemingly useless)
Database:cadvisor
User:root Password:root
Then with a dashboards:
Dashboards/home↓/+new
。。。。
Live: Profile Grafana.ini if modified, it may not be applied. This requires sudo rm-rf/data/grafana/grafana.db
In addition, it is said that Grafana relies on these libraries, but I do not need, perhaps the system already has:
$ sudo apt-get install-y adduser libfontconfig
4. Supervisord the Triad
4.1 Installing Supervisor
$ Apt-cache Show Supervisor
See if it's version 3.0.
Installation:
$ sudo apt-get install supervisor
To see if the installation was successful:
$ echo_supervisord_conf
$ ps aux | grep Supervisor
$ vi/etc/supervisor/supervisord.conf
Last line:
4.2 Triad:
$ VI cigs-supervisor.conf
(excerpt part only)
[Unix_http_server]
File=/tmp/vmd_supervisord.sock
[Supervisord]
Pidfile=/tmp/vmd_supervisord.pid
Nodaemon=true
[Supervisorctl]
Serverurl=unix:///tmp/vmd_supervisord.sock
Prompt=cigs
[Rpcinterface:supervisor]
Supervisor.rpcinterface_factory = Supervisor.rpcinterface:make_main_rpcinterface
[Program:cadvisor]
command=% (here) s/runcadvisor
directory=% (here) s
Autorestart=true
Startsecs=4
startretries=99
Stopasgroup=true
Killasgroup=true
Redirect_stderr=true
stdout_logfile=% (here) s/log/% (program_name) S_supervisor.log
stdout_logfile_maxbytes=500mb
Stdout_logfile_backups=50
Stdout_capture_maxbytes=1mb
Stdout_events_enabled=false
Environment = pypy_gc_max= "250MB", pypy_gc_growth=1.2, Pypy_gc_max_delta= "192MB"
...
Above, cigs-supervisor.conf is the full suerpvisor configuration file that launches Cadvisor,influxdb and Grafana.
This way: by Supervisord the system to start such a task, the command of the task is this: Supervisord-c cigs-supervisor.conf
So, write the config file in/etc/supervisor/conf.d/xx.conf:
cigs_supervisor_conf=$ (PWD)/cigs-supervisor.conf
File_write=/etc/supervisor/conf.d/cigs.conf
echo "[Program:cigs]" > $FILE _write
echo "command = supervisord-c $CIGS _supervisor_conf" >> $FILE _write
echo "Autostart=true" >> $FILE _write
echo "Autorestart=true" >> $FILE _write
echo "startsecs=5" >> $FILE _write
Restart Supervisord:
(This machine found that sudo service supervisor stop is not useful. So the restart method is as follows)
$ sudo supervisorctl
$ shutdown
$ sudo service supervisor start
5. Finally, throw a python program to the server, timed to detect more than 90% of the alarm.
I use the slack alarm, the use of the PY library:
Https://pypi.python.org/pypi/psutil
Https://pypi.python.org/pypi/pyslack-real
Similarly, the PY program is also put into the Supervisord.
(This alarm program, directly change the code of Cadvisor with Go implementation is also a very good choice.)
(formerly) Ubuntu under Cadvisor+influxdb+grafana+supervisord Monitor host and Docker containers