Make gateway state consistent + make stats interval configurable.

This:

* Makes the gateway stats interval configurable (default 30 sec)
* Adds GatewayState type (NEVER_SEEN, OFFLINE, ONLINE)
* Adds gateway state to gateway lists
* Fixes dashboard inconsistencies

Closes #76.
This commit is contained in:
Orne Brocaar
2023-01-11 10:39:18 +00:00
parent d065df2805
commit 438d120fb0
32 changed files with 875 additions and 486 deletions

View File

@ -29,6 +29,9 @@ export class Gateway extends jspb.Message {
clearTagsMap(): void;
getMetadataMap(): jspb.Map<string, string>;
clearMetadataMap(): void;
getStatsInterval(): number;
setStatsInterval(value: number): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): Gateway.AsObject;
static toObject(includeInstance: boolean, msg: Gateway): Gateway.AsObject;
@ -48,6 +51,7 @@ export namespace Gateway {
tenantId: string,
tagsMap: Array<[string, string]>,
metadataMap: Array<[string, string]>,
statsInterval: number,
}
}
@ -86,6 +90,9 @@ export class GatewayListItem extends jspb.Message {
getLastSeenAt(): google_protobuf_timestamp_pb.Timestamp | undefined;
setLastSeenAt(value?: google_protobuf_timestamp_pb.Timestamp): void;
getState(): GatewayStateMap[keyof GatewayStateMap];
setState(value: GatewayStateMap[keyof GatewayStateMap]): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): GatewayListItem.AsObject;
static toObject(includeInstance: boolean, msg: GatewayListItem): GatewayListItem.AsObject;
@ -107,6 +114,7 @@ export namespace GatewayListItem {
createdAt?: google_protobuf_timestamp_pb.Timestamp.AsObject,
updatedAt?: google_protobuf_timestamp_pb.Timestamp.AsObject,
lastSeenAt?: google_protobuf_timestamp_pb.Timestamp.AsObject,
state: GatewayStateMap[keyof GatewayStateMap],
}
}
@ -440,3 +448,11 @@ export namespace GetGatewayMetricsResponse {
}
}
export interface GatewayStateMap {
NEVER_SEEN: 0;
ONLINE: 1;
OFFLINE: 2;
}
export const GatewayState: GatewayStateMap;

View File

@ -24,6 +24,7 @@ goog.exportSymbol('proto.api.CreateGatewayRequest', null, global);
goog.exportSymbol('proto.api.DeleteGatewayRequest', null, global);
goog.exportSymbol('proto.api.Gateway', null, global);
goog.exportSymbol('proto.api.GatewayListItem', null, global);
goog.exportSymbol('proto.api.GatewayState', null, global);
goog.exportSymbol('proto.api.GenerateGatewayClientCertificateRequest', null, global);
goog.exportSymbol('proto.api.GenerateGatewayClientCertificateResponse', null, global);
goog.exportSymbol('proto.api.GetGatewayMetricsRequest', null, global);
@ -344,7 +345,8 @@ proto.api.Gateway.toObject = function(includeInstance, msg) {
location: (f = msg.getLocation()) && common_common_pb.Location.toObject(includeInstance, f),
tenantId: jspb.Message.getFieldWithDefault(msg, 5, ""),
tagsMap: (f = msg.getTagsMap()) ? f.toObject(includeInstance, undefined) : [],
metadataMap: (f = msg.getMetadataMap()) ? f.toObject(includeInstance, undefined) : []
metadataMap: (f = msg.getMetadataMap()) ? f.toObject(includeInstance, undefined) : [],
statsInterval: jspb.Message.getFieldWithDefault(msg, 8, 0)
};
if (includeInstance) {
@ -414,6 +416,10 @@ proto.api.Gateway.deserializeBinaryFromReader = function(msg, reader) {
jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readString, null, "", "");
});
break;
case 8:
var value = /** @type {number} */ (reader.readUint32());
msg.setStatsInterval(value);
break;
default:
reader.skipField();
break;
@ -487,6 +493,13 @@ proto.api.Gateway.serializeBinaryToWriter = function(message, writer) {
if (f && f.getLength() > 0) {
f.serializeBinary(7, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString);
}
f = message.getStatsInterval();
if (f !== 0) {
writer.writeUint32(
8,
f
);
}
};
@ -643,6 +656,24 @@ proto.api.Gateway.prototype.clearMetadataMap = function() {
return this;};
/**
* optional uint32 stats_interval = 8;
* @return {number}
*/
proto.api.Gateway.prototype.getStatsInterval = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 8, 0));
};
/**
* @param {number} value
* @return {!proto.api.Gateway} returns this
*/
proto.api.Gateway.prototype.setStatsInterval = function(value) {
return jspb.Message.setProto3IntField(this, 8, value);
};
@ -683,7 +714,8 @@ proto.api.GatewayListItem.toObject = function(includeInstance, msg) {
propertiesMap: (f = msg.getPropertiesMap()) ? f.toObject(includeInstance, undefined) : [],
createdAt: (f = msg.getCreatedAt()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f),
updatedAt: (f = msg.getUpdatedAt()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f),
lastSeenAt: (f = msg.getLastSeenAt()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f)
lastSeenAt: (f = msg.getLastSeenAt()) && google_protobuf_timestamp_pb.Timestamp.toObject(includeInstance, f),
state: jspb.Message.getFieldWithDefault(msg, 10, 0)
};
if (includeInstance) {
@ -762,6 +794,10 @@ proto.api.GatewayListItem.deserializeBinaryFromReader = function(msg, reader) {
reader.readMessage(value,google_protobuf_timestamp_pb.Timestamp.deserializeBinaryFromReader);
msg.setLastSeenAt(value);
break;
case 10:
var value = /** @type {!proto.api.GatewayState} */ (reader.readEnum());
msg.setState(value);
break;
default:
reader.skipField();
break;
@ -855,6 +891,13 @@ proto.api.GatewayListItem.serializeBinaryToWriter = function(message, writer) {
google_protobuf_timestamp_pb.Timestamp.serializeBinaryToWriter
);
}
f = message.getState();
if (f !== 0.0) {
writer.writeEnum(
10,
f
);
}
};
@ -1100,6 +1143,24 @@ proto.api.GatewayListItem.prototype.hasLastSeenAt = function() {
};
/**
* optional GatewayState state = 10;
* @return {!proto.api.GatewayState}
*/
proto.api.GatewayListItem.prototype.getState = function() {
return /** @type {!proto.api.GatewayState} */ (jspb.Message.getFieldWithDefault(this, 10, 0));
};
/**
* @param {!proto.api.GatewayState} value
* @return {!proto.api.GatewayListItem} returns this
*/
proto.api.GatewayListItem.prototype.setState = function(value) {
return jspb.Message.setProto3EnumField(this, 10, value);
};
@ -3466,4 +3527,13 @@ proto.api.GetGatewayMetricsResponse.prototype.hasTxPacketsPerStatus = function()
};
/**
* @enum {number}
*/
proto.api.GatewayState = {
NEVER_SEEN: 0,
ONLINE: 1,
OFFLINE: 2
};
goog.object.extend(exports, proto.api);

View File

@ -555,11 +555,11 @@ export namespace GetGatewaysSummaryRequest {
}
export class GetGatewaysSummaryResponse extends jspb.Message {
getActiveCount(): number;
setActiveCount(value: number): void;
getOnlineCount(): number;
setOnlineCount(value: number): void;
getInactiveCount(): number;
setInactiveCount(value: number): void;
getOfflineCount(): number;
setOfflineCount(value: number): void;
getNeverSeenCount(): number;
setNeverSeenCount(value: number): void;
@ -576,8 +576,8 @@ export class GetGatewaysSummaryResponse extends jspb.Message {
export namespace GetGatewaysSummaryResponse {
export type AsObject = {
activeCount: number,
inactiveCount: number,
onlineCount: number,
offlineCount: number,
neverSeenCount: number,
}
}

View File

@ -4500,8 +4500,8 @@ proto.api.GetGatewaysSummaryResponse.prototype.toObject = function(opt_includeIn
*/
proto.api.GetGatewaysSummaryResponse.toObject = function(includeInstance, msg) {
var f, obj = {
activeCount: jspb.Message.getFieldWithDefault(msg, 1, 0),
inactiveCount: jspb.Message.getFieldWithDefault(msg, 2, 0),
onlineCount: jspb.Message.getFieldWithDefault(msg, 1, 0),
offlineCount: jspb.Message.getFieldWithDefault(msg, 2, 0),
neverSeenCount: jspb.Message.getFieldWithDefault(msg, 3, 0)
};
@ -4541,11 +4541,11 @@ proto.api.GetGatewaysSummaryResponse.deserializeBinaryFromReader = function(msg,
switch (field) {
case 1:
var value = /** @type {number} */ (reader.readUint32());
msg.setActiveCount(value);
msg.setOnlineCount(value);
break;
case 2:
var value = /** @type {number} */ (reader.readUint32());
msg.setInactiveCount(value);
msg.setOfflineCount(value);
break;
case 3:
var value = /** @type {number} */ (reader.readUint32());
@ -4580,14 +4580,14 @@ proto.api.GetGatewaysSummaryResponse.prototype.serializeBinary = function() {
*/
proto.api.GetGatewaysSummaryResponse.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getActiveCount();
f = message.getOnlineCount();
if (f !== 0) {
writer.writeUint32(
1,
f
);
}
f = message.getInactiveCount();
f = message.getOfflineCount();
if (f !== 0) {
writer.writeUint32(
2,
@ -4605,10 +4605,10 @@ proto.api.GetGatewaysSummaryResponse.serializeBinaryToWriter = function(message,
/**
* optional uint32 active_count = 1;
* optional uint32 online_count = 1;
* @return {number}
*/
proto.api.GetGatewaysSummaryResponse.prototype.getActiveCount = function() {
proto.api.GetGatewaysSummaryResponse.prototype.getOnlineCount = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0));
};
@ -4617,16 +4617,16 @@ proto.api.GetGatewaysSummaryResponse.prototype.getActiveCount = function() {
* @param {number} value
* @return {!proto.api.GetGatewaysSummaryResponse} returns this
*/
proto.api.GetGatewaysSummaryResponse.prototype.setActiveCount = function(value) {
proto.api.GetGatewaysSummaryResponse.prototype.setOnlineCount = function(value) {
return jspb.Message.setProto3IntField(this, 1, value);
};
/**
* optional uint32 inactive_count = 2;
* optional uint32 offline_count = 2;
* @return {number}
*/
proto.api.GetGatewaysSummaryResponse.prototype.getInactiveCount = function() {
proto.api.GetGatewaysSummaryResponse.prototype.getOfflineCount = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
};
@ -4635,7 +4635,7 @@ proto.api.GetGatewaysSummaryResponse.prototype.getInactiveCount = function() {
* @param {number} value
* @return {!proto.api.GetGatewaysSummaryResponse} returns this
*/
proto.api.GetGatewaysSummaryResponse.prototype.setInactiveCount = function(value) {
proto.api.GetGatewaysSummaryResponse.prototype.setOfflineCount = function(value) {
return jspb.Message.setProto3IntField(this, 2, value);
};