Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
update to use threads when getting data from sensu-api; update vagran…
Browse files Browse the repository at this point in the history
…t file for multiple local test hosts
  • Loading branch information
alex-leonhardt committed Apr 9, 2016
1 parent b3062b9 commit d926c2a
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 43 deletions.
122 changes: 82 additions & 40 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.vm.box = "centos65-x86_64-20140116"
config.vm.provider "virtualbox" do |vb|
vb.memory = "768"
end

config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 4567, host: 4567
#config.vm.network "forwarded_port", guest: 5000, host: 5000

config.vm.synced_folder ".", "/vagrant"
config.vm.synced_folder ".", "/opt/sensu-grid"

config.vm.provision "shell", inline: <<-SHELL
config.vm.provision "shell", inline: <<-SHELL
sudo yum -y install epel-release vim-enhanced
sudo su -c cat >/etc/yum.repos.d/sensu.repo<<EOF
[sensu]
Expand All @@ -27,32 +16,85 @@ baseurl=http://repos.sensuapp.org/yum/el/6/x86_64/
gpgcheck=0
enabled=1
EOF
sudo yum -y install sensu uchiwa rabbitmq-server redis
sudo chkconfig rabbitmq-server on
sudo chkconfig redis on
sudo chkconfig sensu-client on
sudo chkconfig sensu-server on
sudo chkconfig sensu-api on
sudo chkconfig uchiwa on
cp -rp /vagrant/vagrant-sensu-config/* /etc/sensu/
sudo service rabbitmq-server restart
sudo service redis restart
sudo service sensu-client stop
sudo service sensu-client start
sudo service sensu-api stop
sudo service sensu-api start
sudo service sensu-server stop
sudo service sensu-server start
sudo service uchiwa restart
sudo yum -y install supervisor python-pip python-devel
sudo pip install -r /vagrant/requirements.txt
sudo cp /vagrant/start-scripts/supervisord.conf /etc/supervisord.conf
sudo service supervisord start
SHELL
sudo yum -y install sensu uchiwa rabbitmq-server redis
sudo chkconfig rabbitmq-server on
sudo chkconfig redis on
sudo chkconfig sensu-client on
sudo chkconfig sensu-server on
sudo chkconfig sensu-api on
sudo chkconfig uchiwa on
cp -rp /vagrant/vagrant-sensu-config/* /etc/sensu/
sudo service rabbitmq-server restart
sudo service redis restart
sudo service sensu-client stop
sudo service sensu-client start
sudo service sensu-api stop
sudo service sensu-api start
sudo service sensu-server stop
sudo service sensu-server start
sudo service uchiwa restart
sudo yum -y install supervisor python-pip python-devel
sudo pip install -r /vagrant/requirements.txt
sudo cp /vagrant/start-scripts/supervisord.conf /etc/supervisord.conf
sudo service supervisord start
SHELL

config.vm.define "vagrant1" do |vagrant1|

vagrant1.vm.box = "bento/centos-6.7"
vagrant1.vm.provider "virtualbox" do |vb|
vb.memory = "768"
end

vagrant1.vm.network "forwarded_port", guest: 3000, host: 3000
vagrant1.vm.network "forwarded_port", guest: 4567, host: 4567

vagrant1.vm.synced_folder ".", "/vagrant"
vagrant1.vm.synced_folder ".", "/opt/sensu-grid"


end

config.vm.define "vagrant2" do |vagrant2|


vagrant2.vm.box = "bento/centos-6.7"
vagrant2.vm.provider "virtualbox" do |vb|
vb.memory = "768"
end

vagrant2.vm.network "forwarded_port", guest: 3000, host: 3001
vagrant2.vm.network "forwarded_port", guest: 4567, host: 4568

vagrant2.vm.synced_folder ".", "/vagrant"
vagrant2.vm.synced_folder ".", "/opt/sensu-grid"


end

config.vm.define "vagrant3" do |vagrant3|


vagrant3.vm.box = "bento/centos-6.7"
vagrant3.vm.provider "virtualbox" do |vb|
vb.memory = "768"
end

vagrant3.vm.network "forwarded_port", guest: 3000, host: 3002
vagrant3.vm.network "forwarded_port", guest: 4567, host: 4569

vagrant3.vm.synced_folder ".", "/vagrant"
vagrant3.vm.synced_folder ".", "/opt/sensu-grid"


end



end
12 changes: 11 additions & 1 deletion conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@
---
dcs:
-
name: vagrant
name: dev
url: localhost
port: 4567
uchiwa: http://localhost:3000
-
name: qa
url: localhost
port: 4568
uchiwa: http://localhost:3001
-
name: stage
url: localhost
port: 4569
uchiwa: http://localhost:3002

app:
refresh: 60
Expand Down
44 changes: 42 additions & 2 deletions sensugrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import nested_scopes
from __future__ import division
from __future__ import generators

from flask import Flask
from flask import render_template
from flask import abort
import json

from reverseproxied import ReverseProxied
from griddata import *
from gridconfig import *

try:
from Queue import Queue
except ImportError:
from queue import Queue

from threading import Thread

import json
import time

app = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app)

Expand All @@ -15,13 +31,37 @@
appcfg = app.config['APPCFG']


def get_agg_data(q, list):
while True:
dc = q.get()
list.append(agg_data(dc, get_data(dc), get_stashes(dc)))
q.task_done()
return list


@app.route('/', methods=['GET'])
def root():

# _now = time.time()
aggregated = []
_queue = Queue()

for x in range(len(dcs)):
worker = Thread(target=get_agg_data, args=(_queue,aggregated,))
worker.setDaemon(True)
worker.start()

for dc in dcs:
# print (dc)
if check_connection(dc):
aggregated.append(agg_data(dc, get_data(dc), get_stashes(dc)))
_queue.put(dc)

_queue.join()

# _finish = time.time()
# print (_finish - _now)

aggregated = sorted(aggregated, key=lambda k: k['name'])
return render_template('data.html', dcs=dcs, data=aggregated, filter_data=get_filter_data(dcs), appcfg=appcfg)


Expand Down

0 comments on commit d926c2a

Please sign in to comment.