-
Notifications
You must be signed in to change notification settings - Fork 487
/
agent.go
46 lines (39 loc) · 1.6 KB
/
agent.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
// Package agent is an "example" integration that has very little functionality,
// but is still useful in practice. The Agent integration re-exposes the Agent's
// own metrics endpoint and allows the Agent to scrape itself.
package agent
import (
"github.com/go-kit/log"
"github.com/grafana/agent/pkg/integrations/v2"
"github.com/grafana/agent/pkg/integrations/v2/common"
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// Config controls the Agent integration.
type Config struct {
Common common.MetricsConfig `yaml:",inline"`
}
// Name returns the name of the integration that this config represents.
func (c *Config) Name() string { return "agent" }
// ApplyDefaults applies runtime-specific defaults to c.
func (c *Config) ApplyDefaults(globals integrations.Globals) error {
c.Common.ApplyDefaults(globals.SubsystemOpts.Metrics.Autoscrape)
if id, err := c.Identifier(globals); err == nil {
c.Common.InstanceKey = &id
}
return nil
}
// Identifier uniquely identifies this instance of Config.
func (c *Config) Identifier(globals integrations.Globals) (string, error) {
if c.Common.InstanceKey != nil {
return *c.Common.InstanceKey, nil
}
return globals.AgentIdentifier, nil
}
// NewIntegration converts this config into an instance of an integration.
func (c *Config) NewIntegration(l log.Logger, globals integrations.Globals) (integrations.Integration, error) {
return metricsutils.NewMetricsHandlerIntegration(l, c, c.Common, globals, promhttp.Handler())
}
func init() {
integrations.Register(&Config{}, integrations.TypeSingleton)
}