Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/agent/agent.go
5333 views
1
// Package agent is an "example" integration that has very little functionality,
2
// but is still useful in practice. The Agent integration re-exposes the Agent's
3
// own metrics endpoint and allows the Agent to scrape itself.
4
package agent
5
6
import (
7
"github.com/go-kit/log"
8
"github.com/grafana/agent/pkg/integrations/v2"
9
"github.com/grafana/agent/pkg/integrations/v2/common"
10
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
11
"github.com/prometheus/client_golang/prometheus/promhttp"
12
)
13
14
// Config controls the Agent integration.
15
type Config struct {
16
Common common.MetricsConfig `yaml:",inline"`
17
}
18
19
// Name returns the name of the integration that this config represents.
20
func (c *Config) Name() string { return "agent" }
21
22
// ApplyDefaults applies runtime-specific defaults to c.
23
func (c *Config) ApplyDefaults(globals integrations.Globals) error {
24
c.Common.ApplyDefaults(globals.SubsystemOpts.Metrics.Autoscrape)
25
if id, err := c.Identifier(globals); err == nil {
26
c.Common.InstanceKey = &id
27
}
28
return nil
29
}
30
31
// Identifier uniquely identifies this instance of Config.
32
func (c *Config) Identifier(globals integrations.Globals) (string, error) {
33
if c.Common.InstanceKey != nil {
34
return *c.Common.InstanceKey, nil
35
}
36
return globals.AgentIdentifier, nil
37
}
38
39
// NewIntegration converts this config into an instance of an integration.
40
func (c *Config) NewIntegration(l log.Logger, globals integrations.Globals) (integrations.Integration, error) {
41
return metricsutils.NewMetricsHandlerIntegration(l, c, c.Common, globals, promhttp.Handler())
42
}
43
44
func init() {
45
integrations.Register(&Config{}, integrations.TypeSingleton)
46
}
47
48