move metric processing to server
This commit is contained in:
parent
4912bcb9b1
commit
722d47e920
|
@ -13,6 +13,7 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
"github.com/status-im/status-go/wakuv2"
|
||||
|
@ -165,7 +166,7 @@ func NewClient(logger *zap.Logger, serverURL string, keyUID string, nodeName str
|
|||
promMetrics := NewPrometheusMetrics(client.processAndPushTelemetry, TelemetryRecord{NodeName: nodeName, PeerID: client.peerId, StatusVersion: version, DeviceType: client.deviceType})
|
||||
client.promMetrics = promMetrics
|
||||
|
||||
//client.promMetrics.Register("waku_connected_peers", GaugeType, nil, nil)
|
||||
client.promMetrics.Register("waku_connected_peers", GaugeType, nil)
|
||||
client.promMetrics.Register("waku2_envelopes_validated_total", CounterType, prometheus.Labels{})
|
||||
client.promMetrics.Register("waku_lightpush_messages", CounterType, prometheus.Labels{})
|
||||
client.promMetrics.Register("waku_lightpush_errors", CounterType, prometheus.Labels{})
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
prom_model "github.com/prometheus/client_model/go"
|
||||
)
|
||||
|
||||
type MetricType int
|
||||
|
@ -27,9 +28,8 @@ type TelemetryRecord struct {
|
|||
type ProcessTelemetryRequest func(ctx context.Context, data interface{})
|
||||
|
||||
type MetricPayload struct {
|
||||
Labels map[string]string
|
||||
Name string
|
||||
Value float64
|
||||
Value []*prom_model.Metric
|
||||
}
|
||||
|
||||
type Metric struct {
|
||||
|
@ -67,13 +67,18 @@ func (pm *PrometheusMetrics) Snapshot() {
|
|||
if !ok {
|
||||
continue
|
||||
}
|
||||
if len(mf.GetMetric()) == 0 {
|
||||
|
||||
metricFamilyValue := mf.GetMetric()
|
||||
|
||||
if len(metricFamilyValue) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
metricValue := []*prom_model.Metric{}
|
||||
|
||||
if metric.labels != nil { //filter out metrics based on labels
|
||||
for _, m := range mf.GetMetric() {
|
||||
var p MetricPayload
|
||||
if metric.labels != nil {
|
||||
|
||||
matchCnt := len(metric.labels)
|
||||
|
||||
for name, value := range metric.labels {
|
||||
|
@ -87,32 +92,22 @@ func (pm *PrometheusMetrics) Snapshot() {
|
|||
if matchCnt > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
metricValue = append(metricValue, m)
|
||||
|
||||
}
|
||||
} else {
|
||||
metricValue = metricFamilyValue
|
||||
}
|
||||
|
||||
labelMap := make(map[string]string)
|
||||
|
||||
for _, l := range m.GetLabel() {
|
||||
labelMap[*l.Name] = *l.Value
|
||||
if len(metricValue) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
switch metric.typ {
|
||||
case CounterType:
|
||||
p = MetricPayload{
|
||||
Name: *mf.Name,
|
||||
Value: *m.Counter.Value,
|
||||
Labels: labelMap,
|
||||
}
|
||||
case GaugeType:
|
||||
p = MetricPayload{
|
||||
Name: *mf.Name,
|
||||
Value: *m.Gauge.Value,
|
||||
Labels: labelMap,
|
||||
}
|
||||
}
|
||||
p := MetricPayload{Name: *mf.Name, Value: metricValue}
|
||||
|
||||
pm.ToTelemetryRequest(p)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -120,7 +115,6 @@ func (pm *PrometheusMetrics) ToTelemetryRequest(p MetricPayload) error {
|
|||
postBody := map[string]interface{}{
|
||||
"value": p.Value,
|
||||
"name": p.Name,
|
||||
"labels": p.Labels,
|
||||
"nodeName": pm.telemetryRecord.NodeName,
|
||||
"deviceType": pm.telemetryRecord.DeviceType,
|
||||
"peerId": pm.telemetryRecord.PeerID,
|
||||
|
|
Loading…
Reference in New Issue