每日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 &
相关推荐
搬码临时工23 分钟前
如何把本地服务器变成公网服务器?内网ip网址转换到外网连接访问
运维·服务器·网络·tcp/ip·智能路由器·远程工作·访问公司内网
vortex528 分钟前
探索 Shell:选择适合你的命令行利器 bash, zsh, fish, dash, sh...
linux·开发语言·bash·shell·dash
GalaxyPokemon1 小时前
LeetCode - 148. 排序链表
linux·算法·leetcode
Guheyunyi1 小时前
监测预警系统重塑隧道安全新范式
大数据·运维·人工智能·科技·安全
懒羊羊大王呀1 小时前
Ubuntu20.04中 Redis 的安装和配置
linux·redis
鳄鱼杆1 小时前
服务器 | Centos 9 系统中,如何部署SpringBoot后端项目?
服务器·spring boot·centos
杰哥技术分享1 小时前
在 CentOS 上安装 Docker 和 Docker Compose 并配置使用国内镜像源
linux·docker·centos
知更鸟呆呆2 小时前
【Linux操作系统】基础开发工具(yum、vim、gcc/g++)
linux·运维·vim
xiangyong582 小时前
ubuntu系统文件误删(/lib/x86_64-linux-gnu/libc.so.6)修复方案 [成功解决]
linux·ubuntu·gnu
jingyucsdn2 小时前
网页端 VUE+C#/FastAPI获取客户端IP和hostname
网络协议·tcp/ip·fastapi