项目作者: shakapark

项目描述 :
Script Ansible to deplay multiple docker for monitoring system
高级语言:
项目地址: git://github.com/shakapark/AnsibleMonitoring.git
创建时间: 2017-07-31T08:36:41Z
项目社区:https://github.com/shakapark/AnsibleMonitoring

开源协议:

下载


AnsibleMonitoring

Description

Schéma Monitoring

The Optional dockers are use to get metrics on the machine :

  • cAdvisor : Get metrics about containers
  • Node-Exporter : Get hardware metrics of the machine
  • Node-Exporter Service : Get state about Systemd
  • SensorsDocker : Get temperature of processor

Prometheus collect those metrics and add a system of request

Grafana use prometheus requests to create graphs.

Docker Name Description
cAdvisor https://github.com/google/cadvisor
Node-Exporter https://github.com/prometheus/node_exporter
SensorsDocker https://github.com/Shakapark/SensorsDocker
Prometheus https://github.com/prometheus/prometheus
Grafana https://github.com/grafana/grafana

Installation (on Remote Server)

  1. $ sudo apt-get install ssh

Installation (on Monitoring Server)

Ansible Installation
http://docs.ansible.com/ansible/latest/intro_installation.html#installing-the-control-machine

  1. $ sudo apt-get install git ssh
  2. $ git clone https://github.com/shakapark/AnsibleMonitoring/
  3. $ cd AnsibleMonitoring

Configuration:

Change the file “hosts” : for all machines, change ip address, ssh port if needed, user name of the remote machine and password or private key for ssh connection.
Example:

  1. [local]
  2. 127.0.0.1 ansible_connection=ssh ansible_port=22 ansible_user=toto ansible_become_pass=Bonjour123 ansible_ssh_private_key_file=/home/toto/PrivKey.pem
  3. [distant]
  4. 192.168.1.10 ansible_connection=ssh ansible_port=22 ansible_user=tetu ansible_become_pass=Bonjour456 ansible_ssh_private_key_file=/home/tetu/PrivKey2.pem

If you don’t want to use the sudo password in the hosts file (“ansible_become_pass”), you can disable it for the command sudo. For that, edit the file “/etc/sudoers” and add a line for the users you have put in hosts file (on each machine).

  1. #includedir /etc/sudoers.d
  2. toto ALL=(ALL) NOPASSWD:ALL

In the file install.yml, you can modify your installation by comment or supress the line you don’t need (prerequisites.yml, prometheus_install.yml and grafana_install.yml must be install) (SensorsDocker need Node-Exporter).
Example:

  1. - hosts: local
  2. name: Installing monitoring server
  3. tasks:
  4. - include: prerequisites.yml
  5. - include: node_exporter_install.yml
  6. # - include: node_exporter_service_install.yml
  7. - include: sensors_install.yml
  8. # - include: cadvisor_install.yml
  9. - include: prometheus_install.yml
  10. - include: grafana_install.yml
  11. - hosts: distant
  12. name: Installing Distant Exporter
  13. tasks:
  14. - include: prerequisites.yml
  15. - include: node_exporter_install.yml
  16. - include: node_exporter_service_install.yml
  17. - include: sensors_install.yml
  18. - include: cadvisor_install.yml

In ‘conf’ folder, you must change the prometheus configuration (“prometheus.yml”) to monitor remote machine (change ‘IpNode1’ by an ip address that the monitoring server can contact, add more if you want).

Example:

  1. global:
  2. scrape_interval: 15s
  3. scrape_configs:
  4. - job_name: prometheus
  5. static_configs:
  6. - targets: ['localhost:9090']
  7. - job_name: node
  8. metrics_path: /metrics
  9. static_configs:
  10. - targets: ['192.168.1.9:9100','192.168.1.10:9100']
  11. - job_name: service
  12. metrics_path: /metrics
  13. static_configs:
  14. - targets: ['192.168.1.9:9110','192.168.1.10:9110']
  15. - job_name: cadvisor
  16. static_configs:
  17. - targets: ['192.168.1.9:8090','192.168.1.10:8090']

You can change too the grafana configuration (“grafana.ini”)

The ports 3000 (grafana), 8090 (cAdvisor), 9090 (Prometheus), 9100 (Node-exporter), 9110 (Node-exporter Service) are use by this system, make sure thy are free, if needed, you can change the port use by a docker in the install file of it. Example for cAdvisor (cadvisor_install.yml):

  1. restart_policy: unless-stopped
  2. #published_ports: 8090:8080 #ExternePort:InternPort
  3. published_ports: 9000:8080 #ExternePort:InternPort
  4. volumes:

You will need to change too the configuration of Prometheus.

Monitoring Installation

  1. $ ansible-playbook -i hosts install.yml

Once the install is finished, you can connect to the prometheus interface by http://IpHost:9090 to verify it receive data, then you can connect to the grafana interface http://IpHost:3000 Login: admin / mdp: admin. To show the graphs, change the variable of all dashboard to correspond to prometheus configuration:
Screen 1
Put the same IP address that Prometheus configuration.
Screen 2

Update Container

If you want to update a container without data (Node-Exporter, cAdvisor…), begin to stop the container then remove it :

  1. $ docker ps #(To show the names of active containers)
  2. $ docker stop <container_name>
  3. $ docker rm <container_name>

Next, remove the Docker image :

  1. $ docker images #(To show the list of images)
  2. $ docker rmi <image_name>

For Prometheus and Grafana Datas, the last Script version save it in /home/docker_share/data/ so you just need to apply previous comands.

If you have installed an older version, you need to save it manually.

For Grafana :

  1. $ docker cp grafana:/var/lib/grafana/grafana.db /home/docker_share/data/grafana/grafana.db

For Prometheus :

  1. $ docker cp prometheus:/prometheus /home/docker_share/data/

Next, apply the command to remove container and image.

To reinstall containers, change install.yml file then apply this Ansible script.

For Grafana, comment the following lines of grafana_install.yml :

  1. #- name: Configuration Grafana 1/2
  2. # become: true
  3. # copy:
  4. # src: conf/grafana/grafana_modele.db
  5. # dest: /home/docker_share/data/grafana/grafana.db