Commit a91c581a authored by Orne Brocaar's avatar Orne Brocaar
Browse files

Implement forwarding improved gw stats.

parent e84b6985
......@@ -211,15 +211,20 @@ func forwardGatewayStats(ctx *statsContext) error {
}
_, err = asClient.HandleGatewayStats(ctx.ctx, &as.HandleGatewayStatsRequest{
GatewayId: ctx.gatewayStats.GatewayId,
StatsId: ctx.gatewayStats.StatsId,
Time: ctx.gatewayStats.Time,
Location: ctx.gatewayStats.Location,
RxPacketsReceived: ctx.gatewayStats.RxPacketsReceived,
RxPacketsReceivedOk: ctx.gatewayStats.RxPacketsReceivedOk,
TxPacketsReceived: ctx.gatewayStats.TxPacketsReceived,
TxPacketsEmitted: ctx.gatewayStats.TxPacketsEmitted,
Metadata: ctx.gatewayStats.MetaData,
GatewayId: ctx.gatewayStats.GatewayId,
StatsId: ctx.gatewayStats.StatsId,
Time: ctx.gatewayStats.Time,
Location: ctx.gatewayStats.Location,
RxPacketsReceived: ctx.gatewayStats.RxPacketsReceived,
RxPacketsReceivedOk: ctx.gatewayStats.RxPacketsReceivedOk,
TxPacketsReceived: ctx.gatewayStats.TxPacketsReceived,
TxPacketsEmitted: ctx.gatewayStats.TxPacketsEmitted,
Metadata: ctx.gatewayStats.MetaData,
TxPacketsPerFrequency: ctx.gatewayStats.TxPacketsPerFrequency,
RxPacketsPerFrequency: ctx.gatewayStats.RxPacketsPerFrequency,
TxPacketsPerDr: perModulationToPerDR(false, ctx.gatewayStats.TxPacketsPerModulation),
RxPacketsPerDr: perModulationToPerDR(true, ctx.gatewayStats.RxPacketsPerModulation),
TxPacketsPerStatus: ctx.gatewayStats.TxPacketsPerStatus,
})
if err != nil {
return errors.Wrap(err, "handle gateway stats error")
......@@ -227,3 +232,44 @@ func forwardGatewayStats(ctx *statsContext) error {
return nil
}
func perModulationToPerDR(uplink bool, items []*gw.PerModulationCount) map[uint32]uint32 {
out := make(map[uint32]uint32)
b := band.Band()
for _, item := range items {
mod := item.GetModulation()
var dr loraband.DataRate
if modParams := mod.GetLora(); modParams != nil {
dr = loraband.DataRate{
Modulation: loraband.LoRaModulation,
SpreadFactor: int(modParams.SpreadingFactor),
Bandwidth: int(modParams.Bandwidth),
}
}
if modParams := mod.GetFsk(); modParams != nil {
dr = loraband.DataRate{
Modulation: loraband.FSKModulation,
BitRate: int(modParams.Datarate),
}
}
if modParams := mod.GetLrFhss(); modParams != nil {
dr = loraband.DataRate{
Modulation: loraband.LRFHSSModulation,
CodingRate: modParams.CodeRate,
OccupiedChannelWidth: int(modParams.OperatingChannelWidth),
}
}
if dr, err := b.GetDataRateIndex(uplink, dr); err == nil {
out[uint32(dr)] = out[uint32(dr)] + item.Count
} else {
log.WithError(err).Error("gateway/stats: convert modulation parameters to data-rate error")
}
}
return out
}
......@@ -236,6 +236,45 @@ func (ts *GatewayStatsTestSuite) TestStats() {
RxPacketsReceivedOk: 9,
TxPacketsReceived: 13,
TxPacketsEmitted: 10,
TxPacketsPerFrequency: map[uint32]uint32{
868100000: 10,
},
RxPacketsPerFrequency: map[uint32]uint32{
868300000: 9,
},
TxPacketsPerModulation: []*gw.PerModulationCount{
{
Modulation: &gw.Modulation{
Parameters: &gw.Modulation_Lora{
Lora: &gw.LoRaModulationInfo{
Bandwidth: 125,
SpreadingFactor: 8,
CodeRate: "4/5",
},
},
},
Count: 10,
},
},
RxPacketsPerModulation: []*gw.PerModulationCount{
{
Modulation: &gw.Modulation{
Parameters: &gw.Modulation_Lora{
Lora: &gw.LoRaModulationInfo{
Bandwidth: 125,
SpreadingFactor: 10,
CodeRate: "4/5",
},
},
},
Count: 9,
},
},
TxPacketsPerStatus: map[string]uint32{
"OK": 10,
"TOO_LATE": 3,
},
MetaData: map[string]string{
"foo": "bar",
},
......@@ -253,6 +292,22 @@ func (ts *GatewayStatsTestSuite) TestStats() {
RxPacketsReceivedOk: stats.RxPacketsReceivedOk,
TxPacketsReceived: stats.TxPacketsReceived,
TxPacketsEmitted: stats.TxPacketsEmitted,
TxPacketsPerFrequency: map[uint32]uint32{
868100000: 10,
},
RxPacketsPerFrequency: map[uint32]uint32{
868300000: 9,
},
TxPacketsPerDr: map[uint32]uint32{
4: 10,
},
RxPacketsPerDr: map[uint32]uint32{
2: 9,
},
TxPacketsPerStatus: map[string]uint32{
"OK": 10,
"TOO_LATE": 3,
},
Metadata: map[string]string{
"foo": "bar",
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment