Skip to content

Commit 033fd9f

Browse files
authored
add gps location info (#39)
1 parent 869596a commit 033fd9f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

internal/exporter/exporter.go

+46
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ const (
2020
)
2121

2222
var (
23+
// Location Info
24+
dishLocationInfo = prometheus.NewDesc(
25+
prometheus.BuildFQName(namespace, "dish", "location_info"),
26+
"Dish Location Info (GPS/Starlink)",
27+
[]string{
28+
"location_source",
29+
"lat",
30+
"lon",
31+
"alt"}, nil,
32+
)
33+
2334
// DeviceInfo
2435
dishInfo = prometheus.NewDesc(
2536
prometheus.BuildFQName(namespace, "dish", "info"),
@@ -395,6 +406,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
395406
start := time.Now()
396407

397408
ok := e.collectDishStatus(ch)
409+
ok = ok && e.collectDishLocationStatus(ch)
398410
ok = ok && e.collectDishObstructions(ch)
399411
ok = ok && e.collectDishAlerts(ch)
400412
ok = ok && e.collectDishConfig(ch)
@@ -437,6 +449,40 @@ func (e *Exporter) collectDishConfig(ch chan<- prometheus.Metric) bool {
437449
return true
438450
}
439451

452+
func (e *Exporter) collectDishLocationStatus(ch chan<- prometheus.Metric) bool {
453+
req := &device.Request{
454+
Request: &device.Request_GetLocation{},
455+
}
456+
457+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*1)
458+
defer cancel()
459+
460+
resp, err := e.Client.Handle(ctx, req)
461+
if err != nil {
462+
log.Errorf("failed to collect dish location: %s", err.Error())
463+
// don't return false since location service might not be enabled
464+
return true
465+
}
466+
467+
dishStatus := resp.GetGetLocation()
468+
locationSource := dishStatus.GetSource()
469+
470+
lla := dishStatus.GetLla()
471+
lat := lla.GetLat()
472+
lon := lla.GetLon()
473+
alt := lla.GetAlt()
474+
475+
ch <- prometheus.MustNewConstMetric(
476+
dishLocationInfo, prometheus.GaugeValue, 1.00,
477+
locationSource.String(),
478+
fmt.Sprint(lat),
479+
fmt.Sprint(lon),
480+
fmt.Sprint(alt),
481+
)
482+
483+
return true
484+
}
485+
440486
func (e *Exporter) collectDishStatus(ch chan<- prometheus.Metric) bool {
441487
req := &device.Request{
442488
Request: &device.Request_GetStatus{},

0 commit comments

Comments
 (0)