/
status.go
74 lines (58 loc) · 2.07 KB
/
status.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 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 2023-present Datadog, Inc.
// Package demultiplexerimpl defines the aggregator demultiplexer
package demultiplexerimpl
import (
"embed"
"encoding/json"
"expvar"
"io"
checkstats "github.com/DataDog/datadog-agent/pkg/collector/check/stats"
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/status"
)
//go:embed status_templates
var templatesFS embed.FS
type demultiplexerStatus struct {
Log log.Component
}
func (d demultiplexerStatus) getStatusInfo() map[string]interface{} {
stats := make(map[string]interface{})
d.populateStatus(stats)
return stats
}
func (d demultiplexerStatus) populateStatus(stats map[string]interface{}) {
aggregatorStatsJSON := []byte(expvar.Get("aggregator").String())
aggregatorStats := make(map[string]interface{})
json.Unmarshal(aggregatorStatsJSON, &aggregatorStats) //nolint:errcheck
stats["aggregatorStats"] = aggregatorStats
s, err := checkstats.TranslateEventPlatformEventTypes(stats["aggregatorStats"])
if err != nil {
d.Log.Debugf("failed to translate event platform event types in aggregatorStats: %s", err.Error())
} else {
stats["aggregatorStats"] = s
}
}
// Name returns the name
func (d demultiplexerStatus) Name() string {
return "Aggregator"
}
// Section return the section
func (d demultiplexerStatus) Section() string {
return "aggregator"
}
// JSON populates the status map
func (d demultiplexerStatus) JSON(_ bool, stats map[string]interface{}) error {
d.populateStatus(stats)
return nil
}
// Text renders the text output
func (d demultiplexerStatus) Text(_ bool, buffer io.Writer) error {
return status.RenderText(templatesFS, "aggregator.tmpl", buffer, d.getStatusInfo())
}
// HTML renders the html output
func (d demultiplexerStatus) HTML(_ bool, buffer io.Writer) error {
return status.RenderHTML(templatesFS, "aggregatorHTML.tmpl", buffer, d.getStatusInfo())
}