Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/handler_integration.go
5282 views
1
package integrations
2
3
import (
4
"context"
5
"net/http"
6
7
"github.com/grafana/agent/pkg/integrations/config"
8
)
9
10
// NewHandlerIntegration creates a new named integration that will call handler
11
// when metrics are needed.
12
func NewHandlerIntegration(name string, handler http.Handler) Integration {
13
return &handlerIntegration{name: name, handler: handler}
14
}
15
16
type handlerIntegration struct {
17
name string
18
handler http.Handler
19
}
20
21
func (hi *handlerIntegration) MetricsHandler() (http.Handler, error) {
22
return hi.handler, nil
23
}
24
25
func (hi *handlerIntegration) ScrapeConfigs() []config.ScrapeConfig {
26
return []config.ScrapeConfig{{
27
JobName: hi.name,
28
MetricsPath: "/metrics",
29
}}
30
}
31
32
func (hi *handlerIntegration) Run(ctx context.Context) error {
33
<-ctx.Done()
34
return nil
35
}
36
37