From 87d772a7d708fec12f48cd8adc0dedff6e1025da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 26 Aug 2024 10:15:20 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- .../go.d.plugin/modules/dnsdist/collect.go | 74 ---------------------- 1 file changed, 74 deletions(-) delete mode 100644 src/go/collectors/go.d.plugin/modules/dnsdist/collect.go (limited to 'src/go/collectors/go.d.plugin/modules/dnsdist/collect.go') diff --git a/src/go/collectors/go.d.plugin/modules/dnsdist/collect.go b/src/go/collectors/go.d.plugin/modules/dnsdist/collect.go deleted file mode 100644 index 650757479..000000000 --- a/src/go/collectors/go.d.plugin/modules/dnsdist/collect.go +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later - -package dnsdist - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - - "github.com/netdata/netdata/go/go.d.plugin/pkg/stm" - "github.com/netdata/netdata/go/go.d.plugin/pkg/web" -) - -const ( - urlPathJSONStat = "/jsonstat" -) - -func (d *DNSdist) collect() (map[string]int64, error) { - statistics, err := d.scrapeStatistics() - if err != nil { - return nil, err - } - - collected := make(map[string]int64) - d.collectStatistic(collected, statistics) - - return collected, nil -} - -func (d *DNSdist) collectStatistic(collected map[string]int64, statistics *statisticMetrics) { - for metric, value := range stm.ToMap(statistics) { - collected[metric] = value - } -} - -func (d *DNSdist) scrapeStatistics() (*statisticMetrics, error) { - req, _ := web.NewHTTPRequest(d.Request) - req.URL.Path = urlPathJSONStat - req.URL.RawQuery = url.Values{"command": []string{"stats"}}.Encode() - - var statistics statisticMetrics - if err := d.doOKDecode(req, &statistics); err != nil { - return nil, err - } - - return &statistics, nil -} - -func (d *DNSdist) doOKDecode(req *http.Request, in interface{}) error { - resp, err := d.httpClient.Do(req) - if err != nil { - return fmt.Errorf("error on HTTP request '%s': %v", req.URL, err) - } - defer closeBody(resp) - - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("'%s' returned HTTP status code: %d", req.URL, resp.StatusCode) - } - - if err := json.NewDecoder(resp.Body).Decode(in); err != nil { - return fmt.Errorf("error on decoding response from '%s': %v", req.URL, err) - } - - return nil -} - -func closeBody(resp *http.Response) { - if resp != nil && resp.Body != nil { - _, _ = io.Copy(io.Discard, resp.Body) - _ = resp.Body.Close() - } -} -- cgit v1.2.3