Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat(httpcheck): add 'url' label to charts (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Nov 23, 2022
1 parent d931ae4 commit f370f1d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/httpcheck/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
prioResponseInStatusDuration
)

var charts = module.Charts{
var httpCheckCharts = module.Charts{
responseTimeChart.Copy(),
responseLengthChart.Copy(),
responseStatusChart.Copy(),
Expand Down
6 changes: 5 additions & 1 deletion modules/httpcheck/httpcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type (
Config `yaml:",inline"`
UpdateEvery int `yaml:"update_every"`

charts *module.Charts

acceptedStatuses map[int]bool
reResponse *regexp.Regexp
client client
Expand All @@ -63,6 +65,8 @@ func (hc *HTTPCheck) Init() bool {
return false
}

hc.charts = hc.initCharts()

httpClient, err := hc.initHTTPClient()
if err != nil {
hc.Errorf("init HTTP client: %v", err)
Expand Down Expand Up @@ -96,7 +100,7 @@ func (hc *HTTPCheck) Check() bool {
}

func (hc *HTTPCheck) Charts() *module.Charts {
return charts.Copy()
return hc.charts
}

func (hc *HTTPCheck) Collect() map[string]int64 {
Expand Down
5 changes: 4 additions & 1 deletion modules/httpcheck/httpcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func TestHTTPCheck_Check(t *testing.T) {
}

func TestHTTPCheck_Charts(t *testing.T) {
assert.NotNil(t, New().Charts())
job := New()
job.URL = testURL
require.True(t, job.Init())
assert.NotNil(t, job.Charts())
}

func TestHTTPCheck_Collect(t *testing.T) {
Expand Down
16 changes: 15 additions & 1 deletion modules/httpcheck/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package httpcheck

import (
"errors"
"github.com/netdata/go.d.plugin/pkg/web"
"net/http"
"regexp"

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

func (hc *HTTPCheck) validateConfig() error {
Expand All @@ -26,3 +28,15 @@ func (hc *HTTPCheck) initResponseMatchRegexp() (*regexp.Regexp, error) {
}
return regexp.Compile(hc.ResponseMatch)
}

func (hc *HTTPCheck) initCharts() *module.Charts {
charts := httpCheckCharts.Copy()

for _, chart := range *charts {
chart.Labels = []module.Label{
{Key: "url", Value: hc.URL},
}
}

return charts
}

0 comments on commit f370f1d

Please sign in to comment.