forked from iotaledger/goshimmer
/
scheduler.go
48 lines (39 loc) · 1.43 KB
/
scheduler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package remotemetrics
import (
"time"
"github.com/izuc/zipp/packages/core/mesh_old"
"github.com/izuc/zipp/packages/app/remotemetrics"
)
func obtainSchedulerStats(timestamp time.Time) {
scheduler := deps.Mesh.Scheduler
queueMap, aManaNormalizedMap := prepQueueMaps(scheduler)
var myID string
if deps.Local != nil {
myID = deps.Local.Identity.ID().String()
}
record := remotemetrics.SchedulerMetrics{
Type: "schedulerSample",
NodeID: myID,
Synced: deps.Mesh.Synced(),
MetricsLevel: Parameters.MetricsLevel,
BufferSize: uint32(scheduler.BufferSize()),
BufferLength: uint32(scheduler.TotalBlocksCount()),
ReadyBlocksInBuffer: uint32(scheduler.ReadyBlocksCount()),
QueueLengthPerNode: queueMap,
AManaNormalizedLengthPerNode: aManaNormalizedMap,
Timestamp: timestamp,
}
_ = deps.RemoteLogger.Send(record)
}
func prepQueueMaps(s *mesh_old.Scheduler) (queueMap map[string]uint32, aManaNormalizedMap map[string]float64) {
queueSizes := s.NodeQueueSizes()
queueMap = make(map[string]uint32, len(queueSizes))
aManaNormalizedMap = make(map[string]float64, len(queueSizes))
for id, size := range queueSizes {
nodeID := id.String()
aMana := s.GetManaFromCache(id)
queueMap[nodeID] = uint32(size)
aManaNormalizedMap[nodeID] = float64(size) / float64(aMana)
}
return
}