コード例 #1
0
import sys

from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from detector import SpikeDetector

DESCRIPTION = "Generates CSV report with spikes found on Graphite hosts"

# Sleep value bethween requests to same host
DEFAULT_SLEEP_VAL = 1
# Limit of requests per host
DEFAULT_HOST_LIMIT = 500
# Output file
DEFAULT_OUTPUT_FILE = None

# Detector class
DETECTOR = SpikeDetector()


def get_host_targets(host_string, pattern):
    """Returns targets that match pattern from a graphite host"""

    targets = []
    try:
        response = requests.get('http://%s/metrics/index.json' % host_string)

        targets = json.loads(response.text)

        targets = [t for t in targets if fnmatch.fnmatch(t, pattern)]
    except Exception as e:
        print 'Exception occured while getting host target: %s' % e
    finally: