Skip to content

Commit

Permalink
Added grafana inc datasource and dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdmorgan committed Aug 26, 2016
1 parent 0c06528 commit 32fc6cb
Show file tree
Hide file tree
Showing 20 changed files with 604 additions and 64 deletions.
17 changes: 11 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
- Start collection of services to test the swarm
- multiple overlay networks for front and backend
- Clustered consul servers and nodes on all hosts
- Centralised logging via syslog docker log driver feeding into ELK stack
- Will publish all the endpoints

- Host monitoring using collectd -> riemann -> influxdb -> grafana.

## Roadmap
- Add monitoring, investigate
- [cAdvisor](https://github.com/google/cadvisor) for docker stats
- collectd
- [influxdb](https://influxdata.com/)
- [grafana](https://grafana.net/)
- Riemann + [Riemann tools](https://github.com/riemann/riemann-tools) for Docker & Consul
- [Riemann tools](https://github.com/riemann/riemann-tools) for Docker & Consul
- statsd for udp from applications (though Riemann.io recommend against UDP)

- Add shipyard for visualisation
Expand All @@ -28,16 +30,19 @@

- Look to start daemon running on 2375 https://docs.docker.com/v1.10/engine/reference/commandline/daemon/

- Add multiple overlay networks and pull out hardcoded **appnet** configuration

## [0.4]()
## [0.4](https://github.com/jamesdmorgan/vagrant-ansible-docker-swarm/releases/tag/v0.4) (2016-08-26) Monitoring

**Added:**

- Added monitoring ansible playbook
- Added global collectd container service
- Added influxdb service constrained to influx ansible group
- Added [influxdb](https://influxdata.com/) service constrained to influx ansible group
- Added single instance of [Riemann](http://riemann.io). H/A is [complicated](https://groups.google.com/forum/m/#!topic/riemann-users/pkMk0aWIjqo)
- Added [grafana](https://grafana.net/) service including influxdb datasource and demo dashboard for CPU - needs work

## [0.3](https://github.com/jamesdmorgan/vagrant-ansible-docker-swarm/releases/tag/v0.3) (2016-08-20)
## [0.3](https://github.com/jamesdmorgan/vagrant-ansible-docker-swarm/releases/tag/v0.3) (2016-08-20) Logging and Consul

**Added:**
- Created python script that utilises **docker-py** and **python-consul** to listen for docker start/stop events
Expand Down
22 changes: 11 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Addition provisioners are only called if --provision-with is passed
if ARGV.include? '--provision-with'
worker.vm.provision "apps", type: "ansible" do |ansible|

# Only need to run against one of the managers since using swarm
ansible.limit = "managers*"
ansible.playbook = "ansible/apps.yml"
worker.vm.provision "consul", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/consul.yml"
ansible.verbose = "vv"
ansible.groups = ANSIBLE_GROUPS
end
Expand All @@ -95,18 +93,20 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
ansible.groups = ANSIBLE_GROUPS
end

worker.vm.provision "consul", type: "ansible" do |ansible|
worker.vm.provision "monitoring", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/consul.yml"
ansible.playbook = "ansible/monitoring.yml"
ansible.verbose = "vv"
ansible.sudo = true
ansible.groups = ANSIBLE_GROUPS
end

worker.vm.provision "monitoring", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/monitoring.yml"
worker.vm.provision "apps", type: "ansible" do |ansible|

# Only need to run against one of the managers since using swarm
ansible.limit = "managers*"
ansible.playbook = "ansible/apps.yml"
ansible.verbose = "vv"
ansible.sudo = true
ansible.groups = ANSIBLE_GROUPS
end
end
Expand Down
23 changes: 3 additions & 20 deletions ansible/monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@
become: yes
become_user: root
roles:
- { role: influxdb, tags: [influxdb] }
- { role: riemann, tags: [riemann] }
- { role: collectd, tags: [collectd] }




- hosts: influxdb
become: yes
become_user: root
tasks:
- name: Running Influxdb
shell: >
docker service create \
--name influxdb \
--network appnet \
-p 8083:8083/tcp \
-p 8086:8086/tcp \
--env "CONSUL_SERVICE_PORT=8086" \
--log-driver syslog \
--log-opt tag={{ docker_syslog_tag }} \
--constraint 'node.labels.influxdb == true' \
tutum/influxdb:0.12
- { role: grafana, tags: [grafana] }
11 changes: 11 additions & 0 deletions ansible/roles/collectd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
collectd_name: collectd
collectd_docker_tar: /vagrant/collectd-docker.tar
collectd_service_definition: >
--name collectd
--mode global
--network appnet
--mount type=bind,src=/vagrant/collectd/root/etc/collectd/,dst=/etc/collectd/
--mount type=bind,src=/vagrant/collectd/root/etc/collectd.d/,dst=/etc/collectd.d/
--mount type=bind,src=/proc,dst=/mnt/proc,readonly
{{ collectd_name }}
52 changes: 26 additions & 26 deletions ansible/roles/collectd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@
run_once: true
become: yes
become_user: root
shell: >
docker build -t collectd .
args:
chdir: /vagrant/collectd
docker_image:
path: /vagrant/collectd
name: "{{ collectd_name }}"
archive_path: "{{ collectd_docker_tar }}"

- name: Get existing services
shell: >
docker service ls --filter name=collectd | tail -n +2
docker service ls --filter name={{ collectd_name }} | tail -n +2
register: collectd_result

#- name: load collectd image
# become: yes
# become_user: root
# shell: >
# docker load -i /vagrant/collectd-docker.tar
# when: inventory_hostname != "{{ groups['managers'][0] }}"
- name: load collectd image
become: yes
become_user: root
shell: >
docker load -i {{ collectd_docker_tar }}
when: item != "{{ groups['managers'][0] }}"
delegate_to: "{{ item }}"
with_items: "{{ groups['all'] }}"

#- name: Clean up collectd image
# run_once: true
# become: yes
# become_user: root
# file: path=/vagrant/collectd-docker.tar state=absent
# delegate_to: "{{ groups['managers'][0] }}"
- name: Clean up collectd image
run_once: true
become: yes
become_user: root
file: path={{ collectd_docker_tar }} state=absent

- name: Stopped existing collectd service
become: yes
become_user: root
shell: >
docker service rm {{ collectd_name }}
when: "'collectd' in collectd_result.stdout"

# Could possibly be an issue with the --priviledged flag which is not available
# for services
- name: Running collectd container
become: yes
become_user: root
shell: >
docker service create \
--name collectd \
--mode global \
--network appnet \
--mount type=bind,src=/vagrant/collectd/root/etc/collectd/,dst=/etc/collectd/ \
--mount type=bind,src=/vagrant/collectd/root/etc/collectd.d/,dst=/etc/collectd.d/ \
--mount type=bind,src=/proc,dst=/mnt/proc,readonly \
collectd
when: "'collectd' not in collectd_result.stdout"
docker service create {{ collectd_service_definition }}
23 changes: 23 additions & 0 deletions ansible/roles/grafana/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
grafana_name: grafana
grafana_user: admin
grafana_password: password
grafana_dashboard_file: templates/dashboard.json.j2
grafana_datasource_files:
- templates/influxdb_datasource.json.j2

influxdb_db_name: riemann-local
influxdb_user: root
influxdb_db_password: password
influxdb_host: http://influxdb
influxdb_port: 8086

grafana_service_definition: >
--name {{ grafana_name }}
--network appnet
-p 3001:3000/tcp
--env "GF_SECURITY_ADMIN_PASSWORD={{ grafana_password }}"
--env "CONSUL_SERVICE_PORT=3001"
--log-driver syslog
--log-opt tag={{ docker_syslog_tag }}
grafana/grafana:3.1.0-beta1
43 changes: 43 additions & 0 deletions ansible/roles/grafana/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Get existing services
shell: >
docker service ls --filter name={{ grafana_name }} | tail -n +2
register: grafana_result

- name: Stopped existing grafana service
become: yes
become_user: root
shell: >
docker service rm {{ grafana_name }}
when: "'{{ grafana_name }}' in grafana_result.stdout"

- name: Running Grafana service
become: yes
become_user: root
shell: >
docker service create {{ grafana_service_definition }}
- pause: seconds=5

- name: Imported Grafana dashboard
uri:
url: http://192.168.77.21:3001/api/dashboards/db
method: POST
user: "{{ grafana_user }}"
password: "{{ grafana_password }}"
body: "{{ lookup('template', grafana_dashboard_file) }}"
status_code: 200
body_format: json
force_basic_auth: yes

- name: Imported Grafana datasources
uri:
url: http://192.168.77.21:3001/api/datasources
method: POST
user: "{{ grafana_user }}"
password: "{{ grafana_password }}"
body: "{{ lookup('template', item) }}"
status_code: 200
body_format: json
force_basic_auth: yes
with_items: "{{ grafana_datasource_files }}"
Loading

0 comments on commit 32fc6cb

Please sign in to comment.