def test_custom_formatter_used(self, mock_sysout):
     mock_results = [{
         'Timestamp': datetime.datetime.utcnow(),
         'Unit': 'Count',
         'Sum': 1337.0,
     }]
     metric = {
         'Namespace': 'AWS/Foo',
         'MetricName': 'RequestCount',
         'Statistics': 'Sum',
         'Unit': 'Count',
         'Dimensions': {
             'Krang': 'X'
         },
         'Options': {
             'Formatter': 'tmnt.%(dimension)s'
         }
     }
     options = leadbutt.get_options(None, metric.get('Options'), None)
     leadbutt.output_results(mock_results, metric, options)
     self.assertTrue(mock_sysout.write.called)
     out = mock_sysout.write.call_args[0][0]
     name, value, timestamp = out.split()
     # assert custom formatter was used
     self.assertEqual(name, 'tmnt.x')
     self.assertEqual(value, '1337.0')
Exemplo n.º 2
0
    def test_multiple_statistics_get_multiple_lines(self, mock_sysout):
        mock_results = [{
            'Timestamp': datetime.datetime.utcnow(),
            'Maximum': 9001.0,
            'Average': 1337.0,
        }]
        metric = {
            'Namespace': 'AWS/Foo',
            'MetricName': 'RequestCount',
            'Statistics': ['Maximum', 'Average'],
            'Unit': 'Count',
            'Dimensions': {'Krang': 'X'},
        }
        options = leadbutt.get_options(None, metric.get('Options'), None)
        leadbutt.output_results(mock_results, metric, options)

        self.assertEqual(
            mock_sysout.write.call_count, len(metric['Statistics']))
 def test_default_formatter_used(self, mock_sysout):
     mock_results = [{
         'Timestamp': datetime.datetime.utcnow(),
         'Sum': 1337.0,
     }]
     metric = {
         'Namespace': 'AWS/Foo',
         'MetricName': 'RequestCount',
         'Statistics': 'Sum',
         'Unit': 'Count',
         'Dimensions': {'Krang': 'X'},
     }
     options = leadbutt.get_options(None, metric.get('Options'), None)
     leadbutt.output_results(mock_results, metric, options)
     self.assertTrue(mock_sysout.write.called)
     out = mock_sysout.write.call_args[0][0]
     name, value, timestamp = out.split()
     # assert default formatter was used
     self.assertEqual(name, 'cloudwatch.aws.foo.x.requestcount.sum.count')
     self.assertEqual(value, '1337.0')