prometheus启停脚本
时间: 2023-12-03 16:03:39 浏览: 32
以下是一个简单的 Prometheus 启停脚本示例。
启动脚本:
```bash
#!/bin/bash
# 指定 Prometheus 配置文件路径
CONFIG_FILE="/path/to/prometheus.yml"
# 启动 Prometheus
nohup /path/to/prometheus --config.file=${CONFIG_FILE} > /dev/null 2>&1 &
```
停止脚本:
```bash
#!/bin/bash
# 查找 Prometheus 进程 ID
PID=$(pgrep -f /path/to/prometheus)
if [ -z "${PID}" ]; then
echo "Prometheus is not running"
else
# 停止 Prometheus
kill -SIGTERM ${PID}
echo "Prometheus stopped"
fi
```
使用方法:
1. 将以上启动脚本和停止脚本保存为不同的文件,如 `start_prometheus.sh` 和 `stop_prometheus.sh`。
2. 根据需要修改启动脚本中的 Prometheus 配置文件路径。
3. 给两个脚本添加执行权限:`chmod +x start_prometheus.sh stop_prometheus.sh`。
4. 启动 Prometheus:`./start_prometheus.sh`。
5. 停止 Prometheus:`./stop_prometheus.sh`。