<commit_before>#!/usr/bin/python

import sys
import time
import requests
import json


def error(msg):
    sys.stderr.write(msg + '\n')
    sys.exit(1)


if len(sys.argv) < 4 or not all([x.isdigit() for x in sys.argv[2:]]):
    error(
        '{cmd} host port check_seconds expected_value'
        .format(cmd=sys.argv[0])
    )

request_parameters = {
    'url': 'http://{host}:{port}/render'.format(
        host=sys.argv[1],
        port=sys.argv[2],
    ),
    'params': {
        'from': '-{secs}sec'.format(secs=sys.argv[3]),
        'format': 'json',
        'maxDataPoints': sys.argv[3],
    },
    'data': {
        'target':
            'stats.docker-env.metrictank.metrictank-1.carbon.metrics_received',
    },
}

# wait while metrics are being generated
time.sleep(int(sys.argv[3]))

result = requests.post(**request_parameters)

if result.status_code != 200:
    error(
        'received bad response status code: {code}'
        .format(code=result.status_code)
    )

try:
    parsed_result = json.loads(result.text)
except Exception:
    error(<commit_msg>fix hostname -> instance-id<commit_after>#!/usr/bin/python

import sys
import time
import requests
import json


def error(msg):
    sys.stderr.write(msg + '\n')
    sys.exit(1)


if len(sys.argv) < 4 or not all([x.isdigit() for x in sys.argv[2:]]):
    error(
        '{cmd} host port check_seconds expected_value'
        .format(cmd=sys.argv[0])
    )

request_parameters = {
    'url': 'http://{host}:{port}/render'.format(
        host=sys.argv[1],
        port=sys.argv[2],
    ),
    'params': {
        'from': '-{secs}sec'.format(secs=sys.argv[3]),
        'format': 'json',
        'maxDataPoints': sys.argv[3],
    },
    'data': {
        'target':
            'stats.docker-env.metrictank.default.carbon.metrics_received',
    },
}

# wait while metrics are being generated
time.sleep(int(sys.argv[3]))

result = requests.post(**request_parameters)

if result.status_code != 200:
    error(
        'received bad response status code: {code}'
        .format(code=result.status_code)
    )

try:
    parsed_result = json.loads(result.text)
except Exception:
    error(
{'fraction_non_alphanumeric': 0.1634928007431491, 'fraction_numerical': 0.011611704598235021, 'mean_word_length': 2.7855887521968365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '6868628', 'n_tokens_mistral': 761, 'n_tokens_neox': 743, 'n_words': 145}