Path: blob/main/component/prometheus/exporter/process/process.go
4096 views
package process12import (3"github.com/grafana/agent/component"4"github.com/grafana/agent/component/prometheus/exporter"5"github.com/grafana/agent/pkg/integrations"6"github.com/grafana/agent/pkg/integrations/process_exporter"7exporter_config "github.com/ncabatoff/process-exporter/config"8)910func init() {11component.Register(component.Registration{12Name: "prometheus.exporter.process",13Args: Arguments{},14Exports: exporter.Exports{},15Build: exporter.New(createIntegration, "process"),16})17}1819func createIntegration(opts component.Options, args component.Arguments) (integrations.Integration, error) {20a := args.(Arguments)21return a.Convert().NewIntegration(opts.Logger)22}2324// DefaultArguments holds the default arguments for the prometheus.exporter.process25// component.26var DefaultArguments = Arguments{27ProcFSPath: "/proc",28Children: true,29Threads: true,30SMaps: true,31Recheck: false,32}3334// Arguments configures the prometheus.exporter.process component35type Arguments struct {36ProcessExporter []MatcherGroup `river:"matcher,block,optional"`3738ProcFSPath string `river:"procfs_path,attr,optional"`39Children bool `river:"track_children,attr,optional"`40Threads bool `river:"track_threads,attr,optional"`41SMaps bool `river:"gather_smaps,attr,optional"`42Recheck bool `river:"recheck_on_scrape,attr,optional"`43}4445// MatcherGroup taken and converted to River from github.com/ncabatoff/process-exporter/config46type MatcherGroup struct {47Name string `river:"name,attr,optional"`48CommRules []string `river:"comm,attr,optional"`49ExeRules []string `river:"exe,attr,optional"`50CmdlineRules []string `river:"cmdline,attr,optional"`51}5253// UnmarshalRiver implements River unmarshalling for Config.54func (c *Arguments) UnmarshalRiver(f func(interface{}) error) error {55*c = DefaultArguments5657type args Arguments58return f((*args)(c))59}6061func (a *Arguments) Convert() *process_exporter.Config {62return &process_exporter.Config{63ProcessExporter: convertMatcherGroups(a.ProcessExporter),64ProcFSPath: a.ProcFSPath,65Children: a.Children,66Threads: a.Threads,67SMaps: a.SMaps,68Recheck: a.Recheck,69}70}7172func convertMatcherGroups(m []MatcherGroup) exporter_config.MatcherRules {73var out exporter_config.MatcherRules74for _, v := range m {75out = append(out, exporter_config.MatcherGroup(v))76}77return out78}798081