github.com/netdata/go.d.plugin@v0.58.1/modules/haproxy/init.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package haproxy
     4  
     5  import (
     6  	"errors"
     7  
     8  	"github.com/netdata/go.d.plugin/pkg/prometheus"
     9  	"github.com/netdata/go.d.plugin/pkg/prometheus/selector"
    10  	"github.com/netdata/go.d.plugin/pkg/web"
    11  )
    12  
    13  func (h Haproxy) validateConfig() error {
    14  	if h.URL == "" {
    15  		return errors.New("'url' is not set")
    16  	}
    17  	if _, err := web.NewHTTPRequest(h.Request); err != nil {
    18  		return err
    19  	}
    20  	return nil
    21  }
    22  
    23  func (h Haproxy) initPrometheusClient() (prometheus.Prometheus, error) {
    24  	httpClient, err := web.NewHTTPClient(h.Client)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	prom := prometheus.NewWithSelector(httpClient, h.Request, sr)
    30  	return prom, nil
    31  }
    32  
    33  var sr, _ = selector.Expr{
    34  	Allow: []string{
    35  		metricBackendHTTPResponsesTotal,
    36  		metricBackendCurrentQueue,
    37  		metricBackendQueueTimeAverageSeconds,
    38  		metricBackendBytesInTotal,
    39  		metricBackendResponseTimeAverageSeconds,
    40  		metricBackendSessionsTotal,
    41  		metricBackendCurrentSessions,
    42  		metricBackendBytesOutTotal,
    43  	},
    44  }.Parse()