forked from allen13/influxdb-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up influxdb-cluster ansible playbook.
- Loading branch information
user
committed
Sep 11, 2015
0 parents
commit 0196a57
Showing
44 changed files
with
1,157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
.vagrant | ||
*.vdi | ||
*.pyc | ||
**/.*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ansible influxdb cluster playbook | ||
================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
require 'fileutils' | ||
require_relative './vagrant/shared.rb' | ||
|
||
Vagrant.configure("2") do |config| | ||
create_vm(config, name: "influxdb", id: 1) | ||
create_vm(config, name: "influxdb", id: 2) | ||
create_vm(config, name: "influxdb", id: 3) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[defaults] | ||
host_key_checking=False | ||
forks=200 | ||
|
||
[ssh_connection] | ||
pipelining=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
vagrant destroy --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
ansible-playbook -i $(dirname $0)/../inventories/development $(dirname $0)/../playbook/site.yml $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[development] | ||
influxdb-01 ansible_ssh_host=10.0.0.101 private_ip=10.0.1.101 | ||
influxdb-02 ansible_ssh_host=10.0.0.102 private_ip=10.0.1.102 | ||
influxdb-03 ansible_ssh_host=10.0.0.103 private_ip=10.0.1.103 | ||
|
||
[development:vars] | ||
ansible_ssh_user=vagrant | ||
ansible_ssh_pass=vagrant | ||
|
||
[consul] | ||
influxdb-01 | ||
|
||
[influxdb] | ||
influxdb-0[1:3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from ansible import errors, runner | ||
import json | ||
|
||
def to_group_vars(host_vars, groups, target = 'all'): | ||
if type(host_vars) != runner.HostVars: | ||
raise errors.AnsibleFilterError("|failed expects a HostVars") | ||
|
||
if type(groups) != dict: | ||
raise errors.AnsibleFilterError("|failed expects a Dictionary") | ||
|
||
data = [] | ||
for host in groups[target]: | ||
data.append(host_vars[host]) | ||
return data | ||
|
||
class FilterModule (object): | ||
def filters(self): | ||
return {"to_group_vars": to_group_vars} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from ansible import errors, runner | ||
import json | ||
|
||
def to_servers_with_port(host_vars, groups, target, attribute, port): | ||
if type(host_vars) != runner.HostVars: | ||
raise errors.AnsibleFilterError("|failed expects a HostVars") | ||
|
||
if type(groups) != dict: | ||
raise errors.AnsibleFilterError("|failed expects a Dictionary") | ||
|
||
hosts_in_group = [] | ||
for host in groups[target]: | ||
hosts_in_group.append(host_vars[host]) | ||
|
||
hosts_with_port = map((lambda host: host[attribute] + ':' + port), hosts_in_group) | ||
return hosts_with_port | ||
|
||
class FilterModule (object): | ||
def filters(self): | ||
return {"to_servers_with_port": to_servers_with_port} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=The Apache HTTP Server | ||
After=network.target remote-fs.target nss-lookup.target | ||
|
||
[Service] | ||
Type=notify | ||
EnvironmentFile=/etc/sysconfig/httpd | ||
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND | ||
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful | ||
ExecStop=/bin/kill -WINCH ${MAINPID} | ||
KillSignal=SIGCONT | ||
PrivateTmp=true | ||
Restart=always | ||
RestartSec=10 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- name: restart apache | ||
service: name=httpd state=restarted | ||
|
||
- name: reload apache | ||
service: name=httpd state=reloaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
- name: install wsgi | ||
yum: pkg={{item}} state=latest | ||
with_items: | ||
- httpd | ||
- mod_wsgi | ||
- mod_ssl | ||
|
||
- name: disable userdir.conf | ||
file: path=/etc/httpd/conf.d/{{item}}.conf state=absent | ||
with_items: | ||
- userdir | ||
- autoindex | ||
|
||
- name: install httpd service files | ||
copy: src={{item}} dest=/usr/lib/systemd/system/{{item}} | ||
register: service | ||
with_items: | ||
- httpd.service | ||
|
||
- name: reload service files | ||
shell: systemctl daemon-reload | ||
when: service.changed | ||
notify: restart apache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
consul_domain: os. | ||
consul_log_level: "ERR" | ||
consul_bootstrap_expect: 3 | ||
is_consul_server: false | ||
has_consul_web_ui: false | ||
|
||
consul_web_ui_users: | ||
- {name: 'admin', password: 'admin'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"check": { | ||
"id": "mem-util", | ||
"name": "Memory utilization", | ||
"script": "/usr/bin/check_linux_memory -w 3 -c 2", | ||
"interval": "10s" | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
playbook/roles/consul/files/check-scripts/check_linux_memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/bin/sh | ||
# | ||
# Plugin to check system memory | ||
# by hugme ([email protected]) | ||
# You can find my checks here: https://github.com/hugme/Nag_checks | ||
# Nagios script to check memory usage on linux server | ||
# version 1.2.0 | ||
# | ||
########################################################## | ||
|
||
MEMINFO="/proc/meminfo" | ||
|
||
########################################################## | ||
# We call them functions because they're fun | ||
########################################################## | ||
|
||
print_help() { | ||
cat << EOF | ||
Linux Memory Plugin for Nagios | ||
Copyright (c) hugme ([email protected]) | ||
Version: 1.2.0 | ||
Last Modified: 10-07-2014 | ||
License: This software can be used for free unless I meet you, then you owe me lunch. | ||
Usage: check_linux_memory -w [warning %] -c [critical %] | ||
Options: | ||
-w [0-99] = Your warning %. 20 means 20% of your memory can remain before a warning alarm. Do not use the % sign. | ||
-c [0-99] = Your critical %. 10 means 10% of your memory can remain before a critical alarm. Do not use the % sign. | ||
-d [K,M,G,T] = divider K=kilobytes, M=megabytes, G=gigabytes, T=terabytes | ||
-f = Include cached memory as free memory when calculating your percentage free | ||
EOF | ||
} | ||
|
||
invalid_type() { | ||
echo "\nInvalid $1\n" | ||
print_help | ||
exit 3 | ||
} | ||
|
||
############################################## | ||
## Suck in the user input | ||
############################################## | ||
|
||
|
||
while test -n "$1"; do | ||
case $1 in | ||
--help) print_help ; exit 0 ;; | ||
-h) print_help ; exit 0 ;; | ||
-w) WARN="$2"; shift ;; | ||
-c) CRIT="$2"; shift ;; | ||
-d) DIV="$2"; shift ;; | ||
-f) FC=1 ;; | ||
esac | ||
shift | ||
done | ||
|
||
############################################## | ||
## Set the defaults if needed | ||
############################################## | ||
|
||
[ -z "$WARN" ] && WARN=20 | ||
[ -z "$CRIT" ] && CRIT=10 | ||
[ -z "$DIV" ] && DIV=M | ||
[ -z "$FC" ] && FC=0 | ||
|
||
############################################## | ||
## Check user input | ||
############################################## | ||
|
||
[ ! -z `echo $WARN | tr -d [:digit:]` ] && invalid_type "Warning: Warning value can only contain numbers" | ||
[ ! -z `echo $CRIT | tr -d [:digit:]` ] && invalid_type "Critical: Critical value can only contain numbers" | ||
[ "${WARN%.*}" -ge 100 ] && invalid_type "Warning: Warning must be smaller than 100%" | ||
[ "${CRIT%.*}" -ge 100 ] && invalid_type "Critical: Critical must be smaller than 100%" | ||
[ "${CRIT%.*}" -gt "${WARN%.*}" ] && invalid_type "Critical: Your Warning must be Higher than your Critical" | ||
|
||
case $DIV in | ||
k|K) DIVNUM=1;; | ||
m|M) DIVNUM=1024;; | ||
g|G) DIVNUM=1048576;; | ||
t|T) DIVNUM=1073741824;; | ||
*) invalid_type;; | ||
esac | ||
|
||
[ ! -f "$MEMINFO" ] && { | ||
echo "Your Memory info file seems to be missing" | ||
exit 1 | ||
} | ||
|
||
############################################## | ||
## Do the work | ||
## Pull the memory file into awk | ||
## grab the lines we need | ||
## Print the information | ||
############################################## | ||
|
||
RESULT=$(awk -v warn=$WARN -v crit=$CRIT -v div=$DIV -v divnum=$DIVNUM -v fc=$FC '/^MemTotal:/ { total=$2 } | ||
/^MemTotal:/ { tot=$2 } | ||
/^MemFree:/ { free=$2 } | ||
/^Buffers:/ { buff=$2 } | ||
/^Cached:/ { cache=$2 } | ||
/^Active:/ { active=$2 } | ||
/^Inactive:/ { inactive=$2 } | ||
END { if ( fc == 1 ) { free=free+cache+buff } | ||
{ freeperct=free/tot*100 } | ||
if ( freeperct > warn ) { result="OK" ; xit="0"} | ||
if ( freeperct <= warn ) { | ||
if ( freeperct > crit ) { result="WARNING" ; xit="1" } | ||
else if ( freeperct <= crit ) { result="CRITICAL" ; xit="2" } | ||
} | ||
{print xit" MEMORY "result" - "freeperct"% Free - Total:"tot/divnum div" Active:"active/divnum div" Inactive:"inactive/divnum div" Buffers:"buff/divnum div" Cached:"cache/divnum div" |Free="freeperct";"warn";"crit";0 Active="active";0;0;0 Inactive="inactive";0;0;0 Buffers="buff";0;0;0 Cached="cache";0;0;0" } | ||
}' /proc/meminfo) | ||
|
||
echo ${RESULT#* } | ||
exit ${RESULT%% *} |
Oops, something went wrong.