<commit_before>#!/usr/bin/env python

import json
import socket
import sys
import time
import urllib
import urlparse

from check_exhibitor import fetch_status

def get_stat(host, hostname):
    path = '/exhibitor/v1/cluster/4ltr/mntr/' + hostname

    stat_url = urlparse.urljoin(host, path)
    f = urllib.urlopen(stat_url)

    if f.getcode() != 200:
        raise Exception("Non 200 response from exhibitor")

    return json.loads(f.read())['response']


def do(host):
    hosts = [h['hostname'] for h in fetch_status(host)]
    for hostname in hosts:
        yield hostname, parse_response(get_stat(host, hostname))


def parse_response(response):
    return response.decode('string-escape').strip("\n\"").split("\n")

if __name__ == '__main__':
    root_host = sys.argv[1]
    socket.setdefaulttimeout(1)
    for host, resp in do(root_host):
        # kv takes the form {key}\t{value}
        for kv in resp:
            print "exhibitor.%s.%s\t%d" % (host.replace('.', '-'), kv, time.time())
<commit_msg>key prefix.<commit_after>#!/usr/bin/env python

import json
import socket
import sys
import time
import urllib
import urlparse

from check_exhibitor import fetch_status

def get_stat(host, hostname):
    path = '/exhibitor/v1/cluster/4ltr/mntr/' + hostname

    stat_url = urlparse.urljoin(host, path)
    f = urllib.urlopen(stat_url)

    if f.getcode() != 200:
        raise Exception("Non 200 response from exhibitor")

    return json.loads(f.read())['response']


def do(host):
    hosts = [h['hostname'] for h in fetch_status(host)]
    for hostname in hosts:
        yield hostname, parse_response(get_stat(host, hostname))


def parse_response(response):
    return response.decode('string-escape').strip("\n\"").split("\n")

if __name__ == '__main__':
    path_prefix = sys.argv[1].rstrip('.')
    root_host = sys.argv[2]
    socket.setdefaulttimeout(1)
    for host, resp in do(root_host):
        # kv takes the form {key}\t{value}
        for kv in resp:
            print "%s.exhibitor.%s.%s\t%d" % (
                path_prefix, host.replace('.', '-'), kv, time.time())

{'fraction_non_alphanumeric': 0.1422434367541766, 'fraction_numerical': 0.010023866348448688, 'mean_word_length': 3.330578512396694, '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': '1192219', 'n_tokens_mistral': 727, 'n_tokens_neox': 700, 'n_words': 174}