Esempio n. 1
0
    def test_should_return_all_backends(self, now_mock):
        now_mock.return_value = datetime(2011, 10, 0o1)
        now = '2011-09-30T23:00:00Z'
        state = ServerState()

        state.update_backend('varnish1', 'web2', 'healthy', '200', 'OK')
        state.update_backend('varnish1', 'web1', 'healthy', '200', 'OK')
        backends = state.get_backends('varnish1')

        expected = {
            'backends': [{
                'name': 'web2',
                'state': 'healthy',
                'status_code': '200',
                'status_text': 'OK',
                'timestamp': now
            }, {
                'name': 'web1',
                'state': 'healthy',
                'status_code': '200',
                'status_text': 'OK',
                'timestamp': now
            }]
        }

        self.assertEquals(expected, backends)
Esempio n. 2
0
    def test_should_return_empty_list_when_no_backends(self):
        state = ServerState()

        state._get_server('varnish1')
        process_state = state.get_backends('varnish1')

        self.assertEquals({'backends': []}, process_state)
Esempio n. 3
0
    def test_should_return_empty_list_when_no_varnish_stat_values(self):
        state = ServerState()

        state._get_server('varnish1')
        process_state = state.get_varnishstats('varnish1')

        self.assertEquals({'varnishstats': []}, process_state)
Esempio n. 4
0
    def test_should_return_empty_dict_for_unknown_backend(self):
        state = ServerState()

        state.update_backend('varnish1', 'web2', 'healthy', '200', 'OK')

        backend_state = state.get_backend('varnish1', 'web1')

        self.assertEquals({}, backend_state)
Esempio n. 5
0
    def test_should_return_zero_values_for_empty_process(self):
        state = ServerState()

        state._get_server('varnish1')
        process_state = state.get_process('varnish1')
        
        self.assertEquals({'virtualmem_mb': 0, 'reservedmem_mb': 0,
                           'cpu': 0.0, 'memory': 0.0}, process_state)
Esempio n. 6
0
    def test_should_update_process_state(self):
        state = ServerState()

        state.update_process('varnish1', '410m', '109m', '2.0', '2.8')
        process_state = state.get_process('varnish1')

        self.assertEquals({'virtualmem_mb': 410, 'reservedmem_mb': 109,
                           'cpu': 2.0, 'memory': 2.8}, process_state)
Esempio n. 7
0
    def test_should_return_dict_of_servers(self):
        state = ServerState()

        state._get_server('varnish1')
        state._get_server('varnish2')
        servers = state.get_servers()

        self.assertEquals({'servers': ['varnish1', 'varnish2']}, servers)
Esempio n. 8
0
    def test_should_return_empty_dict_for_unknown_backend(self):
        state = ServerState()

        state.update_backend('varnish1', 'web2', 'healthy', '200', 'OK')

        backend_state = state.get_backend('varnish1', 'web1')

        self.assertEquals({}, backend_state)
Esempio n. 9
0
    def test_should_return_dict_of_servers(self):
        state = ServerState()

        state._get_server('varnish1')
        state._get_server('varnish2')
        servers = state.get_servers()

        self.assertEquals({'servers': ['varnish1', 'varnish2']}, servers)
Esempio n. 10
0
    def test_should_update_varnish_stats(self):
        state = ServerState()

        state.update_varnishstats('varnish1', [{'name': 'conns', 'value': 34.3,
                                  'description': 'connections'}])
        process_state = state.get_varnishstats('varnish1')

        self.assertEquals({'varnishstats': [{'name': 'conns', 'value': 34.3,
                           'description': 'connections'}]}, process_state)
Esempio n. 11
0
    def test_should_update_backend_state(self, now_mock):
        now_mock.return_value = datetime(2011, 10, 0o1)
        state = ServerState()

        state.update_backend('varnish1', 'web2', 'healthy', '200', 'OK')

        backend_state = state.get_backend('varnish1', 'web2')

        self.assertEquals({'name': 'web2', 'state': 'healthy',
                           'status_code': '200', 'status_text': 'OK',
                           'timestamp': '2011-09-30T23:00:00Z'},
                           backend_state)
Esempio n. 12
0
    def test_should_update_process_state(self):
        state = ServerState()

        state.update_process('varnish1', '410m', '109m', '2.0', '2.8')
        process_state = state.get_process('varnish1')

        self.assertEquals(
            {
                'virtualmem_mb': 410,
                'reservedmem_mb': 109,
                'cpu': 2.0,
                'memory': 2.8
            }, process_state)
Esempio n. 13
0
    def test_should_return_zero_values_for_empty_process(self):
        state = ServerState()

        state._get_server('varnish1')
        process_state = state.get_process('varnish1')

        self.assertEquals(
            {
                'virtualmem_mb': 0,
                'reservedmem_mb': 0,
                'cpu': 0.0,
                'memory': 0.0
            }, process_state)
Esempio n. 14
0
    def test_should_update_backend_state(self, now_mock):
        now_mock.return_value = datetime(2011, 10, 0o1)
        state = ServerState()

        state.update_backend('varnish1', 'web2', 'healthy', '200', 'OK')

        backend_state = state.get_backend('varnish1', 'web2')

        self.assertEquals(
            {
                'name': 'web2',
                'state': 'healthy',
                'status_code': '200',
                'status_text': 'OK',
                'timestamp': '2011-09-30T23:00:00Z'
            }, backend_state)
Esempio n. 15
0
    def test_should_return_all_backends(self, now_mock):
        now_mock.return_value = datetime(2011, 10, 0o1)
        now = '2011-09-30T23:00:00Z'
        state = ServerState()

        state.update_backend('varnish1', 'web2', 'healthy', '200', 'OK')
        state.update_backend('varnish1', 'web1', 'healthy', '200', 'OK')
        backends = state.get_backends('varnish1')

        expected = {'backends': [{'name': 'web2', 'state': 'healthy',
                                  'status_code': '200', 'status_text': 'OK',
                                  'timestamp': now},
                                 {'name': 'web1', 'state': 'healthy',
                                  'status_code': '200', 'status_text': 'OK',
                                  'timestamp': now}]}

        self.assertEquals(expected, backends)
Esempio n. 16
0
    def test_should_update_varnish_stats(self):
        state = ServerState()

        state.update_varnishstats('varnish1', [{
            'name': 'conns',
            'value': 34.3,
            'description': 'connections'
        }])
        process_state = state.get_varnishstats('varnish1')

        self.assertEquals(
            {
                'varnishstats': [{
                    'name': 'conns',
                    'value': 34.3,
                    'description': 'connections'
                }]
            }, process_state)
Esempio n. 17
0
def main(config, static_path):
    hostname = 'testing'
    monitor = WorkerMonitor()
    server_state = ServerState()
    if not config['test']:
        for server_config in config['servers']:
            add_server(monitor, server_config, server_state,
                       config['stat_window'])
        print('Started gathering varnish data')

    else:
        from tests.data_generator import DummyDataGenerator
        dummydata = DummyDataGenerator(server_state)
        worker = Worker('Testing', dummydata)
        monitor.add_worker(worker)

    Worker('WorkerMonitor', monitor).start()
    http_server.start(server_state, static_path, config['port'],
                      config['wsgi_server'])

    print('Simverest stopping...')
    monitor.stop()
Esempio n. 18
0
from bottle import Bottle, redirect, request, response
import bottle
import utils
from data.server_state import ServerState

api = Bottle()
api.VARNISH_STATE = ServerState()
api.MOUNT_POINT = '/'


@api.route('/')
def redirect_api_servers():
    redirect(api.MOUNT_POINT + "/servers")


@api.route('/servers')
def servers():
    return api.VARNISH_STATE.get_servers()


@api.route('/server/:name')
def server_stats(name):
    backends = api.VARNISH_STATE.get_backends(name)
    if backends == {}:
        return {}

    varnishstats = api.VARNISH_STATE.get_varnishstats(name)
    stats = {
        'process': api.VARNISH_STATE.get_process(name),
        'varnishstats': varnishstats['varnishstats'],
        'backends': backends['backends'],
Esempio n. 19
0
    def test_should_return_empty_dict_for_unknown_hostname_for_stat(self):
        state = ServerState()

        process_state = state.get_varnishstats('varnish1')

        self.assertEquals({}, process_state)
Esempio n. 20
0
    def test_should_return_empty_dict_for_unknown_hostname_for_process(self):
        state = ServerState()

        process_state = state.get_process('varnish1')

        self.assertEquals({}, process_state)
Esempio n. 21
0
    def test_should_return_empty_dict_for_unknown_hostname_for_backend(self):
        state = ServerState()

        backend_state = state.get_backend('varnish1', 'web1')

        self.assertEquals({}, backend_state)
Esempio n. 22
0
    def test_should_return_empty_dict_for_unknown_hostname_for_backend(self):
        state = ServerState()

        backend_state = state.get_backend('varnish1', 'web1')

        self.assertEquals({}, backend_state)
Esempio n. 23
0
    def test_should_return_empty_dict_of_servers(self):
        state = ServerState()

        servers = state.get_servers()

        self.assertEquals({'servers': []}, servers)
Esempio n. 24
0
    def test_should_return_empty_dict_of_servers(self):
        state = ServerState()

        servers = state.get_servers()

        self.assertEquals({'servers': []}, servers)