<commit_before>apiVersion: v1
kind: ConfigMap
metadata:
  name: kapacitor-alerts
  namespace: kube-system
data:
  high_cpu.tick: |
    stream
        |from()
            .measurement('cpu/node_utilization')
            .groupBy('nodename')
        |window()
            .period(5m)
            .every(5m)
        |mean('value').as('used')
        |alert()
            .message('{{ .Level}}: {{ .Name }}/{{ index .Tags "nodename" }} has high cpu usage: {{ index .Fields "used" }}%')
            .warn(lambda: "used" > 0.70)
            .crit(lambda: "used" > 0.80)
            .email()
  high_memory.tick: |
    stream
        |from()
            .measurement('memory/node_utilization')
            .groupBy('nodename')
        |window()
            .period(5m)
            .every(5m)
        |mean('value').as('used')
        |alert()
            .message('{{ .Level}}: {{ .Name }}/{{ index .Tags "nodename" }} has high memory usage: {{ index .Fields "used" }}%')
            .warn(lambda: "used" > 0.70)
            .crit(lambda: "used" > 0.80)
            .email()
<commit_msg>Add filesystem alerts<commit_after>apiVersion: v1
kind: ConfigMap
metadata:
  name: kapacitor-alerts
  namespace: kube-system
data:
  high_cpu.tick: |
    stream
        |from()
            .measurement('cpu/node_utilization')
            .groupBy('nodename')
        |window()
            .period(5m)
            .every(5m)
        |mean('value').as('used')
        |alert()
            .message('{{ .Level}}: {{ .Name }}/{{ index .Tags "nodename" }} has high cpu usage: {{ index .Fields "used" }}%')
            .warn(lambda: "used" > 0.70)
            .crit(lambda: "used" > 0.80)
            .email()
  high_memory.tick: |
    stream
        |from()
            .measurement('memory/node_utilization')
            .groupBy('nodename')
        |window()
            .period(5m)
            .every(5m)
        |mean('value').as('used')
        |alert()
            .message('{{ .Level}}: {{ .Name }}/{{ index .Tags "nodename" }} has high memory usage: {{ index .Fields "used" }}%')
            .warn(lambda: "used" > 0.70)
            .crit(lambda: "used" > 0.80)
            .email()
  filesystem.tick: |
    var period = 1m
    var every = 1m
    var warnRate = 80
    var warnReset = 70
    var critRate = 90
    var critReset = 80

    var usage = stream
        |from()
            .measurement('filesystem/usage')
            .groupBy('nodename', 'resource_id')
            .where(lambda: "type" == 'node')
        |window()
            .period(period)
            .every(every)

    var total = stream
        |from()
            .measurement('filesystem/limit')
            .groupBy('nodename', 'resource_id')
            .where(lambda: "type" == 'node')
        |window()
            .period(period)
            .every(every)

    var percent_used = usage
        |join(total)
            .as('usage', 'total')
            .tolerance(30s)
            .streamName('percent_used')
        |eval(lambda: (float("usage.value") * 100.0) / float("total.value"))
            .as('percent_used')

    var trigger = percent_used
        |alert()
            .message('{{ .Level}} / Node {{ index .Tags "nodename" }} has low free space on {{ index .Tags "resource_id" }}')
            .warn(lambda: "percent_used" > warnRate)
            .warnReset(lambda: "percent_used" < warnReset)
            .crit(lambda: "percent_used" > critRate)
            .critReset(lambda: "percent_used" < critReset)
            .stateChangesOnly()
            .details('''
    <b>{{ .Message }}</b>
    Level: {{ .Level }}
    Nodename: {{ index .Tags "nodename" }}
    Resource: {{ index .Tags "resource_id" }}
    Usage: {{ index .Fields "percent_used"  | printf "%0.2f" }}%
    ''')
            .email()

{'fraction_non_alphanumeric': 0.1674628450106157, 'fraction_numerical': 0.013800424628450107, 'mean_word_length': 1.751094890510949, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '315361', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1164, 'n_words': 252}