温馨提示×

如何监控centos trigger

小樊
45
2026-10-17 19:22:40
栏目: 智能运维

在 CentOS 里,“trigger” 这个词常见于几种不同场景,先帮你梳理一下,再给出对应的监控方法。


一、如果你说的是 systemd trigger(服务触发)

CentOS 7+ 使用 systemd,trigger 通常指:

  • systemctl trigger
  • socket / path / timer 触发的 unit
  • 某个服务被其他服务触发启动

监控方式

1️⃣ 查看 trigger 关系

systemctl list-triggers

或查看某个服务:

systemctl show xxx.service | grep Triggers

2️⃣ 实时监控 systemd 触发事件

journalctl -u xxx.service -f

或全局看触发:

journalctl -f | grep -i trigger

3️⃣ 使用 systemd 日志分析

journalctl -p 3 -xb

二、如果你说的是 inotify / 文件触发(trigger 脚本)

比如:

  • 文件变化触发脚本
  • 目录监听

监控方式

1️⃣ 使用 inotifywait(推荐)

yum install inotify-tools
inotifywait -m /path/to/dir

2️⃣ 写监控脚本

inotifywait -m -e create -e modify /data |
while read path action file
do
    echo "$file $action"
done

三、如果你说的是 cron / timer 触发的任务

监控方式

1️⃣ 查看 cron 触发

cat /var/log/cron

2️⃣ systemd timer 触发

systemctl list-timers
journalctl -u your.timer -f

四、如果你说的是 数据库 trigger(MySQL / PostgreSQL)

MySQL

  • 不能直接“监控”
  • 可通过:
    • 审计日志
    • binlog
mysqlbinlog /var/lib/mysql/mysql-bin.000001

PostgreSQL

SELECT * FROM pg_trigger;

结合日志:

tail -f /var/lib/pgsql/data/log/postgresql.log

五、通用监控方案(强烈推荐)

Prometheus + node_exporter

  • 监控服务状态
  • 自定义 trigger 指标

ELK / Grafana Loki

  • 收集 systemd / cron / 脚本日志
  • 设置 trigger 告警

六、你到底想监控什么?

可以告诉我:

  1. trigger 是 systemd / 文件 / cron / 数据库?
  2. 是想 实时看、记录日志 还是 报警?

我可以直接给你可复制的配置或脚本。

0 踩