# Path: collectors/lib/utils.py
# PY3 = sys.version_info[0] > 2
# USER = "nobody"
# def drop_privileges(user=USER):
# def is_sockfile(path):
# def err(msg):
#     def is_numeric(value):
#     def is_numeric(value):
# 
# Path: collectors/etc/aws_cloudwatch_conf.py
# def enabled():
# def get_validate_env_var(var, default):
# def get_accesskey_secretkey():
# def get_aws_profile():


import os
import sys
import time
import datetime
import re
import json
import threading
    import boto3
from collections import OrderedDict
from time import mktime
from collectors.lib import utils
from collectors.etc import aws_cloudwatch_conf
    from botocore.exceptions import ClientError
    from queue import Queue
    from Queue import Queue

def cloudwatch_list_metrics(cloudwatch):
    try:
        metrics = []
        # List metrics through the pagination interface
        paginator = cloudwatch.get_paginator('list_metrics')
        for response in paginator.paginate():
            metrics.append(response['Metrics'])
        return metrics[0]
    except ClientError as exc:
        if exc.response['Error']['Code'] == 'InvalidClientTokenId':
            utils.err('Invalid token while retrieving metrics')
            sys.exit(1)
        else:
            utils.err('Client Error while retrieving metric list: [%s] %s' % (
                exc.response['Error']['Code'], exc.response['Error']['Message']))
            return []
    except:
        print("Unexpected error: %s %s %s" % (sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
        return []


def cloudwatch_query_metric(cloudwatch, region, metric):
    end = datetime.datetime.utcnow()
    start = end - datetime.timedelta(seconds=COLLECTION_INTERVAL)
    global STATISTICS
    # TODO: statistics no longer need to be one at at time so refactor that
    response = cloudwatch.get_metric_statistics(
        Namespace=metric["Namespace"],
        MetricName=metric["MetricName"],

# Path: collectors/lib/utils.py
# PY3 = sys.version_info[0] > 2
# USER = "nobody"
# def drop_privileges(user=USER):
# def is_sockfile(path):
# def err(msg):
#     def is_numeric(value):
#     def is_numeric(value):
# 
# Path: collectors/etc/aws_cloudwatch_conf.py
# def enabled():
# def get_validate_env_var(var, default):
# def get_accesskey_secretkey():
# def get_aws_profile():


# Path: collectors/300/aws_cloudwatch_stats.py
import os
import sys
import time
import datetime
import re
import json
import threading
    import boto3
from collections import OrderedDict
from time import mktime
from collectors.lib import utils
from collectors.etc import aws_cloudwatch_conf
    from botocore.exceptions import ClientError
    from queue import Queue
    from Queue import Queue


def cloudwatch_list_metrics(cloudwatch):
    try:
        metrics = []
        # List metrics through the pagination interface
        paginator = cloudwatch.get_paginator('list_metrics')
        for response in paginator.paginate():
            metrics.append(response['Metrics'])
        return metrics[0]
    except ClientError as exc:
        if exc.response['Error']['Code'] == 'InvalidClientTokenId':
            utils.err('Invalid token while retrieving metrics')
            sys.exit(1)
        else:
            utils.err('Client Error while retrieving metric list: [%s] %s' % (
                exc.response['Error']['Code'], exc.response['Error']['Message']))
            return []
    except:
        print("Unexpected error: %s %s %s" % (sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
        return []


def cloudwatch_query_metric(cloudwatch, region, metric):
    end = datetime.datetime.utcnow()
    start = end - datetime.timedelta(seconds=COLLECTION_INTERVAL)
    global STATISTICS
    # TODO: statistics no longer need to be one at at time so refactor that
    response = cloudwatch.get_metric_statistics(
        Namespace=metric["Namespace"],
        MetricName=metric["MetricName"],

        Dimensions=metric["Dimensions"],