Skip to content
Snippets Groups Projects
Unverified Commit e68d3f27 authored by Levente Pap's avatar Levente Pap
Browse files

Prometheus clients info

parent d72ebb6a
Branches
No related tags found
No related merge requests found
package metrics package metrics
import ( import (
"bytes"
"encoding/gob"
"sync" "sync"
"github.com/iotaledger/goshimmer/plugins/analysis/packet" "github.com/iotaledger/goshimmer/plugins/analysis/packet"
...@@ -35,23 +33,15 @@ var onMetricHeartbeatReceived = events.NewClosure(func(hb *packet.MetricHeartbea ...@@ -35,23 +33,15 @@ var onMetricHeartbeatReceived = events.NewClosure(func(hb *packet.MetricHeartbea
} }
}) })
// ClientsMetrics returns info about the OS, arch, number of cpu cores, cpu load and memory usage.
func ClientsMetrics() map[string]ClientInfo { func ClientsMetrics() map[string]ClientInfo {
clientsMetricsMutex.RLock() clientsMetricsMutex.RLock()
defer clientsMetricsMutex.RUnlock() defer clientsMetricsMutex.RUnlock()
// create copy of the map
var buf bytes.Buffer var copy = make(map[string]ClientInfo)
enc := gob.NewEncoder(&buf) // manually copy content
err := enc.Encode(clientsMetrics) for node, clientInfo := range clientsMetrics {
if err != nil { copy[node] = clientInfo
return nil
}
dec := gob.NewDecoder(&buf)
var copy map[string]ClientInfo
err = dec.Decode(&copy)
if err != nil {
return nil
} }
return copy return copy
} }
package prometheus package prometheus
import ( import (
"strconv"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
var ( var (
clientsInfo *prometheus.GaugeVec clientsInfoCPU *prometheus.GaugeVec
clientsInfoMemory *prometheus.GaugeVec
) )
func registerClientsMetrics() { func registerClientsMetrics() {
clientsInfo = prometheus.NewGaugeVec( clientsInfoCPU = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Name: "clients_info", Name: "clients_info_cpu",
Help: "Clients info.", Help: "Info about client's cpu load labeled with nodeID, OS, ARCH and number of cpu cores",
},
[]string{
"nodeID",
"OS",
"ARCH",
"NUM_CPU",
}, },
[]string{"info"},
// []string{"OS", "ARCH", "NUM_CPU", "CPU_USAGE", "MEM_USAGE"},
) )
// registry.MustRegister(clientsInfo) clientsInfoMemory = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "clients_info_mem",
Help: "Info about client's memory usage labeled with nodeID, OS, ARCH and number of cpu cores",
},
[]string{
"nodeID",
"OS",
"ARCH",
"NUM_CPU",
},
)
// collectClientsInfo() registry.MustRegister(clientsInfoCPU)
registry.MustRegister(clientsInfoMemory)
// clientsInfo.WithLabelValues(banner.AppName, banner.AppVersion).Set(1) addCollect(collectClientsInfo)
} }
func collectClientsInfo() { func collectClientsInfo() {
// for ID, info := range metrics.ClientsMetrics() { clientInfoMap := metrics.ClientsMetrics()
// clientsInfo.WithLabelValues()
// }
for nodeID, clientInfo := range clientInfoMap {
clientsInfoCPU.WithLabelValues(
nodeID,
clientInfo.OS,
clientInfo.Arch,
strconv.Itoa(clientInfo.NumCPU),
).Set(clientInfo.CPUUsage)
clientsInfoMemory.WithLabelValues(
nodeID,
clientInfo.OS,
clientInfo.Arch,
strconv.Itoa(clientInfo.NumCPU),
).Set(float64(clientInfo.MemoryUsage))
}
} }
...@@ -10,7 +10,7 @@ require ( ...@@ -10,7 +10,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect
github.com/drand/drand v0.8.1 github.com/drand/drand v0.8.1
github.com/iotaledger/goshimmer v0.1.3 github.com/iotaledger/goshimmer v0.1.3
github.com/iotaledger/hive.go v0.0.0-20200615181744-3ab0cddc15cf github.com/iotaledger/hive.go v0.0.0-20200617164933-c48b4401b814
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/stretchr/testify v1.5.1 github.com/stretchr/testify v1.5.1
) )
......
...@@ -149,6 +149,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt ...@@ -149,6 +149,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/iotaledger/hive.go v0.0.0-20200610104211-d603429af242 h1:uHMFmfrP6O6lp1lCHT6lpFwHFWYk77V0nUlGbhneQHI= github.com/iotaledger/hive.go v0.0.0-20200610104211-d603429af242 h1:uHMFmfrP6O6lp1lCHT6lpFwHFWYk77V0nUlGbhneQHI=
github.com/iotaledger/hive.go v0.0.0-20200610104211-d603429af242/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU= github.com/iotaledger/hive.go v0.0.0-20200610104211-d603429af242/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU=
github.com/iotaledger/hive.go v0.0.0-20200615181744-3ab0cddc15cf/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU= github.com/iotaledger/hive.go v0.0.0-20200615181744-3ab0cddc15cf/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU=
github.com/iotaledger/hive.go v0.0.0-20200617164933-c48b4401b814/go.mod h1:zwZhaE4ZeglpTrbmbwdnVPMI5XdRu2RmByi3Qn0ztmU=
github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment