“Execute” 具体指什么技术栈里的执行,监控方式差别很大。下面按常见场景分别说明,你可以对号入座;如果是特定工具(如 Ansible、SQL、Shell、Java、Python、K8s Job 等),可以再细说。
目标:看脚本是否执行、成功与否、耗时、输出
bash script.sh \
> run.log 2>&1
echo "exit code: $?"
nohup bash script.sh > run.log 2>&1 &
echo $! # 进程 PID
ps -ef | grep script.sh
top -p <pid>
logrotateif [ $? -ne 0 ]; then
echo "execute failed" | mail -s "Alert" admin@x.com
fi
目标:慢查询、失败 SQL、执行次数
SHOW PROCESSLIST;
慢查询:
SHOW VARIABLES LIKE 'slow_query_log';
审计(推荐):
general_logperformance_schemaSELECT * FROM pg_stat_activity;
@Around("execution(* com.x.service.*.execute(..))")
Timer.timer("execute.time").record(...)
import time, logging
start = time.time()
try:
execute()
except Exception as e:
logging.error("execute failed", exc_info=True)
finally:
logging.info("cost: %.2fs", time.time()-start)
* * * * * /opt/run.sh >> /var/log/run.log 2>&1
kubectl get jobs
kubectl logs job/xxx
我可以给更精确的方案,如果说明:
例如:
“我想监控 Linux 上每天跑的 shell execute 是否成功”
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。