[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Gerhard Lausser gerhard.lausser at consol.de
Tue Feb 28 22:08:33 UTC 2012


The following commit has been merged in the debian/master branch:
commit ad0bc080a7d1fc256d754cb1bd790a792b78346a
Author: Gerhard Lausser <gerhard.lausser at consol.de>
Date:   Wed Dec 14 01:45:43 2011 +0100

    *prepare a testcase for performance measurements of the livestatus logs

diff --git a/shinken/modules/livestatus_broker/livestatus_db.py b/shinken/modules/livestatus_broker/livestatus_db.py
index 7c6afce..862f2a6 100644
--- a/shinken/modules/livestatus_broker/livestatus_db.py
+++ b/shinken/modules/livestatus_broker/livestatus_db.py
@@ -51,6 +51,7 @@ class LiveStatusDb(object):
         # Get no problem for utf8 insert
         self.dbconn.text_factory = str
         self.dbcursor = self.dbconn.cursor()
+        #self.execute("PRAGMA cache_size = 200000")
         # Create db file and tables if not existing
         self.prepare_log_db_table()
         # Start with commit and rotate immediately so the interval timers
diff --git a/test/test_livestatus_db.py b/test/test_livestatus_db.py
index 79ce45c..4d7bc3a 100755
--- a/test/test_livestatus_db.py
+++ b/test/test_livestatus_db.py
@@ -27,6 +27,7 @@
 
 from shinken_test import *
 import os
+import sys
 import re
 import subprocess
 import shutil
@@ -395,6 +396,173 @@ Columns: time type options state host_name"""
         print "archive is", archives_path
 
 
+
+class TestConfigBig(TestConfig):
+    def setUp(self):
+        start_setUp = time.time()
+        self.setup_with_file('etc/nagios_5r_100h_2000s.cfg')
+        Comment.id = 1
+        self.testid = str(os.getpid() + random.randint(1, 1000))
+        self.init_livestatus()
+        print "Cleaning old broks?"
+        self.sched.fill_initial_broks()
+        self.update_broker()
+        print "************* Overall Setup:", time.time() - start_setUp
+        # add use_aggressive_host_checking so we can mix exit codes 1 and 2
+        # but still get DOWN state
+        host = self.sched.hosts.find_by_name("test_host_000")
+        host.__class__.use_aggressive_host_checking = 1
+
+
+    def init_livestatus(self):
+        self.livelogs = 'tmp/livelogs.db' + self.testid
+        self.db_archives = os.path.join(os.path.dirname(self.livelogs), 'archive
+s')
+        self.pnp4nagios = 'tmp/pnp4nagios_test' + self.testid
+        self.livestatus_broker = Livestatus_broker(livestatus_modconf, '127.0.0.1', str(50000 + os.getpid()), 'live', [], self.livelogs, self.db_archives, 365, self.pnp4nagios)
+        self.livestatus_broker.create_queues()
+        #self.livestatus_broker.properties = {
+        #    'to_queue' : 0,
+        #    'from_queue' : 0
+        #
+        #    }
+        self.livestatus_broker.init()
+        self.livestatus_broker.db = LiveStatusDb(self.livestatus_broker.database_file, self.livestatus_broker.archive_path, self.livestatus_broker.max_logs_age)
+
+        self.livestatus_broker.livestatus = LiveStatus(self.livestatus_broker.configs, self.livestatus_broker.hosts, self.livestatus_broker.services, self.livestatus_broker.contacts, self.livestatus_broker.hostgroups, self.livestatus_broker.servicegroups, self.livestatus_broker.contactgroups, self.livestatus_broker.timeperiods, self.livestatus_broker.commands, self.livestatus_broker.schedulers, self.livestatus_broker.pollers, self.livestatus_broker.reactionners, self.livestatus_broker.brokers, self.livestatus_broker.db, self.livestatus_broker.pnp_path, self.livestatus_broker.from_q)
+
+
+
+    def tearDown(self):
+        self.livestatus_broker.db.commit()
+        self.livestatus_broker.db.close()
+        if os.path.exists(self.pnp4nagios):
+            shutil.rmtree(self.pnp4nagios)
+        if os.path.exists('var/nagios.log'):
+            os.remove('var/nagios.log')
+        if os.path.exists('var/retention.dat'):
+            os.remove('var/retention.dat')
+        if os.path.exists('var/status.dat'):
+            os.remove('var/status.dat')
+        to_del = [attr for attr in self.livestatus_broker.livestatus.__class__.out_map['Host'].keys() if attr.startswith('host_')]
+        for attr in to_del:
+            del self.livestatus_broker.livestatus.__class__.out_map['Host'][attr]
+        self.livestatus_broker = None
+
+
+    def test_a_long_history(self):
+        test_host_005 = self.sched.hosts.find_by_name("test_host_005")
+        test_host_099 = self.sched.hosts.find_by_name("test_host_099")
+        test_ok_00 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_00")
+        test_ok_01 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_01")
+        test_ok_04 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_04")
+        test_ok_16 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_16")
+        test_ok_99 = self.sched.services.find_srv_by_name_and_hostname("test_host_099", "test_ok_01")
+        starttime = time.time()
+        # run silently
+        old_stdout = sys.stdout
+        sys.stdout = open(os.devnull, "w")
+        self.scheduler_loop(2, [
+            [test_ok_00, 0, "OK"],
+            [test_ok_01, 0, "OK"],
+            [test_ok_04, 0, "OK"],
+            [test_ok_16, 0, "OK"],
+            [test_ok_99, 0, "OK"],
+        ])
+        self.update_broker()
+        should_be = 0
+        #for i in xrange(3600 * 24 * 7):
+        for i in xrange(100000): 
+            if i % 399 == 0:
+                self.scheduler_loop(3, [
+                    [test_ok_00, 1, "WARN"],
+                    [test_ok_01, 2, "CRIT"],
+                    [test_ok_04, 3, "UNKN"],
+                    [test_ok_16, 1, "WARN"],
+                    [test_ok_99, 2, "CRIT"],
+                ])
+                should_be += 3
+            time.sleep(62)
+            if i % 399 == 0:
+                self.scheduler_loop(1, [
+                    [test_ok_00, 0, "OK"],
+                    [test_ok_01, 0, "OK"],
+                    [test_ok_04, 0, "OK"],
+                    [test_ok_16, 0, "OK"],
+                    [test_ok_99, 0, "OK"],
+                ])
+                should_be += 1
+            time.sleep(2)
+            if i % 199 == 0:
+                self.scheduler_loop(3, [
+                    [test_ok_00, 1, "WARN"],
+                    [test_ok_01, 2, "CRIT"],
+                ])
+            time.sleep(62)
+            if i % 199 == 0:
+                self.scheduler_loop(1, [
+                    [test_ok_00, 0, "OK"],
+                    [test_ok_01, 0, "OK"],
+                ])
+            time.sleep(2)
+            if i % 299 == 0:
+                self.scheduler_loop(3, [
+                    [test_host_005, 2, "DOWN"],
+                ])
+            if i % 19 == 0:
+                self.scheduler_loop(3, [
+                    [test_host_099, 2, "DOWN"],
+                ])
+            time.sleep(62)
+            if i % 299 == 0:
+                self.scheduler_loop(3, [
+                    [test_host_005, 0, "UP"],
+                ])
+            if i % 19 == 0:
+                self.scheduler_loop(3, [
+                    [test_host_099, 0, "UP"],
+                ])
+            time.sleep(2)
+        self.update_broker()
+        endtime = time.time()
+        sys.stdout.close()
+        sys.stdout = old_stdout
+        # now we have a lot of events
+        # find type = HOST ALERT for test_host_005
+        request = """GET log
+Columns: class time type state host_name service_description plugin_output message options contact_name command_name state_type current_host_groups current_service_groups
+Filter: time >= """ + str(int(starttime)) + """
+Filter: time <= """ + str(int(endtime)) + """
+Filter: type = SERVICE ALERT
+And: 1
+Filter: type = HOST ALERT
+And: 1
+Filter: type = SERVICE FLAPPING ALERT
+Filter: type = HOST FLAPPING ALERT
+Filter: type = SERVICE DOWNTIME ALERT
+Filter: type = HOST DOWNTIME ALERT
+Filter: type ~ starting...
+Filter: type ~ shutting down...
+Or: 8
+Filter: host_name = test_host_099
+Filter: service_description = test_ok_01
+And: 5
+OutputFormat: json"""
+        time.time = original_time_time
+        time.sleep = original_time_sleep
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+        pyresponse = eval(response)
+        print "number of records", len(pyresponse)
+        print "should be", should_be
+        numlogs = self.livestatus_broker.db.execute("SELECT min(time), max(time) FROM logs")
+        print starttime, endtime, numlogs
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+
+
+
 if __name__ == '__main__':
     #import cProfile
     command = """unittest.main()"""

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list