Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/apache_http/apache_http.go
5283 views
1
// Package apache_http embeds https://github.com/Lusitaniae/apache_exporter
2
package apache_http //nolint:golint
3
4
import (
5
"net/url"
6
7
ae "github.com/Lusitaniae/apache_exporter/collector"
8
"github.com/go-kit/log"
9
"github.com/go-kit/log/level"
10
"github.com/grafana/agent/pkg/integrations"
11
)
12
13
// DefaultConfig holds the default settings for the apache_http integration
14
var DefaultConfig = Config{
15
ApacheAddr: "http://localhost/server-status?auto",
16
ApacheHostOverride: "",
17
ApacheInsecure: false,
18
}
19
20
// Config controls the apache_http integration.
21
type Config struct {
22
ApacheAddr string `yaml:"scrape_uri,omitempty"`
23
ApacheHostOverride string `yaml:"host_override,omitempty"`
24
ApacheInsecure bool `yaml:"insecure,omitempty"`
25
}
26
27
// UnmarshalYAML implements yaml.Unmarshaler for Config
28
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
29
*c = DefaultConfig
30
31
type plain Config
32
return unmarshal((*plain)(c))
33
}
34
35
// Name returns the name of the integration this config is for.
36
func (c *Config) Name() string {
37
return "apache_http"
38
}
39
40
// InstanceKey returns the addr of the apache server.
41
func (c *Config) InstanceKey(agentKey string) (string, error) {
42
u, err := url.Parse(c.ApacheAddr)
43
if err != nil {
44
return "", err
45
}
46
return u.Host, nil
47
}
48
49
// NewIntegration converts the config into an integration instance.
50
func (c *Config) NewIntegration(logger log.Logger) (integrations.Integration, error) {
51
return New(logger, c)
52
}
53
54
func init() {
55
integrations.RegisterIntegration(&Config{})
56
}
57
58
// New creates a new apache_http integration. The integration scrapes metrics
59
// from an Apache HTTP server.
60
func New(logger log.Logger, c *Config) (integrations.Integration, error) {
61
conf := &ae.Config{
62
ScrapeURI: c.ApacheAddr,
63
HostOverride: c.ApacheHostOverride,
64
Insecure: c.ApacheInsecure,
65
}
66
67
//check scrape URI
68
_, err := url.ParseRequestURI(conf.ScrapeURI)
69
if err != nil {
70
level.Error(logger).Log("msg", "scrape_uri is invalid", "err", err)
71
return nil, err
72
}
73
aeExporter := ae.NewExporter(logger, conf)
74
75
return integrations.NewCollectorIntegration(
76
c.Name(),
77
integrations.WithCollectors(aeExporter),
78
), nil
79
}
80
81