The DevOps Se­ries De­ploy­ing Graphite Us­ing An­si­ble

In this fifth ar­ti­cle in the DevOps se­ries we will learn to in­stall and set up Graphite us­ing An­si­ble.

OpenSource For You - - Contents -

Graphite is a mon­i­tor­ing tool that was writ­ten by Chris Davis in 2006. It has been re­leased un­der the Apache 2.0 li­cence and com­prises three com­po­nents: 1. Graphite-Web 2. Car­bon

3. Whis­per

Graphite-Web is a Django ap­pli­ca­tion and pro­vides a dash­board for mon­i­tor­ing. Car­bon is a server that lis­tens to time-se­ries data, while Whis­per is a data­base li­brary for stor­ing the data.

Set­ting it up

A Cen­tOS 6.8 vir­tual ma­chine (VM) run­ning on KVM is used for the in­stal­la­tion. Please make sure that the VM has ac­cess to the In­ter­net. The An­si­ble ver­sion used on the host (Parabola GNU/Linux-li­bre x86_64) is 2.2.1.0. The an­si­ble/ folder con­tains the fol­low­ing files:

an­si­ble/in­ven­tory/kvm/in­ven­tory an­si­ble/play­books/con­fig­u­ra­tion/graphite.yml an­si­ble/play­books/ad­min/unin­stall-graphite.yml

The IP ad­dress of the guest Cen­tOS 6.8 VM is added to the in­ven­tory file as shown be­low:

graphite an­si­ble_host=192.168.122.120 an­si­ble_­con­nec­tion=ssh an­si­ble_user=root an­si­ble_­pass­word=pass­word Also, add an en­try for the graphite host in the /etc/hosts file as in­di­cated be­low:

192.168.122.120 graphite

Graphite

The play­book to in­stall the Graphite server is given be­low: ---

- name: In­stall Graphite soft­ware hosts: graphite gath­er_­facts: true tags: [graphite]

tasks:

- name: Im­port EPEL GPG key rp­m_key: key: http://dl.fe­do­rapro­ject.org/pub/epel/RPM-GPGKEY-EPEL-6 state: present

- name: Add YUM repo yum_repos­i­tory: name: epel de­scrip­tion: EPEL YUM repo baseurl: https://dl.fe­do­rapro­ject.org/pub/ epel/$re­lea­sever/$basearch/ gpgcheck: yes

- name: Up­date the soft­ware pack­age repos­i­tory yum: name: ‘*’ up­date_­cache: yes

- name: In­stall Graphite server pack­age: name: “{{ item }}” state: lat­est with­_items:

- graphite-web

We first im­port the keys for the Ex­tra Pack­ages for En­ter­prise Linux (EPEL) repos­i­tory and up­date the soft­ware pack­age list. The ‘graphite-web’ pack­age is then in­stalled us­ing Yum. The above play­book can be in­voked us­ing the fol­low­ing com­mand:

$ an­si­ble-play­book -i in­ven­tory/kvm/in­ven­tory play­books/ con­fig­u­ra­tion/graphite.yml --tags “graphite”

MySQL

A back­end data­base is re­quired by Graphite. By de­fault, the SQLite3 data­base is used, but we will in­stall and use MySQL as shown be­low:

- name: In­stall MySQL hosts: graphite be­come: yes be­come_method: sudo gath­er_­facts: true tags: [data­base]

tasks:

- name: In­stall data­base pack­age: name: “{{ item }}” state: lat­est with­_items:

- mysql - mysql-server - MySQL-python - lib­selinux-python

- name: Start mysqld server ser­vice: name: mysqld state: started

- wait­_­for: port: 3306

- name: Cre­ate graphite data­base user mysql_user: name: graphite pass­word: graphite123 priv: ‘*.*:ALL,GRANT’ state: present

- name: Cre­ate a data­base mysql_db: name: graphite state: present

- name: Up­date data­base con­fig­u­ra­tion block­in­file: path: /etc/graphite-web/lo­cal_set­tings.py block: |

DATA­BASES = {

‘de­fault’: {

‘NAME’: ‘graphite’,

‘EN­GINE’: ‘django.db.back­ends.mysql’, ‘USER’: ‘graphite’,

‘PASS­WORD’: ‘graphite123’,

}

}

- name: syncdb shell: /usr/lib/python2.6/site-pack­ages/graphite/ man­age.py syncdb --noin­put

- name: Al­low port 80 shell: ipt­a­bles -I IN­PUT -p tcp --dport 80 -m state --state NEW,ES­TAB­LISHED -j AC­CEPT

- name: line­in­file: path: /etc/httpd/conf.d/graphite-web.conf in­sertafter: ‘ # Apache 2.2’ line: ‘ Al­low from all’

- name: Start httpd server ser­vice: name: httpd state: started

As a first step, let’s in­stall the re­quired MySQL de­pen­dency pack­ages and the server it­self. We can then start the server and wait for it to lis­ten on port 3306. A graphite user and data­base is cre­ated for use with the Graphite Web ap­pli­ca­tion. For this ex­am­ple, the pass­word is pro­vided as plain text. In pro­duc­tion, use an en­crypted An­si­ble Vault pass­word.

The data­base con­fig­u­ra­tion file is then up­dated to use the MySQL cre­den­tials. Since Graphite is a Django ap­pli­ca­tion, the man­age.py script with syncdb needs to be ex­e­cuted to cre­ate the nec­es­sary ta­bles. We then al­low port 80 through the fire­wall in or­der to view the Graphite dash­board. The graphite-web.conf file is up­dated to al­low read ac­cess, and the

Apache Web server is started.

The above play­book can be in­voked as fol­lows:

$ an­si­ble-play­book -i in­ven­tory/kvm/in­ven­tory play­books/ con­fig­u­ra­tion/graphite.yml --tags “data­base”

Car­bon and Whis­per

The Car­bon and Whis­per Python bind­ings need to be in­stalled be­fore start­ing the car­bon-cache script.

- name: In­stall Car­bon and Whis­per hosts: graphite be­come: yes be­come_method: sudo gath­er_­facts: true tags: [car­bon]

tasks:

- name: In­stall car­bon and whis­per pack­age: name: “{{ item }}” state: lat­est with­_items:

- python-car­bon - python-whis­per

- name: Start car­bon-cache shell: /etc/init.d/car­bon-cache start

The above play­book is in­voked as fol­lows:

$ an­si­ble-play­book -i in­ven­tory/kvm/in­ven­tory play­books/ con­fig­u­ra­tion/graphite.yml --tags “car­bon”

The Graphite dash­board

You can open http://192.168.122.120 in the browser on the host to view the Graphite dash­board. A screen­shot of the Graphite Web ap­pli­ca­tion is shown in Fig­ure 1.

Unin­stalling Graphite

An unin­stall script to re­move the Graphite server and its de­pen­dency pack­ages is re­quired for ad­min­is­tra­tion. The An­si­ble play­book for the same is avail­able in the play­books/ ad­min folder and is given be­low:

--name: Unin­stall Graphite and de­pen­den­cies hosts: graphite gath­er_­facts: true tags: [re­move]

tasks:

- name: Stop the car­bon-cache server shell: /etc/init.d/car­bon-cache stop - name: Unin­stall car­bon and whis­per pack­age: name: “{{ item }}” state: ab­sent with­_items:

- python-whis­per

- python-car­bon

- name: Stop httpd server ser­vice: name: httpd state: stopped

- name: Stop mysqld server ser­vice: name: mysqld state: stopped

- name: Unin­stall data­base pack­ages pack­age: name: “{{ item }}” state: ab­sent with­_items:

- lib­selinux-python - MySQL-python

- mysql-server

- mysql

- graphite-web

The script can be in­voked as fol­lows:

$ an­si­ble-play­book -i in­ven­tory/kvm/in­ven­tory play­books/ ad­min/unin­stall-graphite.yml

Fig­ure 1: Graphite Web

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.