예제 #1
0
class TestCloudWatch(unittest.TestCase):

    def setUp(self):

        self.metric = MetricObject("ERROR", 1, None)
        self.metric.timestamp = strftime("%Y%m%dT%H:%M:00Z", gmtime(self.metric.timestamp))

        self.cw = CloudWatch("key", "secretkey", self.metric)
        self.cw.get_instance_id("myserverID").set_params().get_signed_url()

    def test_params(self):

        self.assertEqual(self.cw.base_url, "monitoring.ap-northeast-1.amazonaws.com")
        self.assertEqual(self.cw.key, "key")
        self.assertEqual(self.cw.secret_key, "secretkey")
        self.assertEqual(self.cw.url_params['Namespace'], "logster")
        self.assertEqual(self.cw.url_params['MetricData.member.1.MetricName'], "ERROR")
        self.assertEqual(self.cw.url_params['MetricData.member.1.Value'], 1)
        self.assertEqual(self.cw.url_params['MetricData.member.1.Unit'], None)
        self.assertEqual(self.cw.url_params['MetricData.member.1.Dimensions.member.1.Name'], "InstanceID")
        self.assertEqual(self.cw.url_params['MetricData.member.1.Dimensions.member.1.Value'], "myserverID")
        self.assertEqual(self.cw.url_params['AWSAccessKeyId'], "key")
        self.assertEqual(self.cw.url_params['Timestamp'], self.metric.timestamp)
        self.assertEqual(self.cw.url_params['Action'], 'PutMetricData')
        self.assertEqual(self.cw.url_params['SignatureMethod'], 'HmacSHA256')
        self.assertEqual(self.cw.url_params['SignatureVersion'], '2')
        self.assertEqual(self.cw.url_params['Version'], '2010-08-01')
예제 #2
0
class TestCloudWatch(unittest.TestCase):
    def setUp(self):

        self.metric = MetricObject("ERROR", 1, None)
        self.metric.timestamp = strftime("%Y%m%dT%H:%M:00Z",
                                         gmtime(self.metric.timestamp))

        self.cw = CloudWatch("key", "secretkey", self.metric)
        self.cw.get_instance_id("myserverID").set_params().get_signed_url()

    def test_params(self):

        self.assertEqual(self.cw.base_url,
                         "monitoring.ap-northeast-1.amazonaws.com")
        self.assertEqual(self.cw.key, "key")
        self.assertEqual(self.cw.secret_key, "secretkey")
        self.assertEqual(self.cw.url_params['Namespace'], "logster")
        self.assertEqual(self.cw.url_params['MetricData.member.1.MetricName'],
                         "ERROR")
        self.assertEqual(self.cw.url_params['MetricData.member.1.Value'], 1)
        self.assertEqual(self.cw.url_params['MetricData.member.1.Unit'], None)
        self.assertEqual(
            self.cw.url_params['MetricData.member.1.Dimensions.member.1.Name'],
            "InstanceID")
        self.assertEqual(
            self.cw.
            url_params['MetricData.member.1.Dimensions.member.1.Value'],
            "myserverID")
        self.assertEqual(self.cw.url_params['AWSAccessKeyId'], "key")
        self.assertEqual(self.cw.url_params['Timestamp'],
                         self.metric.timestamp)
        self.assertEqual(self.cw.url_params['Action'], 'PutMetricData')
        self.assertEqual(self.cw.url_params['SignatureMethod'], 'HmacSHA256')
        self.assertEqual(self.cw.url_params['SignatureVersion'], '2')
        self.assertEqual(self.cw.url_params['Version'], '2010-08-01')
예제 #3
0
def submit_cloudwatch(metrics, options):
    for metric in metrics:

        if options.metric_prefix != "":
            metric.name = options.metric_prefix + "." + metric.name
        if options.metric_suffix is not None:
            metric.name = metric.name + "." + options.metric_suffix

        metric.timestamp = time.strftime("%Y%m%dT%H:%M:00Z", time.gmtime(metric.timestamp))
        metric.units = "None"
        metric_string = "%s %s %s" % (metric.name, metric.value, metric.timestamp)
        logger.debug("Submitting CloudWatch metric: %s" % metric_string)

        if not options.dry_run:
            try:
                cw = CloudWatch(options.aws_key, options.aws_secret_key, metric).get_instance_id()
            except CloudWatchException:
                logger.debug("Is this machine really amazon EC2?")
                sys.exit(1)

            try:
                cw.put_data()
            except CloudWatchException, e:
                logger.debug(e.message)
                sys.exit(1)
        else:
            print metric_string
예제 #4
0
    def setUp(self):

        self.metric = MetricObject("ERROR", 1, None)
        self.metric.timestamp = strftime("%Y%m%dT%H:%M:00Z",
                                         gmtime(self.metric.timestamp))

        self.cw = CloudWatch("key", "secretkey", self.metric)
        self.cw.get_instance_id("myserverID").set_params().get_signed_url()
예제 #5
0
    def setUp(self):

        self.metric = MetricObject("ERROR", 1, None)
        self.metric.timestamp = strftime("%Y%m%dT%H:%M:00Z", gmtime(self.metric.timestamp))

        self.cw = CloudWatch("key", "secretkey", self.metric)
        self.cw.get_instance_id("myserverID").set_params().get_signed_url()