summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/portcheck/charts.go
blob: 6b88f7a8f7f0706e3b0a634b218feafc7ad6cd7e (plain)
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
75
// SPDX-License-Identifier: GPL-3.0-or-later

package portcheck

import (
	"fmt"
	"strconv"

	"github.com/netdata/netdata/go/go.d.plugin/agent/module"
)

const (
	prioCheckStatus = module.Priority + iota
	prioCheckInStatusDuration
	prioCheckLatency
)

var chartsTmpl = module.Charts{
	checkStatusChartTmpl.Copy(),
	checkInStateDurationChartTmpl.Copy(),
	checkConnectionLatencyChartTmpl.Copy(),
}

var checkStatusChartTmpl = module.Chart{
	ID:       "port_%d_status",
	Title:    "TCP Check Status",
	Units:    "boolean",
	Fam:      "status",
	Ctx:      "portcheck.status",
	Priority: prioCheckStatus,
	Dims: module.Dims{
		{ID: "port_%d_success", Name: "success"},
		{ID: "port_%d_failed", Name: "failed"},
		{ID: "port_%d_timeout", Name: "timeout"},
	},
}

var checkInStateDurationChartTmpl = module.Chart{
	ID:       "port_%d_current_state_duration",
	Title:    "Current State Duration",
	Units:    "seconds",
	Fam:      "status duration",
	Ctx:      "portcheck.state_duration",
	Priority: prioCheckInStatusDuration,
	Dims: module.Dims{
		{ID: "port_%d_current_state_duration", Name: "time"},
	},
}

var checkConnectionLatencyChartTmpl = module.Chart{
	ID:       "port_%d_connection_latency",
	Title:    "TCP Connection Latency",
	Units:    "ms",
	Fam:      "latency",
	Ctx:      "portcheck.latency",
	Priority: prioCheckLatency,
	Dims: module.Dims{
		{ID: "port_%d_latency", Name: "time"},
	},
}

func newPortCharts(host string, port int) *module.Charts {
	charts := chartsTmpl.Copy()
	for _, chart := range *charts {
		chart.Labels = []module.Label{
			{Key: "host", Value: host},
			{Key: "port", Value: strconv.Itoa(port)},
		}
		chart.ID = fmt.Sprintf(chart.ID, port)
		for _, dim := range chart.Dims {
			dim.ID = fmt.Sprintf(dim.ID, port)
		}
	}
	return charts
}