github.com/netdata/go.d.plugin@v0.58.1/modules/portcheck/charts.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package portcheck
     4  
     5  import (
     6  	"fmt"
     7  	"strconv"
     8  
     9  	"github.com/netdata/go.d.plugin/agent/module"
    10  )
    11  
    12  const (
    13  	prioCheckStatus = module.Priority + iota
    14  	prioCheckInStatusDuration
    15  	prioCheckLatency
    16  )
    17  
    18  var chartsTmpl = module.Charts{
    19  	checkStatusChartTmpl.Copy(),
    20  	checkInStateDurationChartTmpl.Copy(),
    21  	checkConnectionLatencyChartTmpl.Copy(),
    22  }
    23  
    24  var checkStatusChartTmpl = module.Chart{
    25  	ID:       "port_%d_status",
    26  	Title:    "TCP Check Status",
    27  	Units:    "boolean",
    28  	Fam:      "status",
    29  	Ctx:      "portcheck.status",
    30  	Priority: prioCheckStatus,
    31  	Dims: module.Dims{
    32  		{ID: "port_%d_success", Name: "success"},
    33  		{ID: "port_%d_failed", Name: "failed"},
    34  		{ID: "port_%d_timeout", Name: "timeout"},
    35  	},
    36  }
    37  
    38  var checkInStateDurationChartTmpl = module.Chart{
    39  	ID:       "port_%d_current_state_duration",
    40  	Title:    "Current State Duration",
    41  	Units:    "seconds",
    42  	Fam:      "status duration",
    43  	Ctx:      "portcheck.state_duration",
    44  	Priority: prioCheckInStatusDuration,
    45  	Dims: module.Dims{
    46  		{ID: "port_%d_current_state_duration", Name: "time"},
    47  	},
    48  }
    49  
    50  var checkConnectionLatencyChartTmpl = module.Chart{
    51  	ID:       "port_%d_connection_latency",
    52  	Title:    "TCP Connection Latency",
    53  	Units:    "ms",
    54  	Fam:      "latency",
    55  	Ctx:      "portcheck.latency",
    56  	Priority: prioCheckLatency,
    57  	Dims: module.Dims{
    58  		{ID: "port_%d_latency", Name: "time"},
    59  	},
    60  }
    61  
    62  func newPortCharts(host string, port int) *module.Charts {
    63  	charts := chartsTmpl.Copy()
    64  	for _, chart := range *charts {
    65  		chart.Labels = []module.Label{
    66  			{Key: "host", Value: host},
    67  			{Key: "port", Value: strconv.Itoa(port)},
    68  		}
    69  		chart.ID = fmt.Sprintf(chart.ID, port)
    70  		for _, dim := range chart.Dims {
    71  			dim.ID = fmt.Sprintf(dim.ID, port)
    72  		}
    73  	}
    74  	return charts
    75  }