<commit_before>import logging
import time
import os

from string import maketrans
from awslimitchecker.checker import AwsLimitChecker
from prometheus_client import start_http_server, Summary, Gauge


REQUEST_TIME = Summary(
                        'update_processing_seconds',
                        'Time spent querying aws for limits'
                    )
gauges = {}
trantab = maketrans(' -.', '___')


def main():
    port = int(os.environ.get('ALC_PORT', '8080'))
    interval = int(os.environ.get('ALC_INTERVAL', '60'))
    logger = logging.getLogger()
    logger.setLevel(logging.ERROR)

    checkers = {}
    for region in ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']:
        checkers[region] = AwsLimitChecker(region=region)

    start_http_server(port)
    for region, checker in checkers.iteritems():
        update(checker, region)
        time.sleep(interval)


@REQUEST_TIME.time()
def update(checker, region):
    try:
        checker.find_usage()

        labels = {'region': region}
        for service, svc_limits in sorted(checker.get_limits().items()):
            for limit_name, limit in sorted(svc_limits.items()):
                path = '.'.join([service, limit_name])
                usage = limit.get_current_usage()
                metric = limit.get_limit()
                update_service(path, usage, metric, region)
    except Exception as e:
        logging.exception("message")


def update_service(path, usage, limit, region):
    g = gauge(path)<commit_msg>make docs/examples/prometheus.py work with python 3.8 as currently used in awslimitchecker docker image<commit_after>import logging
import time
import os

from awslimitchecker.checker import AwsLimitChecker
from prometheus_client import start_http_server, Summary, Gauge


REQUEST_TIME = Summary(
                        'update_processing_seconds',
                        'Time spent querying aws for limits'
                    )
gauges = {}
trantab = str.maketrans(' -.', '___')


def main():
    port = int(os.environ.get('ALC_PORT', '8080'))
    interval = int(os.environ.get('ALC_INTERVAL', '60'))
    logger = logging.getLogger()
    logger.setLevel(logging.ERROR)

    checkers = {}
    for region in ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']:
        checkers[region] = AwsLimitChecker(region=region)

    start_http_server(port)
    for region, checker in checkers.items():
        update(checker, region)
        time.sleep(interval)


@REQUEST_TIME.time()
def update(checker, region):
    try:
        checker.find_usage()

        labels = {'region': region}
        for service, svc_limits in sorted(checker.get_limits().items()):
            for limit_name, limit in sorted(svc_limits.items()):
                path = '.'.join([service, limit_name])
                usage = limit.get_current_usage()
                metric = limit.get_limit()
                update_service(path, usage, metric, region)
    except Exception as e:
        logging.exception("message")


def update_service(path, usage, limit, region):
    g = gauge(path)
{'fraction_non_alphanumeric': 0.11843393148450244, 'fraction_numerical': 0.007177814029363785, 'mean_word_length': 2.7028985507246377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4303294', 'n_tokens_mistral': 948, 'n_tokens_neox': 910, 'n_words': 215}