Implement support for quick device measurement metrics.

This commit is contained in:
Orne Brocaar
2022-06-28 15:05:42 +01:00
parent 4fa9341139
commit a01f8565fd
73 changed files with 8695 additions and 3833 deletions

View File

@ -7,6 +7,7 @@ option java_package = "io.chirpstack.api";
option java_multiple_files = true;
option java_outer_classname = "DeviceProto";
import "common/common.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/empty.proto";
@ -55,8 +56,13 @@ service DeviceService {
// GetRandomDevAddr returns a random DevAddr taking the NwkID prefix into account.
rpc GetRandomDevAddr(GetRandomDevAddrRequest) returns (GetRandomDevAddrResponse) {}
// GetStats returns the device stats.
rpc GetStats(GetDeviceStatsRequest) returns (GetDeviceStatsResponse) {}
// GetMetrics returns the device metrics.
// Note that this requires a device-profile with codec and measurements configured.
rpc GetMetrics(GetDeviceMetricsRequest) returns (GetDeviceMetricsResponse) {}
// GetLinkMetrics returns the device link metrics.
// This includes uplinks, downlinks, RSSI, SNR, etc...
rpc GetLinkMetrics(GetDeviceLinkMetricsRequest) returns (GetDeviceLinkMetricsResponse) {}
// Enqueue adds the given item to the downlink queue.
rpc Enqueue(EnqueueDeviceQueueItemRequest) returns (EnqueueDeviceQueueItemResponse) {}
@ -309,7 +315,7 @@ message GetRandomDevAddrResponse {
string dev_addr = 1;
}
message GetDeviceStatsRequest {
message GetDeviceMetricsRequest {
// DevEUI (EUI64).
string dev_eui = 1;
@ -318,33 +324,57 @@ message GetDeviceStatsRequest {
// Interval end timestamp.
google.protobuf.Timestamp end = 3;
// Aggregation.
common.Aggregation aggregation = 4;
}
message GetDeviceStatsResponse {
repeated DeviceStats result = 1;
message GetDeviceMetricsResponse {
map<string, common.Metric> metrics = 1;
map<string, DeviceState> states = 2;
}
message DeviceStats {
// Timestamp of the (aggregated) measurement.
google.protobuf.Timestamp time = 1;
message DeviceState {
// Name.
string name = 2;
// Value.
string value = 3;
}
message GetDeviceLinkMetricsRequest {
// DevEUI (EUI64).
string dev_eui = 1;
// Interval start timestamp.
google.protobuf.Timestamp start = 2;
// Interval end timestamp.
google.protobuf.Timestamp end = 3;
// Aggregation.
common.Aggregation aggregation = 4;
}
message GetDeviceLinkMetricsResponse {
// Packets received from the device.
uint32 rx_packets = 2;
common.Metric rx_packets = 1;
// Average RSSI (as reported by the gateway(s)).
float gw_rssi = 3;
// RSSI (as reported by the gateway(s)).
common.Metric gw_rssi = 2;
// Average SNR (as reported by the gateway(s)).
float gw_snr = 4;
// SNR (as reported by the gateway(s)).
common.Metric gw_snr = 3;
// Packets received by frequency.
map<uint32, uint32> rx_packets_per_frequency = 5;
common.Metric rx_packets_per_freq = 4;
// Packets received by DR.
map<uint32, uint32> rx_packets_per_dr = 6;
common.Metric rx_packets_per_dr = 5;
// Error count.
map<string, uint32> errors = 7;
// Errors.
common.Metric errors = 6;
}
message DeviceQueueItem {

View File

@ -22,6 +22,23 @@ enum CodecRuntime {
JS = 2;
}
enum MeasurementKind {
// Unknown (in which case it is not tracked).
UNKNOWN = 0;
// Incrementing counters that never decrease (these are not reset on each reading).
COUNTER = 1;
// Counters that do get reset upon reading.
ABSOLUTE = 2;
// E.g. a temperature value.
GAUGE = 3;
// E.g. a firmware version, true / false value.
STRING = 4;
}
// DeviceProfileService is the service providing API methods for managing device-profiles.
service DeviceProfileService {
// Create the given device-profile.
@ -129,6 +146,18 @@ message DeviceProfile {
// User defined tags.
map<string, string> tags = 25;
// Measurements.
// If defined, ChirpStack will visualize these metrics in the web-interface.
map<string, Measurement> measurements = 27;
}
message Measurement {
// Name (user defined).
string name = 2;
// Kind.
MeasurementKind kind = 3;
}
message DeviceProfileListItem {

View File

@ -118,6 +118,10 @@ message DeviceProfileTemplate {
// User defined tags.
map<string, string> tags = 27;
// Measurements.
// If defined, ChirpStack will visualize these metrics in the web-interface.
map<string, Measurement> measurements = 28;
}
message DeviceProfileTemplateListItem {

View File

@ -31,8 +31,8 @@ service GatewayService {
// Generate client-certificate for the gateway.
rpc GenerateClientCertificate(GenerateGatewayClientCertificateRequest) returns (GenerateGatewayClientCertificateResponse) {}
// GetStats returns the gateway stats.
rpc GetStats(GetGatewayStatsRequest) returns (GetGatewayStatsResponse) {}
// GetMetrics returns the gateway metrics.
rpc GetMetrics(GetGatewayMetricsRequest) returns (GetGatewayMetricsResponse) {}
}
message Gateway {
@ -163,7 +163,7 @@ message GenerateGatewayClientCertificateResponse {
google.protobuf.Timestamp expires_at = 4;
}
message GetGatewayStatsRequest {
message GetGatewayMetricsRequest {
// Gateway ID (EUI64).
string gateway_id = 1;
@ -172,34 +172,30 @@ message GetGatewayStatsRequest {
// Interval end timestamp.
google.protobuf.Timestamp end = 3;
// Aggregation.
common.Aggregation aggregation = 4;
}
message GetGatewayStatsResponse {
repeated GatewayStats result = 1;
}
message GatewayStats {
// Timestamp of the (aggregated) measurement.
google.protobuf.Timestamp time = 1;
// Packets received.
uint32 rx_packets = 2;
// Packets emitted.
uint32 tx_packets = 3;
// Tx packets per frequency.
map<uint32, uint32> tx_packets_per_frequency = 4;
// Rx packets per frequency.
map<uint32, uint32> rx_packets_per_frequency = 5;
// Tx packets per DR.
map<uint32, uint32> tx_packets_per_dr = 6;
// Rx packets per DR.
map<uint32, uint32> rx_packets_per_dr = 7;
// Tx packets per status.
map<string, uint32> tx_packets_per_status = 8;
message GetGatewayMetricsResponse {
// RX packets.
common.Metric rx_packets = 1;
// TX packets.
common.Metric tx_packets = 2;
// TX packets / frequency.
common.Metric tx_packets_per_freq = 3;
// RX packets / frequency.
common.Metric rx_packets_per_freq = 4;
// TX packets / DR.
common.Metric tx_packets_per_dr = 5;
// RX packets / DR.
common.Metric rx_packets_per_dr = 6;
// TX packets per status.
common.Metric tx_packets_per_status = 7;
}

View File

@ -7,6 +7,8 @@ option java_package = "io.chirpstack.api";
option java_multiple_files = true;
option java_outer_classname = "CommonProto";
import "google/protobuf/timestamp.proto";
enum Modulation {
// LoRa
LORA = 0;
@ -129,6 +131,17 @@ enum LocationSource {
GEO_RESOLVER_WIFI = 6;
}
enum Aggregation {
// Hour.
HOUR = 0;
// Day.
DAY = 1;
// Month.
MONTH = 2;
}
message Location {
// Latitude.
double latitude = 1;
@ -153,3 +166,23 @@ message KeyEnvelope {
// AES key (when the kek_label is set, this value must first be decrypted).
bytes aes_key = 2;
}
message Metric {
// Name.
string name = 1;
// Timestamps.
repeated google.protobuf.Timestamp timestamps = 2;
// Datasets.
repeated MetricDataset datasets = 3;
}
message MetricDataset {
// Label.
string label = 1;
// Data.
// Each value index corresponds with the same timestamp index of the Metric.
repeated float data = 2;
}