当前位置: 首页 > news >正文

windows单节点验证victoriametrics结合AlertManger实现告警推送webhook

安装victoriametrics

https://docs.victoriametrics.com/single-server-victoriametrics/

下载地址

https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.113.0

找到​​victoria-metrics-windows-amd64-v1.113.0.zip​​

https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.113.0/victoria-metrics-windows-amd64-v1.113.0.zip

解压并在cmd里启动

victoria-metrics-windows-amd64-prod.exe

启动结果

......
2025-03-21T07:17:44.495Z        info    VictoriaMetrics/app/vmselect/promql/rollup_result_cache.go:156  loaded rollupResult cache from "victoria-metrics-data/cache/rollupResult" in 0.010 seconds; entriesCount: 0, sizeBytes: 0
2025-03-21T07:17:44.495Z        info    VictoriaMetrics/app/vmselect/prometheus/prometheus.go:1297      limiting -search.maxUniqueTimeseries to 8547304 according to -search.maxConcurrentRequests=16 and remaining memory=27351374234 bytes. To increase the limit, reduce -search.maxConcurrentRequests or increase memory available to the process.
2025-03-21T07:17:44.496Z        info    VictoriaMetrics/app/victoria-metrics/main.go:105        started VictoriaMetrics in 0.203 seconds
2025-03-21T07:17:44.500Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:169        started server at http://0.0.0.0:8428/
2025-03-21T07:17:44.502Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:171        pprof handlers are exposed at http://0.0.0.0:8428/debug/pprof/

访问​​

http://127.0.0.1:8428​​

安装vmutils-windows

vmutils-windows包里包含众多VictoriaMetrics组件

https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.113.0/vmutils-windows-amd64-v1.113.0.zip

解压​​vmutils-windows-amd64-v1.113.0.zip​​

启动vmagent

https://docs.victoriametrics.com/vmagent/

启动命令

vmagent-windows-amd64-prod.exe -promscrape.config=prometheus.yml -remoteWrite.url=http://127.0.0.1:8428/api/v1/write

安装victoriametrics

https://docs.victoriametrics.com/single-server-victoriametrics/

下载地址

https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.113.0

找到​​victoria-metrics-windows-amd64-v1.113.0.zip​​

https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.113.0/victoria-metrics-windows-amd64-v1.113.0.zip

解压并在cmd里启动

victoria-metrics-windows-amd64-prod.exe

启动结果

......
2025-03-21T07:17:44.495Z        info    VictoriaMetrics/app/vmselect/promql/rollup_result_cache.go:156  loaded rollupResult cache from "victoria-metrics-data/cache/rollupResult" in 0.010 seconds; entriesCount: 0, sizeBytes: 0
2025-03-21T07:17:44.495Z        info    VictoriaMetrics/app/vmselect/prometheus/prometheus.go:1297      limiting -search.maxUniqueTimeseries to 8547304 according to -search.maxConcurrentRequests=16 and remaining memory=27351374234 bytes. To increase the limit, reduce -search.maxConcurrentRequests or increase memory available to the process.
2025-03-21T07:17:44.496Z        info    VictoriaMetrics/app/victoria-metrics/main.go:105        started VictoriaMetrics in 0.203 seconds
2025-03-21T07:17:44.500Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:169        started server at http://0.0.0.0:8428/
2025-03-21T07:17:44.502Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:171        pprof handlers are exposed at http://0.0.0.0:8428/debug/pprof/

访问​​

http://127.0.0.1:8428​​

安装vmutils-windows

vmutils-windows包里包含众多VictoriaMetrics组件

https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.113.0/vmutils-windows-amd64-v1.113.0.zip

解压​​vmutils-windows-amd64-v1.113.0.zip​​

启动vmagent

https://docs.victoriametrics.com/vmagent/

启动命令

vmagent-windows-amd64-prod.exe -promscrape.config=prometheus.yml -remoteWrite.url=http://127.0.0.1:8428/api/v1/write

其中​​prometheus.yml​​​为prometheus配置文件;​​http://127.0.0.1:8428/api/v1/write​​为victoriametrics服务地址

prometheus.yml配置文件内容如下

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "victoriametrics"
    static_configs:
      - targets: ["127.0.0.1:8429"]
  - job_name: "zookeeper"
    static_configs:
      - targets: ["127.0.0.1:7000"]
  - job_name: "mysql"
    static_configs:
      - targets: ["127.0.0.1:9104"]
  - job_name: "windows"
    static_configs:
      - targets: ["127.0.0.1:9182"]

启动日志如下

2025-03-21T07:32:48.747Z        info    VictoriaMetrics/app/vmagent/main.go:169 started vmagent in 0.380 seconds
2025-03-21T07:32:48.747Z        info    VictoriaMetrics/lib/promscrape/scraper.go:118   reading scrape configs from "prometheus.yml"
2025-03-21T07:32:48.748Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:169        started server at http://0.0.0.0:8429/
2025-03-21T07:32:48.749Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:171        pprof handlers are exposed at http://0.0.0.0:8429/debug/pprof/
2025-03-21T07:32:48.753Z        info    VictoriaMetrics/lib/promscrape/config.go:149    starting service discovery routines...
2025-03-21T07:32:48.754Z        info    VictoriaMetrics/lib/promscrape/config.go:155    started 5 service discovery routines in 0.001 seconds
2025-03-21T07:32:48.754Z        info    VictoriaMetrics/lib/promscrape/scraper.go:439   static_configs: added targets: 5, removed targets: 0; total targets: 5

启动vmalert

https://docs.victoriametrics.com/vmalert/

启动命令

vmalert-windows-amd64-prod.exe -rule=rule-first.yml -datasource.url=http://127.0.0.1:8428 -notifier.url=http://127.0.0.1:9093 -notifier.url=http://127.0.0.1:9093 -remoteWrite.url=http://127.0.0.1:8428 -remoteRead.url=http://127.0.0.1:8428 -external.label=cluster=east-1 -external.label=replica=a

其中rule-first.yml为规则文件;​​http://127.0.0.1:8428​​​为victoriametrics服务地址;​​http://127.0.0.1:9093​​为AlertManger地址。

rule-first.yml规则配置文件内容如下

groups:
  - name: InstanceDown_Rule
    rules:
      - alert: InstanceDown  # 告警名称
        expr: up == 0        # 告警条件
        for: 30s              # 告警触发前需要持续满足条件的时间
        labels:
          severity: critical # 告警的严重程度
          instance: "{{$labels.instance}}"
        annotations:
          summary: "Instance {{ $labels.instance }} down"
          description: "Instance {{ $labels.instance }} has been down for more than 30 seconds."

启动日志如下

......
2025-03-21T07:39:41.952Z        info    VictoriaMetrics/app/vmalert/config/log/logger.go:52     found 1 files to read from "Local FS{MatchPattern: \"rule-first.yml\"}"
2025-03-21T07:39:41.955Z        info    VictoriaMetrics/app/vmalert/config/log/logger.go:52     finished reading 1 files in 889.8µs from "Local FS{MatchPattern: \"rule-first.yml\"}"
2025-03-21T07:39:41.956Z        info    VictoriaMetrics/app/vmalert/rule/group.go:497   group "InstanceDown_Rule" will start in 8.357938405s; interval=1m0s; eval_offset=<nil>; concurrency=1
2025-03-21T07:39:41.959Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:169        started server at http://0.0.0.0:8880/
2025-03-21T07:39:41.960Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:171        pprof handlers are exposed at http://0.0.0.0:8880/debug/pprof/

访问地址

http://127.0.0.1:8880/

部署AlertManger

下载AlertManger

https://github.com/prometheus/alertmanager/releases

下载地址

https://github.com/prometheus/alertmanager/releases/download/v0.28.1/alertmanager-0.28.1.windows-amd64.zip

解压并启动,启动命令如下

alertmanager.exe --config.file=alertmanager.yml --log.level=debug

其中alertmanager.yml为alertmanager的配置文件,配置文件内容如下:

route:
#  group_by: ['alertname', 'instance', 'job']
  group_by: [...]
  group_wait: 10s
  group_interval: 20s
  repeat_interval: 30s
  receiver: 'web.hook'
receivers:
  - name: 'web.hook'
    webhook_configs:
      - url: 'http://127.0.0.1:5001/user/alert'
        send_resolved: true
#inhibit_rules:
#  - source_match:
#      severity: 'critical'
#    target_match:
#      severity: 'warning'
#    equal: ['alertname', 'instance', 'job']
global:
  resolve_timeout: 5m​​

http://127.0.0.1:5001/user/alert​​配置推送到应用服务的服务端点

启动日志如下

......
ts=2025-03-21T07:49:26.950Z caller=main.go:348 level=debug externalURL=http://P7507787A244:9093
ts=2025-03-21T07:49:26.951Z caller=coordinator.go:113 level=info component=configuration msg="Loading configuration file" file=alertmanager.yml
ts=2025-03-21T07:49:26.954Z caller=coordinator.go:126 level=info component=configuration msg="Completed loading of configuration file" file=alertmanager.yml
ts=2025-03-21T07:49:26.958Z caller=main.go:495 level=debug routePrefix=/
ts=2025-03-21T07:49:26.960Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:9093
ts=2025-03-21T07:49:26.962Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:9093

访问地址

http://127.0.0.1:9093

其中​​prometheus.yml​​​为prometheus配置文件;​​http://127.0.0.1:8428/api/v1/write​​为victoriametrics服务地址

prometheus.yml配置文件内容如下

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "victoriametrics"
    static_configs:
      - targets: ["127.0.0.1:8429"]
  - job_name: "zookeeper"
    static_configs:
      - targets: ["127.0.0.1:7000"]
  - job_name: "mysql"
    static_configs:
      - targets: ["127.0.0.1:9104"]
  - job_name: "windows"
    static_configs:
      - targets: ["127.0.0.1:9182"]

启动日志如下

2025-03-21T07:32:48.747Z        info    VictoriaMetrics/app/vmagent/main.go:169 started vmagent in 0.380 seconds
2025-03-21T07:32:48.747Z        info    VictoriaMetrics/lib/promscrape/scraper.go:118   reading scrape configs from "prometheus.yml"
2025-03-21T07:32:48.748Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:169        started server at http://0.0.0.0:8429/
2025-03-21T07:32:48.749Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:171        pprof handlers are exposed at http://0.0.0.0:8429/debug/pprof/
2025-03-21T07:32:48.753Z        info    VictoriaMetrics/lib/promscrape/config.go:149    starting service discovery routines...
2025-03-21T07:32:48.754Z        info    VictoriaMetrics/lib/promscrape/config.go:155    started 5 service discovery routines in 0.001 seconds
2025-03-21T07:32:48.754Z        info    VictoriaMetrics/lib/promscrape/scraper.go:439   static_configs: added targets: 5, removed targets: 0; total targets: 5

启动vmalert

https://docs.victoriametrics.com/vmalert/

启动命令

vmalert-windows-amd64-prod.exe -rule=rule-first.yml -datasource.url=http://127.0.0.1:8428 -notifier.url=http://127.0.0.1:9093 -notifier.url=http://127.0.0.1:9093 -remoteWrite.url=http://127.0.0.1:8428 -remoteRead.url=http://127.0.0.1:8428 -external.label=cluster=east-1 -external.label=replica=a

其中rule-first.yml为规则文件;​​http://127.0.0.1:8428​​​为victoriametrics服务地址;​​http://127.0.0.1:9093​​为AlertManger地址。

rule-first.yml规则配置文件内容如下

groups:
  - name: InstanceDown_Rule
    rules:
      - alert: InstanceDown  # 告警名称
        expr: up == 0        # 告警条件
        for: 30s              # 告警触发前需要持续满足条件的时间
        labels:
          severity: critical # 告警的严重程度
          instance: "{{$labels.instance}}"
        annotations:
          summary: "Instance {{ $labels.instance }} down"
          description: "Instance {{ $labels.instance }} has been down for more than 30 seconds."

启动日志如下

......
2025-03-21T07:39:41.952Z        info    VictoriaMetrics/app/vmalert/config/log/logger.go:52     found 1 files to read from "Local FS{MatchPattern: \"rule-first.yml\"}"
2025-03-21T07:39:41.955Z        info    VictoriaMetrics/app/vmalert/config/log/logger.go:52     finished reading 1 files in 889.8µs from "Local FS{MatchPattern: \"rule-first.yml\"}"
2025-03-21T07:39:41.956Z        info    VictoriaMetrics/app/vmalert/rule/group.go:497   group "InstanceDown_Rule" will start in 8.357938405s; interval=1m0s; eval_offset=<nil>; concurrency=1
2025-03-21T07:39:41.959Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:169        started server at http://0.0.0.0:8880/
2025-03-21T07:39:41.960Z        info    VictoriaMetrics/lib/httpserver/httpserver.go:171        pprof handlers are exposed at http://0.0.0.0:8880/debug/pprof/

访问地址

http://127.0.0.1:8880/

部署AlertManger

下载AlertManger

https://github.com/prometheus/alertmanager/releases

下载地址

https://github.com/prometheus/alertmanager/releases/download/v0.28.1/alertmanager-0.28.1.windows-amd64.zip

解压并启动,启动命令如下

alertmanager.exe --config.file=alertmanager.yml --log.level=debug

其中alertmanager.yml为alertmanager的配置文件,配置文件内容如下:

route:
#  group_by: ['alertname', 'instance', 'job']
  group_by: [...]
  group_wait: 10s
  group_interval: 20s
  repeat_interval: 30s
  receiver: 'web.hook'
receivers:
  - name: 'web.hook'
    webhook_configs:
      - url: 'http://127.0.0.1:5001/user/alert'
        send_resolved: true
#inhibit_rules:
#  - source_match:
#      severity: 'critical'
#    target_match:
#      severity: 'warning'
#    equal: ['alertname', 'instance', 'job']
global:
  resolve_timeout: 5m​​

http://127.0.0.1:5001/user/alert​​配置推送到应用服务的服务端点

启动日志如下

......
ts=2025-03-21T07:49:26.950Z caller=main.go:348 level=debug externalURL=http://P7507787A244:9093
ts=2025-03-21T07:49:26.951Z caller=coordinator.go:113 level=info component=configuration msg="Loading configuration file" file=alertmanager.yml
ts=2025-03-21T07:49:26.954Z caller=coordinator.go:126 level=info component=configuration msg="Completed loading of configuration file" file=alertmanager.yml
ts=2025-03-21T07:49:26.958Z caller=main.go:495 level=debug routePrefix=/
ts=2025-03-21T07:49:26.960Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:9093
ts=2025-03-21T07:49:26.962Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:9093

访问地址

http://127.0.0.1:9093

相关文章:

  • 对接马来西亚、印度、韩国、越南等全球金融数据示例
  • 个人作品集模板!除了Figma还可以选择什么软件?
  • neo4j-如何让外部设备访问wsl中的neo4j
  • Python 类与对象概念全解析:从零到实战
  • Ubuntu上安装Docker
  • 统计哲学的频率学派和贝叶斯学派
  • Redis的大Key问题如何解决?
  • 基于单片机的农作物自动灌溉系统
  • sougou AI close
  • Milvus WeightedRanker 对比 RRF 重排机制
  • Linux信号的诞生与归宿:内核如何管理信号的生成、阻塞和递达?
  • Mysql-经典实战案例(10):如何用PT-Archiver完成大表的自动归档
  • 英语:基础知识
  • teaming技术
  • vulnhub靶场【billu系列】之billu_b0x2靶机
  • Cell子刊 IF48.8 | 绘制 949 种癌细胞蛋白质组全景图,AI 算法锁定千种潜在药物靶点
  • 【达梦数据库】用户权限
  • 【C++】C++构造函数与析构函数
  • 使用 Ollama 本地部署 DeepSeek 模型及 Chatbox 配置
  • poetry安装与使用
  • 上海公办小学验证今起开始,下周一和周二分区进行民办摇号
  • 戛纳打破“疑罪从无”惯例,一法国男演员被拒之门外
  • 马上评|文玩字画竞拍轻松赚差价?严防这类新型传销
  • 牛市早报|4月新增社融1.16万亿,降准今日正式落地
  • 张涌任西安市委常委,已卸任西安市副市长职务
  • 中国-拉共体论坛第四届部长级会议北京宣言