-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
status.go
66 lines (51 loc) · 1.53 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
// 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-present Datadog, Inc.
package net
import (
"embed"
"expvar"
"io"
"strconv"
"github.com/DataDog/datadog-agent/comp/core/status"
)
//go:embed status_templates
var templatesFS embed.FS
// Provider provides the functionality to populate the status output
type Provider struct{}
// Name returns the name
func (Provider) Name() string {
return "Clocks"
}
// Index return the index
func (Provider) Index() int {
return 2
}
func (p Provider) getStatusInfo() map[string]interface{} {
stats := make(map[string]interface{})
p.populateStatus(stats)
return stats
}
func (Provider) populateStatus(stats map[string]interface{}) {
ntpOffset := expvar.Get("ntpOffset")
if ntpOffset != nil && ntpOffset.String() != "" {
float, err := strconv.ParseFloat(expvar.Get("ntpOffset").String(), 64)
if err == nil {
stats["ntpOffset"] = float
}
}
}
// JSON populates the status map
func (p Provider) JSON(_ bool, stats map[string]interface{}) error {
p.populateStatus(stats)
return nil
}
// Text renders the text output
func (p Provider) Text(_ bool, buffer io.Writer) error {
return status.RenderText(templatesFS, "ntp.tmpl", buffer, p.getStatusInfo())
}
// HTML renders the html output
func (p Provider) HTML(_ bool, buffer io.Writer) error {
return status.RenderHTML(templatesFS, "ntpHTML.tmpl", buffer, p.getStatusInfo())
}