每日shell脚本之自动配置Prometheus.yml并支持选择监控的节点数量、输入自定义IP和端口设置
#!/bin/bash
read -p "请输入要监控的节点数量: " node_count
cat << EOF > Prometheus.yml
global:scrape_interval: 15sscrape_configs:
EOFfor ((i=1; i<=$node_count; i++))
doread -p "请输入第 $i 个节点的IP地址: " node_ipread -p "请输入第 $i 个节点的端口号: " node_portcat << EOF >> Prometheus.yml- job_name: 'node$i'static_configs:- targets: ['$node_ip:$node_port']
EOF
donecat << EOF >> Prometheus.yml
storage:local:path: /var/lib/prometheusrule_files:- /etc/prometheus/alert.rulesremote_write:- url: http://remote-write-url:8080/api/v1/writewrite_relabel_configs:- source_labels: [__name__]regex: '(.*)'target_label: __name__replacement: 'new_metric_name'
EOF
./prometheus --config.file=Prometheus.yml &