def test_create_request_from_metrics(self): metrics = [('users', 34, 123456), ('cpu', 78, 98765)] self.assertEqual(["users 34 123456", "cpu 78 98765"], Graphite.create_request_from_metrics(metrics), ) metrics = [('no.time', 34), ('is.fine', 78, time())] self.assertEqual(2, len(Graphite.create_request_from_metrics(metrics)))
def test_equality_based_on_attrs(self): graphite1 = Graphite('example.org', 2003) graphite2 = Graphite('localhost', 2004) self.assertNotEqual(graphite1, graphite2) graphite1.host = 'localhost' graphite1.port = 2004 self.assertEqual(graphite1, graphite2)
def test_create_destinations(self): app = App(['--config', self.config_filename]) destinations = app.create_destinations() self.assertEqual(1, len(destinations)) self.assertEqual([Stdout()], destinations) app_flush_graphite = App(['--flush-graphite', 'localhost']) destinations = app_flush_graphite.create_destinations() self.assertEqual(1, len(destinations)) self.assertEqual([Graphite('localhost', 2003)], destinations) app_multi_flush = App([ '--config', self.config_filename, '--flush-graphite', 'example.org:2006,localhost' ]) destinations = app_multi_flush.create_destinations() self.assertEqual(3, len(destinations)) expected = [ Stdout(), Graphite('example.org', 2006), Graphite('localhost', 2003) ] self.assertEqual(expected, destinations)
def create_destinations(self): # type: () -> List[AbstractDestination] destinations = [] # type: List[AbstractDestination] if self._config.get('flush_stdout'): destinations.append(Stdout()) if self._config.get('flush_graphite'): for graphite_address in self._config['flush_graphite'].split(','): graphite_address = graphite_address.strip().split(':') graphite_host = graphite_address.pop(0).strip() graphite_port = graphite_address and int( graphite_address.pop()) or 2003 destinations.append(Graphite(graphite_host, graphite_port)) if self._config.get('flush_file'): for file_path in self._config['flush_file'].split('|'): destinations.append(TextFile(file_path)) if self._config.get('flush_file_csv'): for file_path in self._config['flush_file_csv'].split('|'): destinations.append(CsvFile(file_path)) return destinations