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

Prometheus clients info

parent d72ebb6a
No related branches found
No related tags found
No related merge requests found
package metrics
import (
"bytes"
"encoding/gob"
"sync"
"github.com/iotaledger/goshimmer/plugins/analysis/packet"
......@@ -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 {
clientsMetricsMutex.RLock()
defer clientsMetricsMutex.RUnlock()
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(clientsMetrics)
if err != nil {
return nil
}
dec := gob.NewDecoder(&buf)
var copy map[string]ClientInfo
err = dec.Decode(&copy)
if err != nil {
return nil
// create copy of the map
var copy = make(map[string]ClientInfo)
// manually copy content
for node, clientInfo := range clientsMetrics {
copy[node] = clientInfo
}
return copy
}
package prometheus
import (
"strconv"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
clientsInfo *prometheus.GaugeVec
clientsInfoCPU *prometheus.GaugeVec
clientsInfoMemory *prometheus.GaugeVec
)
func registerClientsMetrics() {
clientsInfo = prometheus.NewGaugeVec(
clientsInfoCPU = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "clients_info",
Help: "Clients info.",
Name: "clients_info_cpu",
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() {
// for ID, info := range metrics.ClientsMetrics() {
// clientsInfo.WithLabelValues()
// }
clientInfoMap := metrics.ClientsMetrics()
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 (
github.com/docker/go-units v0.4.0 // indirect
github.com/drand/drand v0.8.1
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/stretchr/testify v1.5.1
)
......
......@@ -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/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.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
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.
Finish editing this message first!
Please register or to comment