예제 #1
0
def test_spike_count():
    rules = {'threshold_ref': 10,
             'spike_height': 2,
             'timeframe': datetime.timedelta(seconds=10),
             'spike_type': 'both',
             'timestamp_field': '@timestamp'}
    rule = SpikeRule(rules)

    # Double rate of events at 20 seconds
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:00'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:10'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:20'): 20})
    assert len(rule.matches) == 1

    # Downward spike
    rule = SpikeRule(rules)
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:00'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:10'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:20'): 0})
    assert len(rule.matches) == 1
def test_spike_count():
    rules = {
        'threshold_ref': 10,
        'spike_height': 2,
        'timeframe': datetime.timedelta(seconds=10),
        'spike_type': 'both',
        'timestamp_field': '@timestamp'
    }
    rule = SpikeRule(rules)

    # Double rate of events at 20 seconds
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:00'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:10'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:20'): 20})
    assert len(rule.matches) == 1

    # Downward spike
    rule = SpikeRule(rules)
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:00'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:10'): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt('2014-09-26T00:00:20'): 0})
    assert len(rule.matches) == 1
예제 #3
0
def test_spike_count():
    rules = {
        "threshold_ref": 10,
        "spike_height": 2,
        "timeframe": datetime.timedelta(seconds=10),
        "spike_type": "both",
        "timestamp_field": "@timestamp",
    }
    rule = SpikeRule(rules)

    # Double rate of events at 20 seconds
    rule.add_count_data({ts_to_dt("2014-09-26T00:00:00"): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt("2014-09-26T00:00:10"): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt("2014-09-26T00:00:20"): 20})
    assert len(rule.matches) == 1

    # Downward spike
    rule = SpikeRule(rules)
    rule.add_count_data({ts_to_dt("2014-09-26T00:00:00"): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt("2014-09-26T00:00:10"): 10})
    assert len(rule.matches) == 0
    rule.add_count_data({ts_to_dt("2014-09-26T00:00:20"): 0})
    assert len(rule.matches) == 1