Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/prometheus/exporter/process/process.go
4096 views
1
package process
2
3
import (
4
"github.com/grafana/agent/component"
5
"github.com/grafana/agent/component/prometheus/exporter"
6
"github.com/grafana/agent/pkg/integrations"
7
"github.com/grafana/agent/pkg/integrations/process_exporter"
8
exporter_config "github.com/ncabatoff/process-exporter/config"
9
)
10
11
func init() {
12
component.Register(component.Registration{
13
Name: "prometheus.exporter.process",
14
Args: Arguments{},
15
Exports: exporter.Exports{},
16
Build: exporter.New(createIntegration, "process"),
17
})
18
}
19
20
func createIntegration(opts component.Options, args component.Arguments) (integrations.Integration, error) {
21
a := args.(Arguments)
22
return a.Convert().NewIntegration(opts.Logger)
23
}
24
25
// DefaultArguments holds the default arguments for the prometheus.exporter.process
26
// component.
27
var DefaultArguments = Arguments{
28
ProcFSPath: "/proc",
29
Children: true,
30
Threads: true,
31
SMaps: true,
32
Recheck: false,
33
}
34
35
// Arguments configures the prometheus.exporter.process component
36
type Arguments struct {
37
ProcessExporter []MatcherGroup `river:"matcher,block,optional"`
38
39
ProcFSPath string `river:"procfs_path,attr,optional"`
40
Children bool `river:"track_children,attr,optional"`
41
Threads bool `river:"track_threads,attr,optional"`
42
SMaps bool `river:"gather_smaps,attr,optional"`
43
Recheck bool `river:"recheck_on_scrape,attr,optional"`
44
}
45
46
// MatcherGroup taken and converted to River from github.com/ncabatoff/process-exporter/config
47
type MatcherGroup struct {
48
Name string `river:"name,attr,optional"`
49
CommRules []string `river:"comm,attr,optional"`
50
ExeRules []string `river:"exe,attr,optional"`
51
CmdlineRules []string `river:"cmdline,attr,optional"`
52
}
53
54
// UnmarshalRiver implements River unmarshalling for Config.
55
func (c *Arguments) UnmarshalRiver(f func(interface{}) error) error {
56
*c = DefaultArguments
57
58
type args Arguments
59
return f((*args)(c))
60
}
61
62
func (a *Arguments) Convert() *process_exporter.Config {
63
return &process_exporter.Config{
64
ProcessExporter: convertMatcherGroups(a.ProcessExporter),
65
ProcFSPath: a.ProcFSPath,
66
Children: a.Children,
67
Threads: a.Threads,
68
SMaps: a.SMaps,
69
Recheck: a.Recheck,
70
}
71
}
72
73
func convertMatcherGroups(m []MatcherGroup) exporter_config.MatcherRules {
74
var out exporter_config.MatcherRules
75
for _, v := range m {
76
out = append(out, exporter_config.MatcherGroup(v))
77
}
78
return out
79
}
80
81