Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
1eab0c24
Commit
1eab0c24
authored
5 years ago
by
jkrvivian
Browse files
Options
Downloads
Patches
Plain Diff
feat: Add node status on dashboard
parent
b3f3ae19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/dashboard/tps.go
+67
-0
67 additions, 0 deletions
plugins/dashboard/tps.go
plugins/dashboard/tps_template.go
+32
-8
32 additions, 8 deletions
plugins/dashboard/tps_template.go
with
99 additions
and
8 deletions
plugins/dashboard/tps.go
+
67
−
0
View file @
1eab0c24
...
...
@@ -2,16 +2,26 @@ package dashboard
import
(
"encoding/binary"
"fmt"
"html/template"
"math"
"net/http"
"sync"
"strconv"
"time"
"github.com/gorilla/websocket"
"github.com/iotaledger/goshimmer/packages/accountability"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood"
)
var
(
start
=
time
.
Now
()
homeTempl
,
templ_err
=
template
.
New
(
"dashboard"
)
.
Parse
(
tpsTemplate
)
upgrader
=
websocket
.
Upgrader
{
ReadBufferSize
:
1024
,
...
...
@@ -19,6 +29,57 @@ var (
}
)
type
Status
struct
{
Id
string
`json:"Id"`
Neighbor
string
`json:"Neighbor"`
KnownPeer
string
`json:"KnownPeer"`
Uptime
string
`json:"Uptime"`
}
func
GetStatus
()
*
Status
{
// Get Uptime
duration
:=
time
.
Since
(
start
)
padded
:=
false
uptime
:=
fmt
.
Sprintf
(
"Uptime: "
)
if
int
(
duration
.
Seconds
())
/
(
60
*
60
*
24
)
>
0
{
days
:=
int
(
duration
.
Hours
())
/
24
numberLength
:=
int
(
math
.
Log10
(
float64
(
days
)))
+
1
padLength
:=
31
-
numberLength
uptime
+=
fmt
.
Sprintf
(
"%*v"
,
padLength
,
""
)
uptime
+=
fmt
.
Sprintf
(
"%02dd "
,
days
)
}
if
int
(
duration
.
Seconds
())
/
(
60
*
60
)
>
0
{
if
!
padded
{
uptime
+=
fmt
.
Sprintf
(
"%29v"
,
""
)
padded
=
true
}
uptime
+=
fmt
.
Sprintf
(
"%02dh "
,
int
(
duration
.
Hours
())
%
24
)
}
if
int
(
duration
.
Seconds
())
/
60
>
0
{
if
!
padded
{
uptime
+=
fmt
.
Sprintf
(
"%33v"
,
""
)
padded
=
true
}
uptime
+=
fmt
.
Sprintf
(
"%02dm "
,
int
(
duration
.
Minutes
())
%
60
)
}
if
!
padded
{
uptime
+=
fmt
.
Sprintf
(
"%37v"
,
""
)
}
uptime
+=
fmt
.
Sprintf
(
"%02ds "
,
int
(
duration
.
Seconds
())
%
60
)
return
&
Status
{
Id
:
accountability
.
OwnId
()
.
StringIdentifier
,
Neighbor
:
"Neighbors: "
+
strconv
.
Itoa
(
chosenneighbors
.
INSTANCE
.
Peers
.
Len
())
+
" chosen / "
+
strconv
.
Itoa
(
acceptedneighbors
.
INSTANCE
.
Peers
.
Len
())
+
" accepted / "
+
strconv
.
Itoa
(
chosenneighbors
.
INSTANCE
.
Peers
.
Len
()
+
acceptedneighbors
.
INSTANCE
.
Peers
.
Len
())
+
" total"
,
KnownPeer
:
"Known Peers: "
+
strconv
.
Itoa
(
knownpeers
.
INSTANCE
.
Peers
.
Len
())
+
" total / "
+
strconv
.
Itoa
(
neighborhood
.
INSTANCE
.
Peers
.
Len
())
+
" neighborhood"
,
Uptime
:
uptime
,
}
}
// ServeWs websocket
func
ServeWs
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ws
,
err
:=
upgrader
.
Upgrade
(
w
,
r
,
nil
)
...
...
@@ -38,6 +99,12 @@ func ServeWs(w http.ResponseWriter, r *http.Request) {
if
err
:=
ws
.
WriteMessage
(
websocket
.
BinaryMessage
,
p
);
err
!=
nil
{
return
}
// write node status message
status
:=
GetStatus
()
if
err
:=
ws
.
WriteJSON
(
status
);
err
!=
nil
{
return
}
}()
})
...
...
This diff is collapsed.
Click to expand it.
plugins/dashboard/tps_template.go
+
32
−
8
View file @
1eab0c24
...
...
@@ -9,10 +9,16 @@ var tpsTemplate = `
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>
<div id="container" style="height: 400px; min-width: 310px"></div>
</head>
<body>
<div id="node-status" style="min-width:310px">
<h3 id="node-id"></h3>
<h3 id="node-neighbor"></h3>
<h3 id="node-knownpeer"></h3>
<h3 id="node-uptime"></h3>
</div>
<div id="container" style="height: 400px; min-width: 310px"></div>
<script>
Highcharts.createElement('link', {
href: 'https://fonts.googleapis.com/css?family=Unica+One',
...
...
@@ -306,14 +312,32 @@ var tpsTemplate = `
// console.log('Connection closed');
}
conn.onmessage = evt => {
console.log('metric updated');
const data = evt.data;
const dv = new DataView(data);
// var value = dv.getUint32(4, true) << 32 | dv.getUint32(0, true);
const value = dv.getUint32(0, true);
chart.series[0].addPoint([time += 1000, value], true); //((counter += 1) % update_rate == 4));
console.log(value);
console.log(dv);
if(isJSON(data)) {
console.log('status updated');
var res = JSON.parse(data);
$("#node-id").html("Node ID: " + res.Id);
$("#node-neighbor").html(res.Neighbor);
$("#node-knownpeer").html(res.KnownPeer);
$("#node-uptime").html(res.Uptime);
} else {
console.log('metric updated');
const dv = new DataView(data);
// var value = dv.getUint32(4, true) << 32 | dv.getUint32(0, true);
const value = dv.getUint32(0, true);
chart.series[0].addPoint([time += 1000, value], true); //((counter += 1) % update_rate == 4));
console.log(value);
console.log(dv);
}
}
function isJSON(str) {
try {
JSON.parse(str);
} catch(e) {
return false;
}
return true;
}
</script>
</body>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment