Subscribe to Posts by Email

Subscriber Count

    699

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

DevOps for Databases: vagrant+ansible+prometheus+grafana

Hello

In this post, we are going to install virtualbox with vagrant and configure prometheus + grafana a open source monitoring , visualization, alerting tool. This vagrant file or playbook can be run individually, that means if you do not want to create a virtual box you can just run the playbook.

Here are the things you should know before you start

  1. Install Vagrant and Virtual box in your machine/laptop, even for windows, i kept local run mode for ansible so it take care.
  2. Download/clone the git hub repository from here
  3. Run the vagrant to brought up virtualbox if you need
  4. Run the ansible only if you want to skip vagrant

Explanation of Vagrant File:

The red lines denote

  • A box prom01 is defined and centos7 image will be built, if not found locally vagrant will download from centos cloud.
  • Assigned a private address some random, vagrant create a virtual interface according to it
  • Forwarded the ports 9090, 3000 , so that can access grafana and prometheus URL from my localhost i.e from my OS machine
  • Also assigned 1GB of memory to my newly build prom01 machine
  • Provided hostname as prom01

The blue lines denote:

  • Run the ansible playbook in target machine :ansibel_local if you are running vagrant from windows
  • Run the ansible playbook in target machine from here :ansible if you are not running vagrant from windows.

Vagrant.configure("2") do |config|
config.vm.define "prom01" do |prom01|
prom01.vm.box = "centos/7"
prom01.vm.hostname = 'prom01'
prom01.vm.box_url = "centos/7"

prom01.vm.network :public_network, ip: "192.168.56.120"
prom01.vm.network :forwarded_port, guest: 22, host: 30122, id: "ssh"
prom01.vm.network :forwarded_port, guest: 9090, host: 9090
prom01.vm.network :forwarded_port, guest: 9093, host: 9093

prom01.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--name", "prom01"]
end
end
if Vagrant::Util::Platform.windows?
config.vm.provision :ansible_local do |ansible|
ansible.playbook = "main.yml"
end
else
config.vm.provision :ansible do |ansible|
ansible.playbook = "main.yml"
end
end
end

Some Variable stuff with Ansible Playbook

Variables: Variables are located in top of the file main.yml 

node_exporter_version: 0.16.0
prometheus_version: 2.2.1
grafana_rpm: https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.3-1.x86_64.rpm

According to above, the node exporter which is kind of host agent will 0.16.0 version and prometheus version will be 2.2.1 and Grafana the visualisation tool will be download from aws directly.

Running vagrant

cd <repository directory>

vagrant up

Running Playbook

cd <repository directory>

ansible-playbook main.yml

Full log :-

Log Part of Vagrant

==> prom01: Checking for guest additions in VM...
prom01: No guest additions were detected on the base box for this VM! Guest
prom01: additions are required for forwarded ports, shared folders, host only
prom01: networking, and more. If SSH fails on this machine, please install
prom01: the guest additions and repackage the box to continue.
prom01:
prom01: This is not an error message; everything may continue to work properly,
prom01: in which case you may ignore this message.
==> prom01: Setting hostname...
==> prom01: Configuring and enabling network interfaces...
prom01: SSH address: 127.0.0.1:30122
prom01: SSH username: vagrant
prom01: SSH auth method: private key
==> prom01: Rsyncing folder: /cygdrive/c/Users/Sureshgandhi/Desktop/ansible-prometheus-nodeexporter-grafana/ => /vagrant

Log Part of Prometheus

prom01: Running ansible-playbook...

PLAY [prom01*] *****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [prom01]

TASK [create prometheus group] *************************************************
changed: [prom01]

TASK [create prometheus user] **************************************************
changed: [prom01]

TASK [download latest version of node exporter] ********************************
changed: [prom01]

TASK [unarchive node exporter] *************************************************
changed: [prom01]

TASK [remove node exporter tarball] ********************************************
changed: [prom01]

TASK [create node exporter systemd unit file] **********************************
changed: [prom01]

TASK [set node exporter to be enabled at boot] *********************************
changed: [prom01]

TASK [download latest version of prometheus] ***********************************
changed: [prom01]
[WARNING]: Module remote_tmp /home/prometheus/.ansible/tmp did not exist and
was created with a mode of 0700, this may cause issues when running as another
user. To avoid this, create the remote_tmp dir with the correct permissions
manually

TASK [unarchive prometheus] ****************************************************
changed: [prom01]

TASK [remove node exporter tarball] ********************************************
changed: [prom01]

TASK [create prometheus systemd unit file] *************************************
changed: [prom01]

TASK [create scrape config for prometheus] *************************************
changed: [prom01]

TASK [set prometheus to be enabled at boot] ************************************
changed: [prom01]

TASK [install grafana] *********************************************************
changed: [prom01]

TASK [set grafana to be enabled at boot] ***************************************
changed: [prom01]

PLAY RECAP *********************************************************************
prom01 : ok=16 changed=15 unreachable=0 failed=0

Accessing Prometheus and Grafana from your Guest OS i.e your laptop/machine

Open your browser and type http://localhost:9090 for prometheus and http://localhost:3000 for grafana

Screenshots for the prometheus targets and grafana

 

Comments are closed.