Path: blob/main/pkg/integrations/apache_http/apache_http.go
5283 views
// Package apache_http embeds https://github.com/Lusitaniae/apache_exporter1package apache_http //nolint:golint23import (4"net/url"56ae "github.com/Lusitaniae/apache_exporter/collector"7"github.com/go-kit/log"8"github.com/go-kit/log/level"9"github.com/grafana/agent/pkg/integrations"10)1112// DefaultConfig holds the default settings for the apache_http integration13var DefaultConfig = Config{14ApacheAddr: "http://localhost/server-status?auto",15ApacheHostOverride: "",16ApacheInsecure: false,17}1819// Config controls the apache_http integration.20type Config struct {21ApacheAddr string `yaml:"scrape_uri,omitempty"`22ApacheHostOverride string `yaml:"host_override,omitempty"`23ApacheInsecure bool `yaml:"insecure,omitempty"`24}2526// UnmarshalYAML implements yaml.Unmarshaler for Config27func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {28*c = DefaultConfig2930type plain Config31return unmarshal((*plain)(c))32}3334// Name returns the name of the integration this config is for.35func (c *Config) Name() string {36return "apache_http"37}3839// InstanceKey returns the addr of the apache server.40func (c *Config) InstanceKey(agentKey string) (string, error) {41u, err := url.Parse(c.ApacheAddr)42if err != nil {43return "", err44}45return u.Host, nil46}4748// NewIntegration converts the config into an integration instance.49func (c *Config) NewIntegration(logger log.Logger) (integrations.Integration, error) {50return New(logger, c)51}5253func init() {54integrations.RegisterIntegration(&Config{})55}5657// New creates a new apache_http integration. The integration scrapes metrics58// from an Apache HTTP server.59func New(logger log.Logger, c *Config) (integrations.Integration, error) {60conf := &ae.Config{61ScrapeURI: c.ApacheAddr,62HostOverride: c.ApacheHostOverride,63Insecure: c.ApacheInsecure,64}6566//check scrape URI67_, err := url.ParseRequestURI(conf.ScrapeURI)68if err != nil {69level.Error(logger).Log("msg", "scrape_uri is invalid", "err", err)70return nil, err71}72aeExporter := ae.NewExporter(logger, conf)7374return integrations.NewCollectorIntegration(75c.Name(),76integrations.WithCollectors(aeExporter),77), nil78}798081