Send all metrics with same time stamp

calcGlobalMetrics does only computiation, counter measurement is done before
This commit is contained in:
Holger Obermaier 2023-09-12 10:45:50 +02:00
parent 302e42d1d0
commit 674e78b3d0

View File

@ -554,14 +554,16 @@ func (m *LikwidCollector) calcEventsetMetrics(evset LikwidEventsetConfig, interv
// Now we have the result, send it with the proper tags // Now we have the result, send it with the proper tags
if !math.IsNaN(value) && metric.Publish { if !math.IsNaN(value) && metric.Publish {
fields := map[string]interface{}{"value": value} fields := map[string]interface{}{"value": value}
y, err := lp.New( y, err :=
lp.New(
metric.Name, metric.Name,
map[string]string{ map[string]string{
"type": metric.Type, "type": metric.Type,
}, },
m.meta, m.meta,
fields, fields,
now) now,
)
if err == nil { if err == nil {
if metric.Type != "node" { if metric.Type != "node" {
y.AddTag("type-id", fmt.Sprintf("%d", domain)) y.AddTag("type-id", fmt.Sprintf("%d", domain))
@ -589,7 +591,8 @@ func (m *LikwidCollector) calcEventsetMetrics(evset LikwidEventsetConfig, interv
} }
for coreID, value := range totalCoreValues { for coreID, value := range totalCoreValues {
y, err := lp.New( y, err :=
lp.New(
metric.Name, metric.Name,
map[string]string{ map[string]string{
"type": "core", "type": "core",
@ -625,7 +628,8 @@ func (m *LikwidCollector) calcEventsetMetrics(evset LikwidEventsetConfig, interv
} }
for socketID, value := range totalSocketValues { for socketID, value := range totalSocketValues {
y, err := lp.New( y, err :=
lp.New(
metric.Name, metric.Name,
map[string]string{ map[string]string{
"type": "socket", "type": "socket",
@ -659,7 +663,8 @@ func (m *LikwidCollector) calcEventsetMetrics(evset LikwidEventsetConfig, interv
} }
} }
y, err := lp.New( y, err :=
lp.New(
metric.Name, metric.Name,
map[string]string{ map[string]string{
"type": "node", "type": "node",
@ -685,7 +690,13 @@ func (m *LikwidCollector) calcEventsetMetrics(evset LikwidEventsetConfig, interv
// Go over the global metrics, derive the value out of the event sets' metric values and send it // Go over the global metrics, derive the value out of the event sets' metric values and send it
func (m *LikwidCollector) calcGlobalMetrics(groups []LikwidEventsetConfig, interval time.Duration, output chan lp.CCMetric) error { func (m *LikwidCollector) calcGlobalMetrics(groups []LikwidEventsetConfig, interval time.Duration, output chan lp.CCMetric) error {
// Send all metrics with same time stamp
// This function does only computiation, counter measurement is done before
now := time.Now()
for _, metric := range m.config.Metrics { for _, metric := range m.config.Metrics {
// The metric scope is determined in the Init() function
// Get the map scope-id -> tids
scopemap := m.cpu2tid scopemap := m.cpu2tid
if metric.Type == "socket" { if metric.Type == "socket" {
scopemap = m.sock2tid scopemap = m.sock2tid
@ -712,9 +723,18 @@ func (m *LikwidCollector) calcGlobalMetrics(groups []LikwidEventsetConfig, inter
// Now we have the result, send it with the proper tags // Now we have the result, send it with the proper tags
if !math.IsNaN(value) { if !math.IsNaN(value) {
if metric.Publish { if metric.Publish {
tags := map[string]string{"type": metric.Type} y, err :=
fields := map[string]interface{}{"value": value} lp.New(
y, err := lp.New(metric.Name, tags, m.meta, fields, time.Now()) metric.Name,
map[string]string{
"type": metric.Type,
},
m.meta,
map[string]interface{}{
"value": value,
},
now,
)
if err == nil { if err == nil {
if metric.Type != "node" { if metric.Type != "node" {
y.AddTag("type-id", fmt.Sprintf("%d", domain)) y.AddTag("type-id", fmt.Sprintf("%d", domain))