实现loki 采集error日志,出现error 日志,告警。
1.修改Loki配置文件
在loki-local-config.yml中添加Alertmanager的配置,包括告警规则存储路径、Alertmanager的URL等。例如:
ruler:
enable_api: true
enable_alertmanager_v2: true
alertmanager_refresh_interval: 3m0s
alertmanager_url: http://xxxx:8893
storage:
type: local
local:
directory: /usr/local/monitlog/loki-rules
2.新建规则文件夹
/usr/local/monitlog/loki-rules/fake/loki_first_rules.yml
mkdir /usr/local/monitlog/loki-rules && mkdir /usr/local/monitlog/loki-rules/fake && cd /usr/local/monitlog/loki-rules/fake
vim loki_ck_rules.yml
点击查看代码
groups:
- name: error-logs-group
rules:
- alert: error-logs-alert
expr: count_over_time({filename="/tmp/app_log/my/bbc-gateway_error.log" } |="app_invoke_url_error" !=":255" [3m]) > 1
for: 3m
labels:
severity: error
env: prod
countryCode: my
annotations:
summary: "my最近3分钟logError异常{{ $labels }}"
description: "数量:{{ $value }}"