Update On Fri Jun 7 01:07:23 CEST 2024

This commit is contained in:
github-action[bot]
2024-06-07 01:07:23 +02:00
parent 4f1b1f52e1
commit 4a8fb7903d
1383 changed files with 36790 additions and 15275 deletions

View File

@@ -1,4 +1,4 @@
package node_metric
package metric_reader
import (
"context"
@@ -10,6 +10,7 @@ import (
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"go.uber.org/zap"
)
type Reader interface {
@@ -30,6 +31,27 @@ func NewReader(metricsURL string) *readerImpl {
}
}
func (b *readerImpl) parsePingInfo(metricMap map[string]*dto.MetricFamily, nm *NodeMetrics) error {
metric, ok := metricMap["ehco_ping_response_duration_seconds"]
if !ok {
// this metric is optional when enable_ping = false
zap.S().Warn("ping metric not found")
return nil
}
for _, m := range metric.Metric {
g := m.GetHistogram()
ip := ""
val := float64(g.GetSampleSum()) / float64(g.GetSampleCount()) * 1000 // to ms
for _, label := range m.GetLabel() {
if label.GetName() == "ip" {
ip = label.GetValue()
}
}
nm.PingMetrics = append(nm.PingMetrics, PingMetric{Latency: val, Target: ip})
}
return nil
}
func (b *readerImpl) parseCpuInfo(metricMap map[string]*dto.MetricFamily, nm *NodeMetrics) error {
handleMetric := func(metricName string, handleValue func(float64, string)) error {
metric, ok := metricMap[metricName]
@@ -250,8 +272,7 @@ func (b *readerImpl) ReadOnce(ctx context.Context) (*NodeMetrics, error) {
if err != nil {
return nil, err
}
nm := &NodeMetrics{syncTime: time.Now()}
nm := &NodeMetrics{syncTime: time.Now(), PingMetrics: []PingMetric{}}
if err := b.parseCpuInfo(parsed, nm); err != nil {
return nil, err
}
@@ -264,6 +285,10 @@ func (b *readerImpl) ReadOnce(ctx context.Context) (*NodeMetrics, error) {
if err := b.parseNetworkInfo(parsed, nm); err != nil {
return nil, err
}
if err := b.parsePingInfo(parsed, nm); err != nil {
return nil, err
}
b.lastMetrics = nm
return nm, nil
}

View File

@@ -1,6 +1,8 @@
package node_metric
package metric_reader
import "time"
import (
"time"
)
type NodeMetrics struct {
// cpu
@@ -24,5 +26,13 @@ type NodeMetrics struct {
NetworkReceiveBytesRate float64 `json:"network_receive_bytes_rate"`
NetworkTransmitBytesRate float64 `json:"network_transmit_bytes_rate"`
// ping
PingMetrics []PingMetric `json:"ping_metrics"`
syncTime time.Time
}
type PingMetric struct {
Latency float64 `json:"latency"` // in ms
Target string `json:"target"`
}

View File

@@ -1,4 +1,4 @@
package node_metric
package metric_reader
import "regexp"