Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/core/metrics/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type PerDimension struct {
Dimensions []*proto.Dimension
RunningSumMap map[string]float64
}

type MetricsHandler func(float64, int) float64

type Collections struct {
Expand Down Expand Up @@ -72,7 +73,7 @@ func GenerateMetricsReport(metricsCollections Collections) *proto.MetricsReport

return &proto.MetricsReport{
Meta: &proto.Metadata{},
Type: 0,
Type: proto.MetricsReport_SYSTEM,
Data: results,
}
}
Expand Down Expand Up @@ -315,17 +316,17 @@ func getAggregatedSimpleMetric(count int, internalMap map[string]float64) (simpl

for name, value := range internalMap {
if calculation, ok := calcFn[name]; ok {
aggegatedValue := calculation(value, count)
aggregatedValue := calculation(value, count)

// Only aggregate metrics when the aggregation method is defined
simpleMetrics = append(simpleMetrics, &proto.SimpleMetric{
Name: name,
Value: aggegatedValue,
Value: aggregatedValue,
})
} else {
for reg, calculation := range variableMetrics {
for reg, cal := range variableMetrics {
if reg.MatchString(name) {
result := calculation(value, count)
result := cal(value, count)

simpleMetrics = append(simpleMetrics, &proto.SimpleMetric{
Name: name,
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/advanced_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"time"

"github.com/gogo/protobuf/types"
log "github.com/sirupsen/logrus"

"github.com/nginx/agent/sdk/v2/proto"
"github.com/nginx/agent/v2/src/core"
"github.com/nginx/agent/v2/src/core/config"
"github.com/nginx/agent/v2/src/core/metrics"
advanced_metrics "github.com/nginx/agent/v2/src/extensions/advanced-metrics/pkg/advanced-metrics"
"github.com/nginx/agent/v2/src/extensions/advanced-metrics/pkg/publisher"
"github.com/nginx/agent/v2/src/extensions/advanced-metrics/pkg/schema"
log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -214,7 +215,9 @@ func (m *AdvancedMetrics) run() {
return
}
now := types.TimestampNow()
m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{toMetricReport(mr, now, commonDimensions)}))
if report := toMetricReport(mr, now, commonDimensions); len(report.Data) > 0 {
m.pipeline.Process(core.NewMessage(core.CommMetrics, []core.Payload{report}))
}
case <-m.pipeline.Context().Done():
return
}
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/metrics_throlling.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ func (r *MetricsThrottle) metricsReportGoroutine(ctx context.Context, wg *sync.W
return
case <-r.ticker.C:
aggregatedReport := r.getAggregatedReport()
r.messagePipeline.Process(
core.NewMessage(core.CommMetrics, []core.Payload{aggregatedReport}),
)
if len(aggregatedReport.Data) > 0 {
r.messagePipeline.Process(
core.NewMessage(core.CommMetrics, []core.Payload{aggregatedReport}),
)
}
if r.firstRun {
// for the first run, we added the staggering time in report cycle, reset it back to regular
r.ticker = time.NewTicker(r.conf.AgentMetrics.ReportInterval)
Expand Down