每日shell脚本之自动配置Prometheus.yml并支持选择监控的节点数量、输入自定义IP和端口设置

每日shell脚本之自动配置Prometheus.yml并支持选择监控的节点数量、输入自定义IP和端口设置

bash 复制代码
#!/bin/bash

# 获取用户输入的节点数量
read -p "请输入要监控的节点数量: " node_count

# 生成Prometheus.yml配置文件
cat << EOF > Prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
EOF

for ((i=1; i<=$node_count; i++))
do
  read -p "请输入第 $i 个节点的IP地址: " node_ip
  read -p "请输入第 $i 个节点的端口号: " node_port
  cat << EOF >> Prometheus.yml
  - job_name: 'node$i'
    static_configs:
      - targets: ['$node_ip:$node_port']
EOF
done

cat << EOF >> Prometheus.yml
storage:
  local:
    path: /var/lib/prometheus

rule_files:
  - /etc/prometheus/alert.rules

remote_write:
  - url: http://remote-write-url:8080/api/v1/write
    write_relabel_configs:
      - source_labels: [__name__]
        regex: '(.*)'
        target_label: __name__
        replacement: 'new_metric_name'
EOF

# 启动Prometheus进程
./prometheus --config.file=Prometheus.yml &
相关推荐
甲鱼92911 小时前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
Johny_Zhao1 天前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
blasit1 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
YuMiao2 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
chlk1233 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑3 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件3 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒3 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号3 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash3 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)