-
Notifications
You must be signed in to change notification settings - Fork 482
/
squid.go
69 lines (57 loc) · 1.72 KB
/
squid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package squid
import (
"net"
"github.com/grafana/agent/component"
"github.com/grafana/agent/component/prometheus/exporter"
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/squid_exporter"
"github.com/grafana/river/rivertypes"
"github.com/prometheus/common/config"
)
func init() {
component.Register(component.Registration{
Name: "prometheus.exporter.squid",
Args: Arguments{},
Exports: exporter.Exports{},
NeedsServices: exporter.RequiredServices(),
Build: exporter.New(createExporter, "squid"),
})
}
func createExporter(opts component.Options, args component.Arguments, defaultInstanceKey string) (integrations.Integration, string, error) {
a := args.(Arguments)
return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.Convert(), defaultInstanceKey)
}
// Arguments controls the squid exporter.
type Arguments struct {
SquidAddr string `river:"address,attr"`
SquidUser string `river:"username,attr,optional"`
SquidPassword rivertypes.Secret `river:"password,attr,optional"`
}
// SetToDefault implements river.Defaulter.
func (a *Arguments) SetToDefault() {
*a = Arguments{}
}
// Validate implements river.Validator.
func (a *Arguments) Validate() error {
if a.SquidAddr == "" {
return squid_exporter.ErrNoAddress
}
host, port, err := net.SplitHostPort(a.SquidAddr)
if err != nil {
return err
}
if host == "" {
return squid_exporter.ErrNoHostname
}
if port == "" {
return squid_exporter.ErrNoPort
}
return nil
}
func (a *Arguments) Convert() *squid_exporter.Config {
return &squid_exporter.Config{
Address: a.SquidAddr,
Username: a.SquidUser,
Password: config.Secret(a.SquidPassword),
}
}