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

import memcache
import sys

MEMCACHE_KEYS = ("get_hits",
                 "get_misses")


def main():
    metrics = {}
    mc = memcache.Client(['localhost:11211'], debug=0)

    if len(mc.get_stats()) == 0:
        error()

    stats = mc.get_stats()[0][1]

    for k in MEMCACHE_KEYS:
        if k in stats:
            metrics[k] = stats[k]

    if len(metrics.keys()) > 0:
        print "status ok"
        for k in metrics.keys():
            print "metric %s int64 %s" % (k, metrics[k])
    else:
        error()


def error():
    print "status error"
    sys.exit(1)


if __name__ == "__main__":
    main()<commit_msg>Leverage maas_common in memcache_stats.py<commit_after>#!/usr/bin/env python

import memcache

from maas_common import status_ok, status_err, metric

MEMCACHE_KEYS = ("get_hits",
                 "get_misses")


def main():
    metrics = {}
    mc = memcache.Client(['localhost:11211'], debug=0)

    if len(mc.get_stats()) == 0:
        status_err()

    stats = mc.get_stats()[0][1]

    for k in MEMCACHE_KEYS:
        if k in stats:
            metrics[k] = stats[k]

    if len(metrics.keys()) > 0:
        status_ok()
        for k, v in metrics.items():
            metric(k, 'int64', v)
    else:
        status_err()


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.14296463506395787, 'fraction_numerical': 0.018811136192626036, 'mean_word_length': 2.251833740831296, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '2801135', 'n_tokens_mistral': 492, 'n_tokens_neox': 460, 'n_words': 115}