Prometheus 自定义监控

自定义脚本

#!/bin/bash

# 获取内存信息
total_memory=$(free | awk '/Mem/ {print $2}')  # 总内存(KB)
used_memory=$(free | awk '/Mem/ {print $3}')   # 已用内存(KB)

# 定义作业和实例名称
job_name="custom_category.monitor"
instance_name=$(hostname -I | awk '{print $1}')  # 获取本机IP

# Pushgateway 服务器地址
pushgateway_url="http://192.168.174.149:19091/metrics/job/$job_name/instance/$instance_name"

# 推送指标到 Pushgateway
cat <<EOF | curl --data-binary @- "$pushgateway_url"
# TYPE custom_memory_total gauge
custom_memory_total $total_memory
# TYPE custom_memory_used gauge
custom_memory_used $used_memory
EOF

验证指标

posted @ 2025-04-03 15:25  小吉猫  阅读(28)  评论(0)    收藏  举报