为 ONVIF 设备增加经纬度标签以支持 Geomap
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,12 +4,15 @@
|
||||
|
||||
## 指标
|
||||
|
||||
- `onvif_device_up`:1=可达,0=不可达(标签:instance, location, model, device_type)
|
||||
- `onvif_probe_duration_seconds`:探测耗时(秒)
|
||||
- `onvif_device_up`:1=可达,0=不可达
|
||||
- 标签:`instance`, `location`, `model`, `device_type`, `lat`, `lon`
|
||||
- `onvif_probe_duration_seconds`:探测耗时(秒)
|
||||
- 标签同上
|
||||
|
||||
## 配置
|
||||
|
||||
- 从 **config/onvif-targets.json** 读取设备列表(与 `targets.csv` 中 onvif 行一致,由 `config/update-configs.sh` 生成)。
|
||||
- 支持字段:`device_type`, `model`, `location`, `username`, `password`, `onvif_port`, `lat`, `lon`
|
||||
- 环境变量:`TARGETS_FILE`(默认 `/config/targets.json`)、`EXPORTER_PORT`(默认 9600)。
|
||||
|
||||
## 构建与运行
|
||||
|
||||
@@ -37,11 +37,11 @@ func main() {
|
||||
up := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "onvif_device_up",
|
||||
Help: "1 if ONVIF device is reachable, 0 otherwise",
|
||||
}, []string{"instance", "location", "model", "device_type"})
|
||||
}, []string{"instance", "location", "model", "device_type", "lat", "lon"})
|
||||
duration := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "onvif_probe_duration_seconds",
|
||||
Help: "ONVIF probe duration in seconds",
|
||||
}, []string{"instance", "location", "model", "device_type"})
|
||||
}, []string{"instance", "location", "model", "device_type", "lat", "lon"})
|
||||
|
||||
reg := prometheus.NewRegistry()
|
||||
reg.MustRegister(up, duration)
|
||||
@@ -87,6 +87,8 @@ func probe(targetsFile string, up, duration *prometheus.GaugeVec) {
|
||||
user := strings.TrimSpace(g.Labels["username"])
|
||||
pass := strings.TrimSpace(g.Labels["password"])
|
||||
location := strings.TrimSpace(g.Labels["location"])
|
||||
lat := strings.TrimSpace(g.Labels["lat"])
|
||||
lon := strings.TrimSpace(g.Labels["lon"])
|
||||
model := strings.TrimSpace(g.Labels["model"])
|
||||
deviceType := strings.TrimSpace(g.Labels["device_type"])
|
||||
instance := ip + ":" + port
|
||||
@@ -95,6 +97,8 @@ func probe(targetsFile string, up, duration *prometheus.GaugeVec) {
|
||||
"location": location,
|
||||
"model": model,
|
||||
"device_type": deviceType,
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user