def test_proc_error_es(self): es = ESFileLogger() es.proc_error(11111, 22, "epic fail") es.proc_error(11111, 9758, "fail") es.proc_error(11112, 7364, "little fail") es.close() actual = open(utils.event_log + ".es").read() expected = pkg_resources.resource_string( self.__module__, 'expected_events.es').decode('utf8') t_assert.equal(actual, expected)
def test_proc_info_es(self): es = ESFileLogger() es.proc_info(11111, 22, "proc1") es.proc_info(11111, 9758, "proc2") es.proc_info(11111, 7364, "proc4") es.proc_info(11111, 3332, "proc3") es.close() actual = open(utils.proc_info_log + ".es").read() expected = pkg_resources.resource_string( self.__module__, 'expected_proc_info.es').decode('utf8') t_assert.equal(actual, expected)
def test_cpu_sys_es(self): es = ESFileLogger() es.cpu_sys(0, 1, 1, 1, 1) es.cpu_sys(1, 3, 2, 5, 6) es.cpu_sys(3, 22, 99, 11, 4) es.cpu_sys(5, 155, 122, 12, 22) es.close() actual = open(utils.cpu_sys_log + ".es").read() expected = pkg_resources.resource_string( __name__, 'expected_cpu_sys.es').decode('utf8') t_assert.equal(actual, expected)
def test_proc_error_es(self): es = ESFileLogger() es.proc_error(11111, 22, "epic fail") es.proc_error(11111, 9758, "fail") es.proc_error(11112, 7364, "little fail") es.close() actual = open(utils.event_log+".es").read() expected = pkg_resources.resource_string(self.__module__, 'expected_events.es').decode('utf8') t_assert.equal(actual, expected)
def test_cpu_sys_es(self): es = ESFileLogger() es.cpu_sys(0, 1, 1, 1, 1) es.cpu_sys(1, 3, 2, 5, 6) es.cpu_sys(3, 22, 99, 11, 4) es.cpu_sys(5, 155, 122, 12, 22) es.close() actual = open(utils.cpu_sys_log+".es").read() expected = pkg_resources.resource_string(__name__, 'expected_cpu_sys.es').decode('utf8') t_assert.equal(actual, expected)
def test_proc_info_es(self): es = ESFileLogger() es.proc_info(11111, 22, "proc1") es.proc_info(11111, 9758, "proc2") es.proc_info(11111, 7364, "proc4") es.proc_info(11111, 3332, "proc3") es.close() actual = open(utils.proc_info_log+".es").read() expected = pkg_resources.resource_string(self.__module__, 'expected_proc_info.es').decode('utf8') t_assert.equal(actual, expected)
def init(): global loggers global proc_poller global cpu_poller global mem_poller global io_poller loggers = [] if (config.ES_FILE_ENABLED): loggers.append(ESFileLogger()) if (config.ES_NW_ENABLED): loggers.append(ESNetLogger()) if (config.MYSQL_ENABLED): loggers.append(MySqlLogger()) if (config.CSV_ENABLED): loggers.append(CSVFileLogger()) if (config.KAFKA_ENABLED): loggers.append(KafkaLogger()) proc_poller = ProcPoller(loggers) cpu_poller = CPUPoller(proc_poller, loggers) mem_poller = MemPoller(proc_poller, loggers) io_poller = IOPoller(loggers)
pid = proc.pid pname = self.proc_poller.get_name(proc) priority = proc.nice() #status is a text indicator such as "running". ignoring for now. # status = proc.status() ctx_switches = proc.num_ctx_switches() ctx_count = ctx_switches.voluntary + ctx_switches.involuntary n_threads = proc.num_threads() cpu_times = proc.cpu_times() cpu_user = cpu_times.user cpu_system = cpu_times.system cpu_percent = proc.cpu_percent() for logger in self.loggers: logger.cpu_proc(epoch, pid, priority, ctx_count, n_threads, cpu_user, cpu_system, cpu_percent, pname) except (psutil.NoSuchProcess, psutil.AccessDenied): #if the process has disappeared, we get an exception and ignore it #pass <- pass is NOP in Python self.proc_poller.handle_process_poll_error(epoch, proc) if __name__ == "__main__": csv = CSVFileLogger() es = ESFileLogger() proc = ProcPoller(csv, es) cpu_poller = CPUPoller(proc, csv, es) while (True): cpu_poller.poll() time.sleep(config.INTERVAL) csv.close()
def test_io_sys_es(self): es = ESFileLogger() es.io_sys(11111, 22, 22, 34, 43, 11, 11, 5, 3) es.io_sys(22222, 55, 23, 44, 34, 23, 17, 15, 4) es.io_sys(22233, 65, 23, 777, 44, 28, 18, 35, 5) es.io_sys(25555, 78, 44, 1911, 53, 99434, 43, 43, 21) es.close() actual = open(utils.io_sys_log + ".es").read() expected = pkg_resources.resource_string( self.__module__, 'expected_io_sys.es').decode('utf8') t_assert.equal(actual, expected)
def test_mem_proc_es(self): es = ESFileLogger() es.mem_proc(0, 1, 11, 15, 5, "p1") es.mem_proc(0, 2, 1, 3, 2, "p2") es.mem_proc(0, 5432, 21, 33, 9, "p3") es.mem_proc(5, 1, 22, 11, 3, "p1") es.mem_proc(5, 5432, 7, 55, 7, "p3") es.mem_proc(66, 1, 11, 15, 5, "p1") es.mem_proc(66, 2, 11, 0, 22, "p2") es.mem_proc(66, 5432, 212, 334, 44, "p3") es.close() actual = open(utils.mem_proc_log + ".es").read() expected = pkg_resources.resource_string( self.__module__, 'expected_mem_proc.es').decode('utf8') t_assert.equal(actual, expected)
def test_mem_sys_es(self): es = ESFileLogger() es.mem_sys(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) es.mem_sys(10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) es.mem_sys(12, 34, 654, 24, 33, 23, 442, 1, 13, 21, 44) es.mem_sys(15, 3445, 345, 345, 44, 745, 367, 32, 1111, 33, 55) es.mem_sys(33, 33, 453, 998, 347, 976, 8544, 45, 5555, 66, 33) es.close() actual = open(utils.mem_sys_log + ".es").read() expected = pkg_resources.resource_string( self.__module__, 'expected_mem_sys.es').decode('utf8') t_assert.equal(actual, expected)
def test_cpu_proc_es(self): es = ESFileLogger() es.cpu_proc(0, 1, 1, 1, 1, 1, 1, 1, "p1") es.cpu_proc(0, 2, 1, 3, 4, 2, 3, 1, "p2") es.cpu_proc(0, 3, 2, 122, 7, 5, 8, 11, "p3") es.cpu_proc(10, 1, 1, 1, 1, 1, 1, 1, "p1") es.cpu_proc(10, 2, 1, 3, 4, 2, 3, 1, "p2") es.cpu_proc(10, 3, 2, 122, 7, 5, 8, 11, "p3") es.cpu_proc(20, 1, 1, 5, 1, 4, 3, 2, "p1") es.cpu_proc(20, 3, 2, 555, 7, 11, 55, 32, "p3") es.close() actual = open(utils.cpu_proc_log + ".es").read() expected = pkg_resources.resource_string( self.__module__, 'expected_cpu_proc.es').decode('utf8') t_assert.equal(actual, expected)
def test_io_sys_es(self): es = ESFileLogger() es.io_sys(11111, 22, 22, 34, 43, 11, 11, 5, 3) es.io_sys(22222, 55, 23, 44, 34, 23, 17, 15, 4) es.io_sys(22233, 65, 23, 777, 44, 28, 18, 35, 5) es.io_sys(25555, 78, 44, 1911, 53, 99434, 43, 43, 21) es.close() actual = open(utils.io_sys_log+".es").read() expected = pkg_resources.resource_string(self.__module__, 'expected_io_sys.es').decode('utf8') t_assert.equal(actual, expected)
def test_mem_proc_es(self): es = ESFileLogger() es.mem_proc(0, 1, 11, 15, 5, "p1") es.mem_proc(0, 2, 1, 3, 2, "p2") es.mem_proc(0, 5432, 21, 33, 9, "p3") es.mem_proc(5, 1, 22, 11, 3, "p1") es.mem_proc(5, 5432, 7, 55, 7, "p3") es.mem_proc(66, 1, 11, 15, 5, "p1") es.mem_proc(66, 2, 11, 0, 22, "p2") es.mem_proc(66, 5432, 212, 334, 44, "p3") es.close() actual = open(utils.mem_proc_log+".es").read() expected = pkg_resources.resource_string(self.__module__, 'expected_mem_proc.es').decode('utf8') t_assert.equal(actual, expected)
def test_mem_sys_es(self): es = ESFileLogger() es.mem_sys(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) es.mem_sys(10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) es.mem_sys(12, 34, 654, 24, 33, 23, 442, 1, 13, 21, 44) es.mem_sys(15, 3445, 345, 345, 44, 745, 367, 32, 1111, 33, 55) es.mem_sys(33, 33, 453, 998, 347, 976, 8544, 45, 5555, 66, 33) es.close() actual = open(utils.mem_sys_log+".es").read() expected = pkg_resources.resource_string(self.__module__, 'expected_mem_sys.es').decode('utf8') t_assert.equal(actual, expected)
def test_cpu_proc_es(self): es = ESFileLogger() es.cpu_proc(0, 1, 1, 1, 1, 1, 1, 1, "p1") es.cpu_proc(0, 2, 1, 3, 4, 2, 3, 1, "p2") es.cpu_proc(0, 3, 2, 122, 7, 5, 8, 11, "p3") es.cpu_proc(10, 1, 1, 1, 1, 1, 1, 1, "p1") es.cpu_proc(10, 2, 1, 3, 4, 2, 3, 1, "p2") es.cpu_proc(10, 3, 2, 122, 7, 5, 8, 11, "p3") es.cpu_proc(20, 1, 1, 5, 1, 4, 3, 2, "p1") es.cpu_proc(20, 3, 2, 555, 7, 11, 55, 32, "p3") es.close() actual = open(utils.cpu_proc_log+".es").read() #what is the diff with __name__ vs self.__module__? who knows.. expected = pkg_resources.resource_string(self.__module__, 'expected_cpu_proc.es').decode('utf8') t_assert.equal(actual, expected)