Example #1
0
 def test_send_dict_with_timestamp(self):
     graphitesend.init(system_name='')
     graphitesend.send_dict({'test_send_dict': 50}, 1)
     (c, addr) = self.server.accept()
     sent_on_socket = str(c.recv(69))
     print(sent_on_socket)
     self.assertIn('test_send_dict 50.000000 1', sent_on_socket)
Example #2
0
 def test_send_dict_with_timestamp(self):
     graphitesend.init(system_name='')
     graphitesend.send_dict({'test_send_dict': 50}, 1)
     (c, addr) = self.server.accept()
     sent_on_socket = str(c.recv(69))
     print(sent_on_socket)
     self.assertIn('test_send_dict 50.000000 1', sent_on_socket)
Example #3
0
 def test_send_list_str_to_int(self):
     graphitesend.init(system_name='')
     graphitesend.send_list([
         ('test_send_list', '50'),
     ])
     (c, addr) = self.server.accept()
     sent_on_socket = c.recv(69)
     self.assertIn('test_send_list 50.000000', sent_on_socket)
Example #4
0
    def test_send(self):
        with self.assertRaises(graphitesend.GraphiteSendException):
            graphitesend.send('test_metric', 50)

        graphitesend.init(system_name='')
        graphitesend.send('test_send', 50)
        (c, addr) = self.server.accept()
        sent_on_socket = c.recv(69)
        self.assertIn('test_send 50.000000', sent_on_socket)
Example #5
0
    def test_send_dict(self):
        with self.assertRaises(graphitesend.GraphiteSendException):
            graphitesend.send_dict({'test_metric': 50})

        graphitesend.init(system_name='')
        graphitesend.send_dict({'test_send_dict': 50})
        (c, addr) = self.server.accept()
        sent_on_socket = str(c.recv(69))
        print(sent_on_socket)
        self.assertIn('test_send_dict 50.000000', sent_on_socket)
Example #6
0
    def test_send_dict(self):
        with self.assertRaises(graphitesend.GraphiteSendException):
            graphitesend.send_dict({'test_metric': 50})

        graphitesend.init(system_name='')
        graphitesend.send_dict({'test_send_dict': 50})
        (c, addr) = self.server.accept()
        sent_on_socket = str(c.recv(69))
        print(sent_on_socket)
        self.assertIn('test_send_dict 50.000000', sent_on_socket)
Example #7
0
    def test_init_as_pickel(self):
        g = graphitesend.init()
        self.assertEqual(type(g), type(graphitesend.GraphiteClient()))

        for init_type in ['plaintext_tcp', 'plaintext', 'plain']:
            g = graphitesend.init(init_type=init_type, dryrun=True)
            self.assertEqual(type(g), type(graphitesend.GraphiteClient()))

        for init_type in ['pickle', 'pickle_tcp']:
            g = graphitesend.init(init_type=init_type, dryrun=True)
            self.assertEqual(type(g),
                             type(graphitesend.GraphitePickleClient()))
Example #8
0
 def test_set_prefix_group_system(self):
     g = graphitesend.init(prefix='prefix',
                           system_name='system',
                           group='group')
     custom_prefix = g.prefix
     expected_prefix = 'prefix.system.group.'
     self.assertEqual(custom_prefix, expected_prefix)
Example #9
0
 def test_send_value_as_string(self):
     # Make sure it can handle custom timestamp
     graphite_instance = graphitesend.init(prefix='')
     response = graphite_instance.send("metric", "1", "1")
     self.assertEqual('1.00000' in response, True)
     print response
     self.assertEqual(response.endswith('1\n'), True)
Example #10
0
 def test_BadGraphtieServer(self):
     graphitesend.default_graphite_server = "BADGRAPHITESERVER"
     g = graphitesend.init(prefix='', dryrun=True)
     self.assertEqual(type(g).__name__, 'GraphiteClient')
     dryrun_message = g.send('metric', 1, 1)
     self.assertEqual(dryrun_message,
                      "%s.metric 1.000000 1\n" % self.hostname)
Example #11
0
 def test_send_value_as_string(self):
     # Make sure it can handle custom timestamp
     graphite_instance = graphitesend.init(prefix='')
     response = graphite_instance.send("metric", "1", "1")
     self.assertEqual('1.00000' in response, True)
     print response
     self.assertEqual(response.endswith('1\n'), True)
Example #12
0
 def test_BadGraphtieServer(self):
     graphitesend.default_graphite_server = "BADGRAPHITESERVER"
     g = graphitesend.init(prefix='', dryrun=True)
     self.assertEqual(type(g).__name__, 'GraphiteClient')
     dryrun_message = g.send('metric', 1, 1)
     self.assertEqual(dryrun_message,
                      "%s.metric 1.000000 1\n" % self.hostname)
Example #13
0
 def test_send_list_metric_value_single_timestamp(self):
     # Make sure it can handle custom timestamp
     graphite_instance = graphitesend.init(prefix='test')
     response = graphite_instance.send_list([('metric', 1)], timestamp=1)
     # self.assertEqual('sent 23 long message: test.metric' in response,
     # True)
     self.assertEqual('1.00000' in response, True)
     self.assertEqual(response.endswith('1\n'), True)
Example #14
0
 def test_str2listtuple_good(self):
     g = graphitesend.init(init_type='pickle')
     pickle_response = g.str2listtuple("path metric 1")
     self.assertEqual(
         pickle_response,
         "\x00\x00\x00.(lp0\n(S'path'\np1\n" +
         "(F1.0\nS'metric'\np2\ntp3\ntp4\na."
     )
Example #15
0
 def test_send_list_metric_value_timestamp_2(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='')
     # Make sure it can handle custom timestamp
     response = graphite_instance.send_list([('metric', 1, 1),
                                             ('metric', 1, 2)])
     # self.assertEqual('sent 46 long message:' in response, True)
     self.assertEqual('test.metric 1.000000 1' in response, True)
     self.assertEqual('test.metric 1.000000 2' in response, True)
Example #16
0
 def test_send_list_metric_value_timestamp_2(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='')
     # Make sure it can handle custom timestamp
     response = graphite_instance.send_list(
         [('metric', 1, 1), ('metric', 1, 2)])
     # self.assertEqual('sent 46 long message:' in response, True)
     self.assertEqual('test.metric 1.000000 1' in response, True)
     self.assertEqual('test.metric 1.000000 2' in response, True)
Example #17
0
 def test_send_list_metric_value_single_timestamp(self):
     # Make sure it can handle custom timestamp
     graphite_instance = graphitesend.init(prefix='test')
     response = graphite_instance.send_list([('metric', 1)], timestamp=1)
     # self.assertEqual('sent 23 long message: test.metric' in response,
     # True)
     self.assertEqual('1.00000' in response, True)
     self.assertEqual(response.endswith('1\n'), True)
Example #18
0
 def test_pickle_send(self):
     g = graphitesend.init(init_type='pickle', system_name='', prefix='')
     (c, addr) = self.pserver.accept()
     g.send('test_pickle', 50, 0)
     sent_on_socket = c.recv(69)
     self.assertEqual(
         sent_on_socket,
         "\x00\x00\x008(lp0\n(S'test_pickle'\np1\n(F0.0\nS'50.000000'\np2\ntp3\ntp4\na."
     )
Example #19
0
    def test_clean_metric_false(self):
        g = graphitesend.init(clean_metric_name=False)

        metric_name = g.clean_metric_name('test(name)')
        self.assertEqual(metric_name, 'test(name)')

        metric_name = g.clean_metric_name('test name')
        self.assertEqual(metric_name, 'test name')

        metric_name = g.clean_metric_name('test__name')
        self.assertEqual(metric_name, 'test__name')
Example #20
0
    def test_clean_metric_false(self):
        g = graphitesend.init(clean_metric_name=False)

        metric_name = g.clean_metric_name('test(name)')
        self.assertEqual(metric_name, 'test(name)')

        metric_name = g.clean_metric_name('test name')
        self.assertEqual(metric_name, 'test name')

        metric_name = g.clean_metric_name('test__name')
        self.assertEqual(metric_name, 'test__name')
Example #21
0
 def test_clean_metric(self):
     g = graphitesend.init()
     #
     metric_name = g.clean_metric_name('test(name)')
     self.assertEqual(metric_name, 'test_name')
     #
     metric_name = g.clean_metric_name('test name')
     self.assertEqual(metric_name, 'test_name')
     #
     metric_name = g.clean_metric_name('test  name')
     self.assertEqual(metric_name, 'test__name')
Example #22
0
 def test_send_reconnect_send_again(self):
     g = graphitesend.init(prefix='', system_name='')
     g.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = str(c.recv(69))
     self.assertIn('test_send 50.000000', sent_on_socket)
     g.reconnect()
     g.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = str(c.recv(69))
     self.assertIn('test_send 50.000000', sent_on_socket)
Example #23
0
 def test_send_reconnect_send_again(self):
     g = graphitesend.init(prefix='', system_name='')
     g.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = c.recv(69)
     self.assertTrue(sent_on_socket.startswith('test_send 50.000000'))
     g.reconnect()
     g.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = c.recv(69)
     self.assertTrue(sent_on_socket.startswith('test_send 50.000000'))
Example #24
0
 def test_clean_metric(self):
     g = graphitesend.init()
     #
     metric_name = g.clean_metric_name('test(name)')
     self.assertEqual(metric_name, 'test_name')
     #
     metric_name = g.clean_metric_name('test name')
     self.assertEqual(metric_name, 'test_name')
     #
     metric_name = g.clean_metric_name('test  name')
     self.assertEqual(metric_name, 'test__name')
Example #25
0
 def test_send_reconnect_send_again(self):
     g = graphitesend.init(prefix='', system_name='')
     g.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = str(c.recv(69))
     self.assertIn('test_send 50.000000', sent_on_socket)
     g.reconnect()
     g.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = str(c.recv(69))
     self.assertIn('test_send 50.000000', sent_on_socket)
Example #26
0
 def test_send_list_metric_value_timestamp_default(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='bar')
     # Make sure it can handle custom timestamp, fill in the missing with
     # the current time.
     response = graphite_instance.send_list([
         ('metric', 1, 1),
         ('metric', 2),
     ],
                                            timestamp='4')
     # self.assertEqual('sent 69 long message:' in response, True)
     self.assertEqual('test.bar.metric 1.000000 1' in response, True)
     self.assertEqual('test.bar.metric 2.000000 4' in response, True)
Example #27
0
    def test_str2listtuple_bad(self):
        g = graphitesend.init(init_type='pickle')
        with self.assertRaises(TypeError):
            g.str2listtuple(54)
        with self.assertRaises(TypeError):
            g.str2listtuple([])
        with self.assertRaises(TypeError):
            g.str2listtuple({})
        with self.assertRaises(ValueError):
            g.str2listtuple("metric")

        with self.assertRaises(ValueError):
            g.str2listtuple("metric value timestamp extra")
Example #28
0
 def test_send_list_metric_value_timestamp_default(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='bar')
     # Make sure it can handle custom timestamp, fill in the missing with
     # the current time.
     response = graphite_instance.send_list(
         [
             ('metric', 1, 1),
             ('metric', 2),
         ],
         timestamp='4'
     )
     # self.assertEqual('sent 69 long message:' in response, True)
     self.assertEqual('test.bar.metric 1.000000 1' in response, True)
     self.assertEqual('test.bar.metric 2.000000 4' in response, True)
Example #29
0
 def test_send_list_metric_value_timestamp_default_2(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='foo')
     # Make sure it can handle custom timestamp, fill in the missing with
     # the current time.
     (c, addr) = self.server.accept()
     response = graphite_instance.send_list([
         ('metric', 1),
         ('metric', 2, 2),
     ],
                                            timestamp='4')
     # self.assertEqual('sent 69 long message:' in response, True)
     self.assertEqual('test.foo.metric 1.000000 4' in response, True)
     self.assertEqual('test.foo.metric 2.000000 2' in response, True)
     sent_on_socket = c.recv(69)
     self.assertEqual('test.foo.metric 1.000000 4' in sent_on_socket, True)
     self.assertEqual('test.foo.metric 2.000000 2' in sent_on_socket, True)
Example #30
0
 def test_send_list_metric_value_timestamp_default_2(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='foo')
     # Make sure it can handle custom timestamp, fill in the missing with
     # the current time.
     (c, addr) = self.server.accept()
     response = graphite_instance.send_list(
         [
             ('metric', 1),
             ('metric', 2, 2),
         ],
         timestamp='4'
     )
     # self.assertEqual('sent 69 long message:' in response, True)
     self.assertEqual('test.foo.metric 1.000000 4' in response, True)
     self.assertEqual('test.foo.metric 2.000000 2' in response, True)
     sent_on_socket = c.recv(69)
     self.assertEqual('test.foo.metric 1.000000 4' in sent_on_socket, True)
     self.assertEqual('test.foo.metric 2.000000 2' in sent_on_socket, True)
Example #31
0
 def test_create_graphitesend_instance(self):
     g = graphitesend.init()
     expected_type = type(graphitesend.GraphiteClient())
     g_type = type(g)
     self.assertEqual(g_type, expected_type)
Example #32
0
 def test_lowercase_metric_names(self):
     g = graphitesend.init(lowercase_metric_names=True)
     send_data = g.send('METRIC', 1)
     self.assertEqual('metric' in send_data, True)
     self.assertEqual('METRIC' in send_data, False)
Example #33
0
 def test_set_lowercase_metric_names(self):
     g = graphitesend.init(lowercase_metric_names=True)
     self.assertEqual(g.lowercase_metric_names, True)
Example #34
0
 def test_connect_exception_on_badhost(self):
     bad_graphite_server = 'missinggraphiteserver.example.com'
     graphitesend.default_graphite_server = bad_graphite_server
     with self.assertRaises(graphitesend.GraphiteSendException):
         graphitesend.init()
Example #35
0
 def test_prefix_double_dot(self):
     g = graphitesend.init(prefix='custom_prefix.')
     custom_prefix = g.prefix
     self.assertEqual(custom_prefix, 'custom_prefix.%s.' % self.hostname)
Example #36
0
 def test_empty_system_name(self):
     g = graphitesend.init(system_name='')
     custom_prefix = g.prefix
     expected_prefix = 'systems.'
     self.assertEqual(custom_prefix, expected_prefix)
Example #37
0
 def test_noprefix(self):
     g = graphitesend.init()
     custom_prefix = g.prefix
     self.assertEqual(custom_prefix, 'systems.%s.' % self.hostname)
Example #38
0
 def test_prefix_double_dot(self):
     g = graphitesend.init(prefix='custom_prefix.')
     custom_prefix = g.prefix
     self.assertEqual(custom_prefix, 'custom_prefix.%s.' % self.hostname)
Example #39
0
 def test_send_list_metric_value(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='local')
     response = graphite_instance.send_list([('metric', 1)])
     self.assertEqual('long message: test.local.metric 1' in response, True)
     self.assertEqual('1.00000' in response, True)
Example #40
0
 def test_dryrun(self):
     g = graphitesend.init(dryrun=True)
     dryrun_messsage_send = 'testing dryrun'
     dryrun_messsage_recv = g._dispatch_send(dryrun_messsage_send)
     self.assertEqual(dryrun_messsage_recv, dryrun_messsage_send)
Example #41
0
 def test_system_name(self):
     g = graphitesend.init(system_name='remote_host')
     custom_prefix = g.prefix
     expected_prefix = 'systems.remote_host.'
     self.assertEqual(custom_prefix, expected_prefix)
Example #42
0
 def test_empty_system_name(self):
     g = graphitesend.init(system_name='')
     custom_prefix = g.prefix
     expected_prefix = 'systems.'
     self.assertEqual(custom_prefix, expected_prefix)
Example #43
0
 def test_no_system_name(self):
     g = graphitesend.init(group='foo')
     custom_prefix = g.prefix
     expected_prefix = 'systems.%s.foo.' % self.hostname
     self.assertEqual(custom_prefix, expected_prefix)
Example #44
0
 def test_send_dict_str_to_int(self):
     graphitesend.init(system_name='')
     graphitesend.send_dict({'test_send_dict': '50'})
     (c, addr) = self.server.accept()
     sent_on_socket = c.recv(69)
     self.assertIn('test_send_dict 50.000000', sent_on_socket)
Example #45
0
 def test_monkey_patch_of_graphitehost(self):
     g = graphitesend.init()
     custom_prefix = g.addr[0]
     self.assertEqual(custom_prefix, 'localhost')
Example #46
0
 def test_fqdn_squash(self):
     g = graphitesend.init(fqdn_squash=True)
     custom_prefix = g.prefix
     expected_results = 'systems.%s.' % self.hostname.replace('.', '_')
     self.assertEqual(custom_prefix, expected_results)
Example #47
0
 def test_socket_timeout(self):
     with self.assertRaises(graphitesend.GraphiteSendException):
         graphitesend.init(timeout_in_seconds=.0000000000001)
Example #48
0
 def test_system_name(self):
     g = graphitesend.init(system_name='remote_host')
     custom_prefix = g.prefix
     expected_prefix = 'systems.remote_host.'
     self.assertEqual(custom_prefix, expected_prefix)
Example #49
0
 def test_send_prefix_empty(self):
     graphitesend.init(prefix='', system_name='')
     graphitesend.send('test_send', 50)
     (c, addr) = self.server.accept()
     sent_on_socket = c.recv(69)
     self.assertTrue(sent_on_socket.startswith('test_send 50.000000'))
Example #50
0
 def test_no_system_name(self):
     g = graphitesend.init(group='foo')
     custom_prefix = g.prefix
     expected_prefix = 'systems.%s.foo.' % self.hostname
     self.assertEqual(custom_prefix, expected_prefix)
Example #51
0
 def test_send_gaierror(self):
     g = graphitesend.init()
     g.socket = True
     with self.assertRaises(graphitesend.GraphiteSendException):
         g._dispatch_send('test')
Example #52
0
 def test_set_async_false(self):
     g = graphitesend.init(dryrun=True, asynchronous=False)
     self.assertEqual(g.asynchronous, False)
Example #53
0
 def test_init_bad_type(self):
     with self.assertRaises(graphitesend.GraphiteSendException):
         graphitesend.init(init_type="bad_type", dryrun=True)