Skip to content

Commit

Permalink
feat(history): get history from Dishy (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphielscape authored Nov 5, 2024
1 parent 256b250 commit 72417a6
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 8 deletions.
32 changes: 32 additions & 0 deletions internal/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ var (
"Starlink dish downlink throughput in bit/sec",
nil, nil,
)
dishDownlinkThroughputHistogram = prometheus.NewDesc(
prometheus.BuildFQName(namespace, dishSubsystem, "downlink_throughput_histogram"),
"Histogram of Starlink dish downlink throughput over last 15 minutes",
nil, nil,
)
dishUplinkThroughputHistogram = prometheus.NewDesc(
prometheus.BuildFQName(namespace, dishSubsystem, "uplink_throughput_histogram"),
"Histogram of Starlink dish uplink throughput over last 15 minutes",
nil, nil,
)

// PoP ping
dishPopPingDropRatio = prometheus.NewDesc(
Expand All @@ -99,6 +109,23 @@ var (
"Starlink PoP ping latency in seconds",
nil, nil,
)
dishPopPingLatencyHistogram = prometheus.NewDesc(
prometheus.BuildFQName(namespace, dishSubsystem, "pop_ping_latency_histogram"),
"Histogram of Starlink dish pop ping latency over last 15 minutes",
nil, nil,
)

// Power In
dishPowerInputHistogram = prometheus.NewDesc(
prometheus.BuildFQName(namespace, dishSubsystem, "power_input_histogram"),
"Histogram of Starlink dish power input over last 15 minutes",
nil, nil,
)
dishPowerInput = prometheus.NewDesc(
prometheus.BuildFQName(namespace, dishSubsystem, "power_input"),
"Current power input for the Starlink dish",
nil, nil,
)

// Software update
dishSoftwareUpdateState = prometheus.NewDesc(
Expand Down Expand Up @@ -211,15 +238,20 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- dishSnrPersistentlyLow
ch <- dishUplinkThroughputBps
ch <- dishDownlinkThroughputBps
ch <- dishDownlinkThroughputHistogram
ch <- dishUplinkThroughputHistogram
ch <- dishPopPingDropRatio
ch <- dishPopPingLatencySeconds
ch <- dishPopPingLatencyHistogram
ch <- dishSoftwareUpdateRebootReady
ch <- dishBoresightAzimuthDeg
ch <- dishBoresightElevationDeg
ch <- dishCurrentlyObstructed
ch <- dishFractionObstructionRatio
ch <- dishLast24HoursObstructedSeconds
ch <- dishProlongedObstructionDurationSeconds
ch <- dishPowerInputHistogram
ch <- dishPowerInput
}

func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
Expand Down
103 changes: 95 additions & 8 deletions internal/exporter/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ func (e *Exporter) scrapeDishStatus(ctx context.Context, ch chan<- prometheus.Me
return false
}

hist, err := e.client.Handle(ctx, &device.Request{
Request: new(device.Request_GetHistory),
})
if err != nil {
slog.Error("Failed to scrape dish history context", slog.Any("err", err))
return false
}

dishStatus := res.GetDishGetStatus()
deviceInfo := dishStatus.GetDeviceInfo()
deviceState := dishStatus.GetDeviceState()
obstructionStats := dishStatus.GetObstructionStats()
dishHistory := hist.GetDishGetHistory()

// starlink_dish_info
ch <- prometheus.MustNewConstMetric(
Expand All @@ -103,6 +112,72 @@ func (e *Exporter) scrapeDishStatus(ctx context.Context, ch chan<- prometheus.Me
itos(deviceInfo.GetBootcount()),
)

// starlink_dish_pop_ping_latency_histogram
latencyBuckets := []float64{0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0}
latencyData := parseRingBuffer(dishHistory.GetPopPingLatencyMs(), dishHistory.GetCurrent())
latencyHist := prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: dishSubsystem,
Name: "pop_ping_latency_histogram",
Help: "Histogram of Starlink dish pop ping latency over last 15 minutes",
Buckets: latencyBuckets,
})

for _, latency := range latencyData {
latencyHist.Observe(float64(latency) / 1000) // Convert ms to seconds
}
ch <- latencyHist

// starlink_dish_downlink_throughput_histogram
throughputBuckets := []float64{1e6, 5e6, 10e6, 25e6, 50e6, 100e6, 250e6, 500e6}
downlinkData := parseRingBuffer(dishHistory.GetDownlinkThroughputBps(), dishHistory.GetCurrent())

downlinkHist := prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: dishSubsystem,
Name: "downlink_throughput_histogram",
Help: "Histogram of Starlink dish downlink throughput over last 15 minutes",
Buckets: throughputBuckets,
})

for _, throughput := range downlinkData {
downlinkHist.Observe(float64(throughput))
}
ch <- downlinkHist

// starlink_dish_uplink_throughput_histogram
uplinkData := parseRingBuffer(dishHistory.GetUplinkThroughputBps(), dishHistory.GetCurrent())

uplinkHist := prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: dishSubsystem,
Name: "uplink_throughput_histogram",
Help: "Histogram of Starlink dish uplink throughput over last 15 minutes",
Buckets: throughputBuckets,
})

for _, throughput := range uplinkData {
uplinkHist.Observe(float64(throughput))
}
ch <- uplinkHist

// starlink_dish_power_input_histogram
powerBuckets := []float64{20, 50, 75, 100, 150, 200}
powerData := parseRingBuffer(dishHistory.GetPowerIn(), dishHistory.GetCurrent())

powerHist := prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: dishSubsystem,
Name: "power_input_histogram",
Help: "Histogram of Starlink dish power input over last 15 minutes",
Buckets: powerBuckets,
})

for _, power := range powerData {
powerHist.Observe(float64(power))
}
ch <- powerHist

// starlink_dish_uptime_seconds
ch <- prometheus.MustNewConstMetric(
dishUptimeSeconds, prometheus.GaugeValue,
Expand All @@ -122,16 +197,28 @@ func (e *Exporter) scrapeDishStatus(ctx context.Context, ch chan<- prometheus.Me
)

// starlink_dish_uplink_throughput_bps
ch <- prometheus.MustNewConstMetric(
dishUplinkThroughputBps, prometheus.GaugeValue,
float64(dishStatus.GetUplinkThroughputBps()),
)
if len(uplinkData) > 0 {
ch <- prometheus.MustNewConstMetric(
dishUplinkThroughputBps, prometheus.GaugeValue,
float64(uplinkData[len(uplinkData)-1]),
)
}

// starlink_dish_downlink_throughput_bps
ch <- prometheus.MustNewConstMetric(
dishDownlinkThroughputBps, prometheus.GaugeValue,
float64(dishStatus.GetDownlinkThroughputBps()),
)
if len(downlinkData) > 0 {
ch <- prometheus.MustNewConstMetric(
dishDownlinkThroughputBps, prometheus.GaugeValue,
float64(downlinkData[len(downlinkData)-1]),
)
}

// starlink_dish_power_input
if len(powerData) > 0 {
ch <- prometheus.MustNewConstMetric(
dishPowerInput, prometheus.GaugeValue,
float64(powerData[len(powerData)-1]),
)
}

// starlink_dish_pop_ping_drop_ratio
ch <- prometheus.MustNewConstMetric(
Expand Down
14 changes: 14 additions & 0 deletions internal/exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ func btof(b bool) float64 {
}
return 0
}

// parseRingBuffer parses the ringbuffer of history data
func parseRingBuffer(data []float32, current uint64) []float32 {
bufferSize := uint64(len(data))
if current <= bufferSize {
return data[:current]
}

start := current % bufferSize
result := make([]float32, bufferSize)
copy(result, data[start:])
copy(result[bufferSize-start:], data[:start])
return result
}

0 comments on commit 72417a6

Please sign in to comment.