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

import requests
import sys

OVERVIEW_URL = "http://localhost:55672/api/overview"
NODES_URL = "http://localhost:55672/api/nodes"
USERNAME = 'guest'
PASSWORD = '<PASSWORD>'

OVERVIEW_METRICS = {"queue_totals": ("messages",
                                     "messages_ready",
                                     "messages_unacknowledged"),
                    "message_stats": ("get",
                                      "ack",
                                      "deliver_get",
                                      "deliver",
                                      "publish")}
NODES_METRICS = ("proc_used",
                 "proc_total",
                 "fd_used",
                 "fd_total",
                 "sockets_used",
                 "sockets_total",
                 "mem_used",
                 "mem_limit",
                 "mem_alarm")


def main():
    metrics = {}

    try:
        r = requests.get(OVERVIEW_URL, auth=(USERNAME, PASSWORD))
    except requests.exceptions.ConnectionError:
        error()

    if r.status_code == 200:
        for k in OVERVIEW_METRICS.keys():
            if k in r.json():
                for i in OVERVIEW_METRICS[k]:
                    if i in r.json()[k]:
                        metrics[i] = r.json()[k][i]
    else:
        error()

    try:
        r = requests.get(NODES_URL, auth=(USERNAME, PASSWORD))
    except requests.exceptions.ConnectionError:
        error()

    if r.status_code == 200:
        for i in NODES_METRICS:
            if i in r.json()[0]:
                metrics[i] = r.json()[0][i]
    else:
        error()

    print "status ok"

    for k in metrics.keys():
        print "metric %s int64 %d" % (k, metrics[k])


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


if __name__ == "__main__":
    main()<commit_msg>adding cluster size check for alarming purposes<commit_after>#!/usr/bin/env python

import requests
import sys

OVERVIEW_URL = "http://localhost:15672/api/overview"
NODES_URL = "http://localhost:15672/api/nodes"
USERNAME = 'guest'
PASSWORD = '<PASSWORD>'
CLUSTERED = True
CLUSTER_SIZE = 3

OVERVIEW_METRICS = {"queue_totals": ("messages",
                                     "messages_ready",
                                     "messages_unacknowledged"),
                    "message_stats": ("get",
                                      "ack",
                                      "deliver_get",
                                      "deliver",
                                      "publish")}
NODES_METRICS = ("proc_used",
                 "proc_total",
                 "fd_used",
                 "fd_total",
                 "sockets_used",
                 "sockets_total",
                 "mem_used",
                 "mem_limit",
                 "mem_alarm",
                 "disk_free_alarm",
                 "uptime")


def main():
    metrics = {}

    try:
        r = requests.get(OVERVIEW_URL, auth=(USERNAME, PASSWORD))
    except requests.exceptions.ConnectionError:
        error()

    if r.status_code == 200:
        for k in OVERVIEW_METRICS.keys():
            if k in r.json():
                for i in OVERVIEW_METRICS[k]:
                    if i in r.json()[k]:
                        metrics[i] = r.json()[k][i]
    else:
        error()

    try:
        r = requests.get(NODES_URL, auth=(USERNAME, PASSWORD))
    except requests.exceptions.ConnectionError:
        error()

    if r.status_code == 200:
        for i in NODES_METRICS:
            if i in r.json()[0]:
                metrics[i] = r.json()[0][i]
    else:
        error()

    if CLUSTERED and len(r.json()) < CLUSTER_SIZE:
      print "status err cluster too small"
    else:
      print "status ok"

    for k in metrics.keys():
        print "metric %s int64 %d" % (k, metrics[k])


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


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.11848461734045258, 'fraction_numerical': 0.010933129926264938, 'mean_word_length': 1.3914893617021276, 'pattern_counts': {'":': 6, '<': 6, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581670', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1140, 'n_words': 255}