Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/prometheus/exporter/consul/consul.go
4096 views
1
package consul
2
3
import (
4
"time"
5
6
"github.com/grafana/agent/component"
7
"github.com/grafana/agent/component/prometheus/exporter"
8
"github.com/grafana/agent/pkg/integrations"
9
"github.com/grafana/agent/pkg/integrations/consul_exporter"
10
)
11
12
func init() {
13
component.Register(component.Registration{
14
Name: "prometheus.exporter.consul",
15
Args: Arguments{},
16
Exports: exporter.Exports{},
17
Build: exporter.New(createExporter, "consul"),
18
})
19
}
20
21
func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {
22
a := args.(Arguments)
23
return a.Convert().NewIntegration(opts.Logger)
24
}
25
26
// DefaultArguments holds the default settings for the consul_exporter exporter.
27
var DefaultArguments = Arguments{
28
Server: "http://localhost:8500",
29
Timeout: 500 * time.Millisecond,
30
AllowStale: true,
31
KVFilter: ".*",
32
HealthSummary: true,
33
}
34
35
// Arguments controls the consul_exporter exporter.
36
type Arguments struct {
37
Server string `river:"server,attr,optional"`
38
CAFile string `river:"ca_file,attr,optional"`
39
CertFile string `river:"cert_file,attr,optional"`
40
KeyFile string `river:"key_file,attr,optional"`
41
ServerName string `river:"server_name,attr,optional"`
42
Timeout time.Duration `river:"timeout,attr,optional"`
43
InsecureSkipVerify bool `river:"insecure_skip_verify,attr,optional"`
44
RequestLimit int `river:"concurrent_request_limit,attr,optional"`
45
AllowStale bool `river:"allow_stale,attr,optional"`
46
RequireConsistent bool `river:"require_consistent,attr,optional"`
47
48
KVPrefix string `river:"kv_prefix,attr,optional"`
49
KVFilter string `river:"kv_filter,attr,optional"`
50
HealthSummary bool `river:"generate_health_summary,attr,optional"`
51
}
52
53
// UnmarshalRiver implements River unmarshalling for Arguments.
54
func (a *Arguments) UnmarshalRiver(f func(interface{}) error) error {
55
*a = DefaultArguments
56
57
type args Arguments
58
return f((*args)(a))
59
}
60
61
func (a *Arguments) Convert() *consul_exporter.Config {
62
return &consul_exporter.Config{
63
Server: a.Server,
64
CAFile: a.CAFile,
65
CertFile: a.CertFile,
66
KeyFile: a.KeyFile,
67
ServerName: a.ServerName,
68
Timeout: a.Timeout,
69
InsecureSkipVerify: a.InsecureSkipVerify,
70
RequestLimit: a.RequestLimit,
71
AllowStale: a.AllowStale,
72
RequireConsistent: a.RequireConsistent,
73
KVPrefix: a.KVPrefix,
74
KVFilter: a.KVFilter,
75
HealthSummary: a.HealthSummary,
76
}
77
}
78
79