fix heartbeat + add kerberos hub connection kpi

This commit is contained in:
Thomas Quandalle
2022-08-31 10:06:56 +02:00
parent f2b1f82f59
commit cdca6d77cb
7 changed files with 39 additions and 23 deletions
+12 -10
View File
@@ -126,13 +126,6 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
loop:
for {
// This will check if we need to stop the thread,
// because of a reconfiguration.
select {
case <-communication.HandleHeartBeat:
break loop
case <-time.After(30 * time.Second):
}
uptime, _ := host.Uptime()
days := strconv.Itoa(int(uptime / (60 * 60 * 24)))
@@ -149,9 +142,9 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
// Check if the agent is running inside a cluster (Kerberos Factory) or as
// an open source agent
isEnterprise := "false"
isEnterprise := false
if os.Getenv("DEPLOYMENT") == "factory" || os.Getenv("MACHINERY_ENVIRONMENT") == "kubernetes" {
isEnterprise = "true"
isEnterprise = true
}
var object = fmt.Sprintf(`{
@@ -166,7 +159,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
"docker" : true,
"kios" : false,
"raspberrypi" : false,
"enterprise" : "%s",
"enterprise" : %t,
"board" : "",
"disk1size" : "%s",
"disk3size" : "%s",
@@ -192,6 +185,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
resp.Body.Close()
}
if err == nil && resp.StatusCode == 200 {
communication.CloudTimestamp.Store(time.Now().Unix())
log.Log.Info("HandleHeartBeat: (200) Heartbeat received by Kerberos Hub.")
} else {
log.Log.Error("HandleHeartBeat: (400) Something went wrong while sending to Kerberos Hub.")
@@ -215,6 +209,14 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models.
log.Log.Error("HandleHeartBeat: (400) Something went wrong while sending to Kerberos Vault.")
}
}
// This will check if we need to stop the thread,
// because of a reconfiguration.
select {
case <-communication.HandleHeartBeat:
break loop
case <-time.After(15 * time.Second):
}
}
}
+6
View File
@@ -32,6 +32,12 @@ func Bootstrap(configuration *models.Configuration, communication *models.Commun
packageCounter.Store(int64(0))
communication.LastPacketTimer = &lastPacketTimer
// This is used to understand if we have a working Kerberos Hub connection
// cloudTimestamp will be updated when successfully sending heartbeats.
var cloudTimestamp atomic.Value
cloudTimestamp.Store(int64(0))
communication.CloudTimestamp = &cloudTimestamp
communication.HandleStream = make(chan string, 1)
communication.HandleUpload = make(chan string, 1)
communication.HandleHeartBeat = make(chan string, 1)
+1
View File
@@ -11,6 +11,7 @@ import (
type Communication struct {
PackageCounter *atomic.Value
LastPacketTimer *atomic.Value
CloudTimestamp *atomic.Value
HandleBootstrap chan string
HandleStream chan string
HandleMotion chan MotionDataPartial
+10 -1
View File
@@ -59,16 +59,25 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware, configuratio
// This will return the timestamp when the last packet was correctyl received
// this is to calculate if the camera connection is still working.
lastPacketReceived := int64(0)
if communication.LastPacketTimer != nil {
if communication.LastPacketTimer != nil && communication.LastPacketTimer.Load() != nil {
lastPacketReceived = communication.LastPacketTimer.Load().(int64)
}
// If an agent is properly setup with Kerberos Hub, we will send
// a ping to Kerberos Hub every 15seconds. On receiving a positive response
// it will update the CloudTimestamp value.
cloudTimestamp := int64(0)
if communication.CloudTimestamp != nil && communication.CloudTimestamp.Load() != nil {
cloudTimestamp = communication.CloudTimestamp.Load().(int64)
}
// The total number of recordings stored in the directory
numberOfRecordings := utils.NumberOfFilesInDirectory("./data/recordings")
c.JSON(200, gin.H{
"offlineMode": configuration.Config.Offline,
"cameraOnline": lastPacketReceived,
"cloudOnline": cloudTimestamp,
"numberOfRecordings": numberOfRecordings,
})
})
+5 -1
View File
@@ -27,12 +27,16 @@ class App extends React.Component {
const { dispatchGetDashboardInformation } = this.props;
dispatchGetDashboardInformation();
const interval$ = interval(2000);
const interval$ = interval(5000);
this.subscription = interval$.subscribe(() => {
dispatchGetDashboardInformation();
});
}
componentWillUnmount() {
this.subscription.unsubscribe();
}
render() {
const { children, username, dashboard, dispatchLogout } = this.props;
return (
+1 -1
View File
@@ -5,7 +5,7 @@
background: var(--upper-gradient);
width: 100%;
color: white;
padding: size(1) size(4);
padding: size(1.5) size(4);
margin: -6px 0 0 0;
display: flex;
align-items: center;
+4 -10
View File
@@ -61,16 +61,12 @@ class Dashboard extends React.Component {
// We check if a connection is made to Kerberos Hub, or if Offline mode
// has been turned on.
// let offlineMode = false;
const cloudOnline = this.getCurrentTimestamp() - dashboard.cloudOnline < 30;
let cloudConnection = 'Not connected';
if (dashboard.offlineMode === 'true') {
// offlineMode = true;
cloudConnection = 'Offline mode';
} else {
// TODO check if cloud connection is working
// ....
// offlineMode = true | false
// cloudConnection = "Not connected" | "Connected"
cloudConnection = cloudOnline ? 'Connected' : 'Not connected';
}
return (
@@ -100,9 +96,7 @@ class Dashboard extends React.Component {
/>
<Card
title="IP Camera"
subtitle={
isCameraOnline ? 'succesfully connected' : 'not connected'
}
subtitle={isCameraOnline ? 'Connected' : 'not connected'}
footer="Camera"
icon={isCameraOnline ? 'circle-check-big' : 'circle-cross-big'}
/>
@@ -110,7 +104,7 @@ class Dashboard extends React.Component {
title="Kerberos Hub"
subtitle={cloudConnection}
footer="Cloud"
icon="circle-cross-big"
icon={cloudOnline ? 'circle-check-big' : 'circle-cross-big'}
/>
</div>
<hr />