/
monitor.go
53 lines (44 loc) · 1.4 KB
/
monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
//go:build linux
// Package reorderer holds reorderer related files
package reorderer
import (
"context"
"sync"
"github.com/DataDog/datadog-go/v5/statsd"
"github.com/DataDog/datadog-agent/pkg/security/metrics"
)
// Monitor represents a reorderer monitor
type Monitor struct {
ctx context.Context
statsdClient statsd.ClientInterface
reOrderer *ReOrderer
}
// NewReOrderMonitor instantiates a new reorder statistics counter
func NewReOrderMonitor(ctx context.Context, statsdClient statsd.ClientInterface, reOrderer *ReOrderer) (*Monitor, error) {
return &Monitor{
ctx: ctx,
statsdClient: statsdClient,
reOrderer: reOrderer,
}, nil
}
// Start the reorderer monitor
func (r *Monitor) Start(wg *sync.WaitGroup) {
defer wg.Done()
for {
select {
case metric := <-r.reOrderer.Metrics:
_ = r.statsdClient.Gauge(metrics.MetricPerfBufferSortingQueueSize, float64(metric.QueueSize), []string{}, 1.0)
var avg float64
if metric.TotalOp > 0 {
avg = float64(metric.TotalDepth) / float64(metric.TotalOp)
}
_ = r.statsdClient.Gauge(metrics.MetricPerfBufferSortingAvgOp, avg, []string{}, 1.0)
case <-r.ctx.Done():
return
}
}
}