// Package agent is an "example" integration that has very little functionality,1// but is still useful in practice. The Agent integration re-exposes the Agent's2// own metrics endpoint and allows the Agent to scrape itself.3package agent45import (6"context"7"net/http"89"github.com/go-kit/log"10"github.com/grafana/agent/pkg/integrations"11"github.com/grafana/agent/pkg/integrations/config"12"github.com/prometheus/client_golang/prometheus/promhttp"13)1415// Config controls the Agent integration.16type Config struct{}1718// Name returns the name of the integration that this config represents.19func (c *Config) Name() string {20return "agent"21}2223// InstanceKey returns the hostname of the machine.24func (c *Config) InstanceKey(agentKey string) (string, error) {25return agentKey, nil26}2728// NewIntegration converts this config into an instance of an integration.29func (c *Config) NewIntegration(_ log.Logger) (integrations.Integration, error) {30return New(c), nil31}3233func init() {34integrations.RegisterIntegration(&Config{})35}3637// Integration is the Agent integration. The Agent integration scrapes the38// Agent's own metrics.39type Integration struct {40c *Config41}4243// New creates a new Agent integration.44func New(c *Config) *Integration {45return &Integration{c: c}46}4748// MetricsHandler satisfies Integration.RegisterRoutes.49func (i *Integration) MetricsHandler() (http.Handler, error) {50return promhttp.Handler(), nil51}5253// ScrapeConfigs satisfies Integration.ScrapeConfigs.54func (i *Integration) ScrapeConfigs() []config.ScrapeConfig {55return []config.ScrapeConfig{{56JobName: i.c.Name(),57MetricsPath: "/metrics",58}}59}6061// Run satisfies Integration.Run.62func (i *Integration) Run(ctx context.Context) error {63// We don't need to do anything here, so we can just wait for the context to64// finish.65<-ctx.Done()66return ctx.Err()67}686970