Пример #1
0
def test_detector_with_assign_combinator():
    """ We should correctly generate a detector comprised of two assignment
        functions
    """
    cpu_util_string = 'cpu.utilization'
    sum_string = 'utilization_sum'
    count_string = 'utilization_count'
    mean_string = 'utilization_mean'

    sum_data = Data(cpu_util_string).sum()
    count_data = Data(cpu_util_string).count()

    utilization_sum = Assign(sum_string, sum_data)
    utilization_count = Assign(count_string, count_data)

    mean_data = Div(Ref(sum_string), Ref(count_string))

    utilization_mean = Assign(mean_string, mean_data)

    detect = Detect(When(GT(Ref(mean_string), 50))).publish(label='detector')

    program = Program(utilization_sum, utilization_count, utilization_mean,
                      detect)

    detector = Detector().with_program(program)

    assert detector.options["programText"] == "{0}\n{1}\n{2}\n{3}".format(
        str(utilization_sum), str(utilization_count), str(utilization_mean),
        str(detect))

    assert program.statements.pop() == detect
    assert program.statements.pop() == utilization_mean
    assert program.statements.pop() == utilization_count
    assert program.statements.pop() == utilization_sum
Пример #2
0
    def fun(name, threshold):
        program = Program(
            Detect(GT(Data("cpu.utilization"), threshold)).publish(label=name))

        rule = (Rule().for_label(name).with_severity(
            Severity.Info).with_notifications(
                EmailNotification("*****@*****.**")))

        return (Detector(session=session).with_name(name).with_program(
            program).with_rules(rule))
Пример #3
0
 def bad_helper(p):
     p.add_statements(Data("I shouldn't exist").publish(label='Y'))
     return Program(Detect(LT(p.find_label('Z'), 10)).publish(label='foo'))
Пример #4
0
 def helper(p):
     return Program(Detect(LT(p.find_label('Z'), 10)).publish(label='foo'))
def detector_helper(prog):
    d = prog.find_label('A')
    return Program(Detect(LT(d, 1)).publish(alert_label))
from signal_analog.detectors import Detector, Rule, EmailNotification, Severity
from signal_analog.flow import Data, Detect, Filter, Program
from signal_analog.combinators import And, LT

"""
Example 1: from scratch

This is useful when you want to monitor something that isn't tied to an
existing chart or dashboard.
"""

alert_label = 'CPU is too low for 75% of the last 2 minutes!'

filters = And(Filter('app', 'my-app'), Filter('env', 'test'))
data = Data('cpu.utilization', filter=filters).publish(label='A')
cpu_too_low = Detect(When(LT(data, 50), '2m', 0.75)).publish(alert_label)
program = Program(cpu_too_low)

info_rule = Rule()\
    .for_label(alert_label)\
    .with_severity(Severity.Info)\
    .with_notifications(EmailNotification('*****@*****.**'))

detector = Detector()\
    .with_name('TEST: example detector')\
    .with_program(program)\
    .with_rules(info_rule)

"""
Example 2: from an existing chart
Пример #7
0
 def program(threshold):
     return Program(
         Detect(GT(Data('cpu.utilization'),
                   threshold)).publish(label=label))