Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d17daeb
initial
captncraig Jul 7, 2022
e741cbd
at least get node_exporter running
captncraig Jul 7, 2022
6b650d1
basic framework for exposing http handlers from components
captncraig Jul 7, 2022
4905ae4
add some output targets (still unsure of proper format)
captncraig Jul 7, 2022
16e5778
Merge branch 'main' into cmp_node_exporter_flow
captncraig Jul 14, 2022
536cc39
clean up path handling code a bit
captncraig Jul 14, 2022
f7ff605
lint
captncraig Jul 14, 2022
12fa0b0
merge
captncraig Jul 25, 2022
fff138b
use model package for label names
captncraig Jul 25, 2022
dc4606c
fix conflicts and update for river
captncraig Aug 3, 2022
83033eb
handle error
captncraig Aug 3, 2022
fde2356
lint
captncraig Aug 3, 2022
946a195
fix lint
captncraig Aug 3, 2022
f489282
lint problems
captncraig Aug 3, 2022
7dfe878
first round code review
captncraig Sep 6, 2022
cf5b271
add files
captncraig Sep 6, 2022
fa4ec40
pass http addr all the way down
captncraig Sep 6, 2022
e76525a
Update component/component.go
captncraig Sep 6, 2022
7be0900
Update component/component.go
captncraig Sep 6, 2022
3a7f4ba
code review changes
captncraig Sep 6, 2022
f4512ac
don't embed mutex
captncraig Sep 6, 2022
3ab9aac
Merge branch 'cmp_node_exporter_flow' of github.com:grafana/agent int…
captncraig Sep 6, 2022
7e41382
fix validation for three part names
captncraig Sep 6, 2022
4e6f689
add files
captncraig Sep 6, 2022
45ea2f4
Update component/all/all.go
captncraig Sep 7, 2022
5a299d2
Update component/component.go
captncraig Sep 7, 2022
91a29e4
Update component/prometheus/integrations/node_exporter/node_exporter.go
captncraig Sep 7, 2022
a496a03
Update component/prometheus/integrations/node_exporter/node_exporter.go
captncraig Sep 7, 2022
1d11276
clean up calidatePrefixMatch
captncraig Sep 7, 2022
142611e
make river specific config types
captncraig Sep 7, 2022
d0d8b41
remove river tags
captncraig Sep 7, 2022
838f588
reference node_integration.Defaults for more complicated fields
captncraig Sep 7, 2022
97221cb
reduce imports
captncraig Sep 7, 2022
5e79ff1
doc commennts
captncraig Sep 7, 2022
e8bc4b5
periods
captncraig Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/agent/flow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func (fr *flowRun) Run(configFile string) error {
}

f := flow.New(flow.Options{
Logger: l,
DataPath: fr.storagePath,
Reg: prometheus.DefaultRegisterer,
Logger: l,
DataPath: fr.storagePath,
Reg: prometheus.DefaultRegisterer,
HTTPListenAddr: fr.httpListenAddr,
})

reload := func() error {
Expand Down Expand Up @@ -152,6 +153,7 @@ func (fr *flowRun) Run(configFile string) error {
r.Handle("/debug/graph", f.GraphHandler())
r.Handle("/debug/scope", f.ScopeHandler())
r.PathPrefix("/debug/pprof").Handler(http.DefaultServeMux)
r.PathPrefix("/component/{id}/").Handler(f.ComponentHandler())
}

ready := atomic.NewBool(true)
Expand Down
15 changes: 8 additions & 7 deletions component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
package all

import (
_ "github.com/grafana/agent/component/discovery/kubernetes" // Import discovery.k8s
_ "github.com/grafana/agent/component/discovery/relabel" // Import discovery.relabel
_ "github.com/grafana/agent/component/local/file" // Import local.file
_ "github.com/grafana/agent/component/prometheus/relabel" // Import prometheus.relabel
_ "github.com/grafana/agent/component/prometheus/remotewrite" // Import prometheus.remote_write
_ "github.com/grafana/agent/component/prometheus/scrape" // Import prometheus.scrape
_ "github.com/grafana/agent/component/remote/s3" // Import s3.file
_ "github.com/grafana/agent/component/discovery/kubernetes" // Import discovery.k8s
_ "github.com/grafana/agent/component/discovery/relabel" // Import discovery.relabel
_ "github.com/grafana/agent/component/local/file" // Import local.file
_ "github.com/grafana/agent/component/prometheus/integrations/node_exporter" // Import prometheus.integration.node_exporter
_ "github.com/grafana/agent/component/prometheus/relabel" // Import prometheus.relabel
_ "github.com/grafana/agent/component/prometheus/remotewrite" // Import prometheus.remote_write
_ "github.com/grafana/agent/component/prometheus/scrape" // Import prometheus.scrape
_ "github.com/grafana/agent/component/remote/s3" // Import s3.file
)
16 changes: 15 additions & 1 deletion component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
// creating a new one.
package component

import "context"
import (
"context"
"net/http"
)

// The Arguments contains the input fields for a specific component, which is
// unmarshaled from River.
Expand Down Expand Up @@ -111,3 +114,14 @@ type DebugComponent interface {
// DebugInfo must be safe for calling concurrently.
DebugInfo() interface{}
}

// HTTPComponent is an extension interface for components which contain their own HTTP handlers.
type HTTPComponent interface {
Component

// Handler should return a valid HTTP handler for the component.
// All requests to the component will have the path trimmed such that the component is at the root.
// For example, f a request is made to `/component/{id}/metrics`, the component
// will receive a request to just `/metrics`.
Handler() http.Handler
}
268 changes: 268 additions & 0 deletions component/prometheus/integrations/node_exporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
package node_exporter

import (
"time"

node_integration "github.com/grafana/agent/pkg/integrations/node_exporter"
"github.com/grafana/dskit/flagext"
)

// DefaultConfig holds non-zero default options for the Config when it is
// unmarshaled from YAML.
//
// Some defaults are populated from init functions in the github.com/grafana/agent/pkg/integrations/node_exporter package.
var DefaultConfig = Config{
ProcFSPath: node_integration.DefaultConfig.ProcFSPath,
RootFSPath: node_integration.DefaultConfig.RootFSPath,
SysFSPath: node_integration.DefaultConfig.SysFSPath,
Disk: DiskStatsConfig{
IgnoredDevices: node_integration.DefaultConfig.DiskStatsIgnoredDevices,
},
EthTool: EthToolConfig{
MetricsInclude: ".*",
},
Filesystem: FilesystemConfig{
MountTimeout: 5 * time.Second,
MountPointsExclude: node_integration.DefaultConfig.FilesystemMountPointsExclude,
FSTypesExclude: node_integration.DefaultConfig.FilesystemFSTypesExclude,
},
NTP: NTPConfig{
IPTTL: 1,
LocalOffsetTolerance: time.Millisecond,
MaxDistance: time.Microsecond * 3466080,
ProtocolVersion: 4,
Server: "127.0.0.1",
},
Netclass: NetclassConfig{
IgnoredDevices: "^$",
},
Netstat: NetstatConfig{
Fields: node_integration.DefaultConfig.NetstatFields,
},
Powersupply: PowersupplyConfig{
IgnoredSupplies: "^$",
},
Runit: RunitConfig{
ServiceDir: "/etc/service",
},
Supervisord: SupervisordConfig{
URL: node_integration.DefaultConfig.SupervisordURL,
},
Systemd: SystemdConfig{
UnitExclude: node_integration.DefaultConfig.SystemdUnitExclude,
UnitInclude: ".+",
},
Tapestats: TapestatsConfig{
IgnoredDevices: "^$",
},
VMStat: VMStatConfig{
Fields: node_integration.DefaultConfig.VMStatFields,
},
}

// Config is the base config for this integration.
type Config struct {
IncludeExporterMetrics bool `river:"include_exporter_metrics,attr,optional"`
ProcFSPath string `river:"procfs_path,attr,optional"`
SysFSPath string `river:"sysfs_path,attr,optional"`
RootFSPath string `river:"rootfs_path,attr,optional"`

// Collectors to mark as enabled
EnableCollectors flagext.StringSlice `river:"enable_collectors,attr,optional"`

// Collectors to mark as disabled
DisableCollectors flagext.StringSlice `river:"disable_collectors,attr,optional"`

// Overrides the default set of enabled collectors with the collectors
// listed.
SetCollectors flagext.StringSlice `river:"set_collectors,attr,optional"`

// Collector-specific config options
BCache BCacheConfig `river:"bcache,block,optional"`
CPU CPUConfig `river:"cpu,block,optional"`
Disk DiskStatsConfig `river:"disk,block,optional"`
EthTool EthToolConfig `river:"ethtool,block,optional"`
Filesystem FilesystemConfig `river:"filesystem,block,optional"`
IPVS IPVSConfig `river:"ipvs,block,optional"`
NTP NTPConfig `river:"ntp,block,optional"`
Netclass NetclassConfig `river:"netclass,block,optional"`
Netdev NetdevConfig `river:"netdev,block,optional"`
Netstat NetstatConfig `river:"netstat,block,optional"`
Perf PerfConfig `river:"perf,block,optional"`
Powersupply PowersupplyConfig `river:"powersupply,block,optional"`
Runit RunitConfig `river:"runit,block,optional"`
Supervisord SupervisordConfig `river:"supervisord,block,optional"`
Systemd SystemdConfig `river:"systemd,block,optional"`
Tapestats TapestatsConfig `river:"tapestats,block,optional"`
Textfile TextfileConfig `river:"textfile,block,optional"`
VMStat VMStatConfig `river:"vmstat,block,optional"`
}

// Convert gives a config suitable for use with github.com/grafana/agent/pkg/integrations/node_exporter.
func (c *Config) Convert() *node_integration.Config {
return &node_integration.Config{
IncludeExporterMetrics: c.IncludeExporterMetrics,
ProcFSPath: c.ProcFSPath,
SysFSPath: c.SysFSPath,
RootFSPath: c.RootFSPath,
EnableCollectors: c.EnableCollectors,
DisableCollectors: c.DisableCollectors,
SetCollectors: c.SetCollectors,
BcachePriorityStats: c.BCache.PriorityStats,
CPUBugsInclude: c.CPU.BugsInclude,
CPUEnableCPUGuest: c.CPU.EnableCPUGuest,
CPUEnableCPUInfo: c.CPU.EnableCPUInfo,
CPUFlagsInclude: c.CPU.FlagsInclude,
DiskStatsIgnoredDevices: c.Disk.IgnoredDevices,
EthtoolDeviceExclude: c.EthTool.DeviceExclude,
EthtoolDeviceInclude: c.EthTool.DeviceInclude,
EthtoolMetricsInclude: c.EthTool.MetricsInclude,
FilesystemFSTypesExclude: c.Filesystem.FSTypesExclude,
FilesystemMountPointsExclude: c.Filesystem.MountPointsExclude,
FilesystemMountTimeout: c.Filesystem.MountTimeout,
IPVSBackendLabels: c.IPVS.BackendLabels,
NTPIPTTL: c.NTP.IPTTL,
NTPLocalOffsetTolerance: c.NTP.LocalOffsetTolerance,
NTPMaxDistance: c.NTP.MaxDistance,
NTPProtocolVersion: c.NTP.ProtocolVersion,
NTPServer: c.NTP.Server,
NTPServerIsLocal: c.NTP.ServerIsLocal,
NetclassIgnoreInvalidSpeedDevice: c.Netclass.IgnoreInvalidSpeedDevice,
NetclassIgnoredDevices: c.Netclass.IgnoredDevices,
NetdevAddressInfo: c.Netdev.AddressInfo,
NetdevDeviceExclude: c.Netdev.DeviceExclude,
NetdevDeviceInclude: c.Netdev.DeviceInclude,
NetstatFields: c.Netstat.Fields,
PerfCPUS: c.Perf.CPUS,
PerfTracepoint: c.Perf.Tracepoint,
PowersupplyIgnoredSupplies: c.Powersupply.IgnoredSupplies,
RunitServiceDir: c.Runit.ServiceDir,
SupervisordURL: c.Supervisord.URL,
SystemdEnableRestartsMetrics: c.Systemd.EnableRestartsMetrics,
SystemdEnableStartTimeMetrics: c.Systemd.EnableStartTimeMetrics,
SystemdEnableTaskMetrics: c.Systemd.EnableTaskMetrics,
SystemdUnitExclude: c.Systemd.UnitExclude,
SystemdUnitInclude: c.Systemd.UnitInclude,
TapestatsIgnoredDevices: c.Tapestats.IgnoredDevices,
TextfileDirectory: c.Textfile.Directory,
VMStatFields: c.VMStat.Fields,
}
}

// UnmarshalRiver implements River unmarshalling for Config.
func (c *Config) UnmarshalRiver(f func(interface{}) error) error {
*c = DefaultConfig

type cfg Config
return f((*cfg)(c))
}

// PowersupplyConfig contains config specific to the powersupply collector.
type PowersupplyConfig struct {
IgnoredSupplies string `river:"ignored_supplies,attr,optional"`
}

// RunitConfig contains config specific to the runit collector.
type RunitConfig struct {
ServiceDir string `river:"service_dir,attr,optional"`
}

// SupervisordConfig contains config specific to the supervisord collector.
type SupervisordConfig struct {
URL string `river:"url,attr,optional"`
}

// TapestatsConfig contains config specific to the tapestats collector.
type TapestatsConfig struct {
IgnoredDevices string `river:"ignored_devices,attr,optional"`
}

// TextfileConfig contains config specific to the textfile collector.
type TextfileConfig struct {
Directory string `river:"directory,attr,optional"`
}

// VMStatConfig contains config specific to the vmstat collector.
type VMStatConfig struct {
Fields string `river:"fields,attr,optional"`
}

// NetclassConfig contains config specific to the netclass collector.
type NetclassConfig struct {
IgnoreInvalidSpeedDevice bool `river:"ignore_invalid_speed_device,attr,optional"`
IgnoredDevices string `river:"ignored_devices,attr,optional"`
}

// NetdevConfig contains config specific to the netdev collector.
type NetdevConfig struct {
AddressInfo bool `river:"address_info,attr,optional"`
DeviceExclude string `river:"device_exclude,attr,optional"`
DeviceInclude string `river:"device_include,attr,optional"`
}

// NetstatConfig contains config specific to the netstat collector.
type NetstatConfig struct {
Fields string `river:"fields,attr,optional"`
}

// PerfConfig contains config specific to the perf collector.
type PerfConfig struct {
CPUS string `river:"cpus,attr,optional"`
Tracepoint flagext.StringSlice `river:"tracepoint,attr,optional"`
}

// EthToolConfig contains config specific to the ethtool collector.
type EthToolConfig struct {
DeviceExclude string `river:"device_exclude,attr,optional"`
DeviceInclude string `river:"device_include,attr,optional"`
MetricsInclude string `river:"metrics_include,attr,optional"`
}

// FilesystemConfig contains config specific to the filesystem collector.
type FilesystemConfig struct {
FSTypesExclude string `river:"fs_types_exclude,attr,optional"`
MountPointsExclude string `river:"mount_points_exclude,attr,optional"`
MountTimeout time.Duration `river:"mount_timeout,attr,optional"`
}

// IPVSConfig contains config specific to the ipvs collector.
type IPVSConfig struct {
BackendLabels []string `river:"backend_labels,attr,optional"`
}

// BCacheConfig contains config specific to the bcache collector.
type BCacheConfig struct {
PriorityStats bool `river:"priority_stats,attr,optional"`
}

// CPUConfig contains config specific to the cpu collector.
type CPUConfig struct {
BugsInclude string `river:"bugs_include,attr,optional"`
EnableCPUGuest bool `river:"guest,attr,optional"`
EnableCPUInfo bool `river:"info,attr,optional"`
FlagsInclude string `river:"flags_include,attr,optional"`
}

// DiskStatsConfig contains config specific to the diskstats collector.
type DiskStatsConfig struct {
IgnoredDevices string `river:"ignored_devices,attr,optional"`
}

// NTPConfig contains config specific to the ntp collector.
type NTPConfig struct {
IPTTL int `river:"ip_ttl,attr,optional"`
LocalOffsetTolerance time.Duration `river:"local_offset_tolerance,attr,optional"`
MaxDistance time.Duration `river:"max_distance,attr,optional"`
ProtocolVersion int `river:"protocol_version,attr,optional"`
Server string `river:"server,attr,optional"`
ServerIsLocal bool `river:"server_is_local,attr,optional"`
}

// SystemdConfig contains config specific to the systemd collector.
type SystemdConfig struct {
EnableRestartsMetrics bool `river:"enable_restarts,attr,optional"`
EnableStartTimeMetrics bool `river:"start_time,attr,optional"`
EnableTaskMetrics bool `river:"task_metrics,attr,optional"`
UnitExclude string `river:"unit_exclude,attr,optional"`
UnitInclude string `river:"unit_include,attr,optional"`
}
Loading