Newer
Older
Angelo Capossele
committed
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package prometheus
import (
"strconv"
metricspkg "github.com/iotaledger/goshimmer/packages/metrics"
"github.com/iotaledger/goshimmer/packages/vote"
analysisdashboard "github.com/iotaledger/goshimmer/plugins/analysis/dashboard"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/iotaledger/hive.go/events"
"github.com/prometheus/client_golang/prometheus"
)
const (
like = "LIKE"
dislike = "DISLIKE"
)
// These metrics store information collected via the analysis server.
var (
// Process related metrics.
nodesInfoCPU *prometheus.GaugeVec
nodesInfoMemory *prometheus.GaugeVec
// Autopeering related metrics.
nodesNeighborCount *prometheus.GaugeVec
networkDiameter prometheus.Gauge
// FPC related metrics.
conflictCount *prometheus.GaugeVec
conflictFinalizationRounds *prometheus.GaugeVec
conflictOutcome *prometheus.GaugeVec
conflictInitialOpinion *prometheus.GaugeVec
)
var onFPCFinalized = events.NewClosure(func(ev *metricspkg.AnalysisFPCFinalizedEvent) {
conflictCount.WithLabelValues(
ev.NodeID,
).Add(1)
conflictFinalizationRounds.WithLabelValues(
ev.ConflictID,
ev.NodeID,
).Set(float64(ev.Rounds + 1))
conflictOutcome.WithLabelValues(
ev.ConflictID,
ev.NodeID,
opinionToString(ev.Outcome),
).Set(1)
conflictInitialOpinion.WithLabelValues(
ev.ConflictID,
ev.NodeID,
opinionToString(ev.Opinions[0]),
).Set(1)
})
func registerClientsMetrics() {
nodesInfoCPU = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_nodes_info_cpu",
Help: "Info about node's cpu load labeled with nodeID, OS, ARCH and number of cpu cores",
},
[]string{
"nodeID",
"OS",
"ARCH",
"NUM_CPU",
},
)
nodesInfoMemory = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_nodes_info_mem",
Help: "Info about node's memory usage labeled with nodeID, OS, ARCH and number of cpu cores",
},
[]string{
"nodeID",
"OS",
"ARCH",
"NUM_CPU",
},
)
nodesNeighborCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_nodes_neighbor_count",
Help: "Info about node's neighbors count",
},
[]string{
"nodeID",
"direction",
},
)
networkDiameter = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "global_network_diameter",
Help: "Autopeering network diameter",
})
conflictCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_conflict_count",
Help: "Conflicts count labeled with nodeID",
},
[]string{
"nodeID",
},
)
conflictFinalizationRounds = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_conflict_finalization_rounds",
Help: "Number of rounds to finalize a given conflict labeled with conflictID and nodeID",
},
[]string{
"conflictID",
"nodeID",
},
)
conflictInitialOpinion = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_conflict_initial_opinion",
Help: "Initial opinion of a given conflict labeled with conflictID, nodeID and opinion",
},
[]string{
"conflictID",
"nodeID",
"opinion",
},
)
conflictOutcome = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "global_conflict_outcome",
Help: "Outcome of a given conflict labeled with conflictID, nodeID and opinion",
},
[]string{
"conflictID",
"nodeID",
"opinion",
},
)
registry.MustRegister(nodesInfoCPU)
registry.MustRegister(nodesInfoMemory)
registry.MustRegister(nodesNeighborCount)
registry.MustRegister(networkDiameter)
registry.MustRegister(conflictCount)
registry.MustRegister(conflictFinalizationRounds)
registry.MustRegister(conflictInitialOpinion)
registry.MustRegister(conflictOutcome)
metricspkg.Events().AnalysisFPCFinalized.Attach(onFPCFinalized)
addCollect(collectNodesInfo)
}
func collectNodesInfo() {
nodeInfoMap := metrics.NodesMetrics()
for nodeID, nodeMetrics := range nodeInfoMap {
nodesInfoCPU.WithLabelValues(
nodeID,
nodeMetrics.OS,
nodeMetrics.Arch,
strconv.Itoa(nodeMetrics.NumCPU),
).Set(nodeMetrics.CPUUsage)
nodesInfoMemory.WithLabelValues(
nodeID,
nodeMetrics.OS,
nodeMetrics.Arch,
strconv.Itoa(nodeMetrics.NumCPU),
).Set(float64(nodeMetrics.MemoryUsage))
}
for nodeID, neighborCount := range analysisdashboard.NumOfNeighbors() {
nodesNeighborCount.WithLabelValues(nodeID, "in").Set(float64(neighborCount.Inbound))
nodesNeighborCount.WithLabelValues(nodeID, "out").Set(float64(neighborCount.Outbound))
}
networkDiameter.Set(float64(metrics.NetworkDiameter()))
}
func opinionToString(opinion vote.Opinion) string {
if opinion == vote.Like {
return like
}
return dislike
}