Skip to content

feat: split process metrics out of host metrics #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion cmd/commands/initconfig/configschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ type HostMonitoringLogsConfig struct {
Enabled bool `yaml:"enabled"`
}

type HostMonitoringMetricsConfig struct {
type HostMonitoringHostMetricsConfig struct {
Enabled bool `yaml:"enabled"`
}

type HostMonitoringProcessMetricsConfig struct {
Enabled bool `yaml:"enabled"`
}

type HostMonitoringMetricsConfig struct {
Host HostMonitoringHostMetricsConfig
Process HostMonitoringProcessMetricsConfig
}

type HostMonitoringConfig struct {
Enabled bool `yaml:"enabled"`
Logs HostMonitoringLogsConfig
Expand Down
47 changes: 26 additions & 21 deletions cmd/commands/initconfig/initconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@ import (
)

var (
config_path string
token string
observe_url string
self_monitoring_enabled bool
host_monitoring_enabled bool
host_monitoring_logs_enabled bool
host_monitoring_metrics_enabled bool
config_path string
token string
observe_url string
self_monitoring_enabled bool
host_monitoring_enabled bool
host_monitoring_logs_enabled bool
host_monitoring_metrics_host_enabled bool
host_monitoring_metrics_process_enabled bool
//go:embed observe-agent.tmpl
configTemplateFS embed.FS
)

const configTemplate = "observe-agent.tmpl"

type FlatAgentConfig struct {
Token string
ObserveURL string
SelfMonitoring_Enabled bool
HostMonitoring_Enabled bool
HostMonitoring_LogsEnabled bool
HostMonitoring_MetricsEnabled bool
Token string
ObserveURL string
SelfMonitoring_Enabled bool
HostMonitoring_Enabled bool
HostMonitoring_LogsEnabled bool
HostMonitoring_Metrics_HostEnabled bool
HostMonitoring_Metrics_ProcessEnabled bool
}

func NewConfigureCmd() *cobra.Command {
Expand All @@ -44,12 +46,13 @@ func NewConfigureCmd() *cobra.Command {
Long: `This command takes in parameters and creates an initialized observe agent configuration file. Will overwrite existing config file and should only be used to initialize.`,
RunE: func(cmd *cobra.Command, args []string) error {
configValues := FlatAgentConfig{
Token: viper.GetString("token"),
ObserveURL: viper.GetString("observe_url"),
SelfMonitoring_Enabled: viper.GetBool("self_monitoring::enabled"),
HostMonitoring_Enabled: viper.GetBool("host_monitoring::enabled"),
HostMonitoring_LogsEnabled: viper.GetBool("host_monitoring::logs::enabled"),
HostMonitoring_MetricsEnabled: viper.GetBool("host_monitoring::metrics::enabled"),
Token: viper.GetString("token"),
ObserveURL: viper.GetString("observe_url"),
SelfMonitoring_Enabled: viper.GetBool("self_monitoring::enabled"),
HostMonitoring_Enabled: viper.GetBool("host_monitoring::enabled"),
HostMonitoring_LogsEnabled: viper.GetBool("host_monitoring::logs::enabled"),
HostMonitoring_Metrics_HostEnabled: viper.GetBool("host_monitoring::metrics::host::enabled"),
HostMonitoring_Metrics_ProcessEnabled: viper.GetBool("host_monitoring::metrics::process::enabled"),
}
var outputPath string
if config_path != "" {
Expand Down Expand Up @@ -85,11 +88,13 @@ func RegisterConfigFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&self_monitoring_enabled, "self_monitoring::enabled", true, "Enable self monitoring")
cmd.PersistentFlags().BoolVar(&host_monitoring_enabled, "host_monitoring::enabled", true, "Enable host monitoring")
cmd.PersistentFlags().BoolVar(&host_monitoring_logs_enabled, "host_monitoring::logs::enabled", true, "Enable host monitoring logs")
cmd.PersistentFlags().BoolVar(&host_monitoring_metrics_enabled, "host_monitoring::metrics::enabled", true, "Enable host monitoring metrics")
cmd.PersistentFlags().BoolVar(&host_monitoring_metrics_host_enabled, "host_monitoring::metrics::host::enabled", true, "Enable host monitoring host metrics")
cmd.PersistentFlags().BoolVar(&host_monitoring_metrics_process_enabled, "host_monitoring::metrics::process::enabled", false, "Enable host monitoring process metrics")
viper.BindPFlag("token", cmd.PersistentFlags().Lookup("token"))
viper.BindPFlag("observe_url", cmd.PersistentFlags().Lookup("observe_url"))
viper.BindPFlag("self_monitoring::enabled", cmd.PersistentFlags().Lookup("self_monitoring::enabled"))
viper.BindPFlag("host_monitoring::enabled", cmd.PersistentFlags().Lookup("host_monitoring::enabled"))
viper.BindPFlag("host_monitoring::logs::enabled", cmd.PersistentFlags().Lookup("host_monitoring::logs::enabled"))
viper.BindPFlag("host_monitoring::metrics::enabled", cmd.PersistentFlags().Lookup("host_monitoring::metrics::enabled"))
viper.BindPFlag("host_monitoring::metrics::host::enabled", cmd.PersistentFlags().Lookup("host_monitoring::metrics::host::enabled"))
viper.BindPFlag("host_monitoring::metrics::process::enabled", cmd.PersistentFlags().Lookup("host_monitoring::metrics::process::enabled"))
}
16 changes: 13 additions & 3 deletions cmd/commands/initconfig/initconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ func Test_InitConfigCommand(t *testing.T) {
Enabled: true,
},
Metrics: HostMonitoringMetricsConfig{
Enabled: true,
Host: HostMonitoringHostMetricsConfig{
Enabled: true,
},
Process: HostMonitoringProcessMetricsConfig{
Enabled: false,
},
},
},
},
expectErr: "",
},
{
args: []string{"--config_path=./test-config.yaml", "--token=test-token", "--observe_url=test-url", "--self_monitoring::enabled=false", "--host_monitoring::enabled=false", "--host_monitoring::logs::enabled=false", "--host_monitoring::metrics::enabled=false"},
args: []string{"--config_path=./test-config.yaml", "--token=test-token", "--observe_url=test-url", "--self_monitoring::enabled=false", "--host_monitoring::enabled=false", "--host_monitoring::logs::enabled=false", "--host_monitoring::metrics::host::enabled=false", "--host_monitoring::metrics::process::enabled=false"},
expectedConfig: AgentConfig{
Token: "test-token",
ObserveURL: "test-url",
Expand All @@ -48,7 +53,12 @@ func Test_InitConfigCommand(t *testing.T) {
Enabled: false,
},
Metrics: HostMonitoringMetricsConfig{
Enabled: false,
Host: HostMonitoringHostMetricsConfig{
Enabled: false,
},
Process: HostMonitoringProcessMetricsConfig{
Enabled: false,
},
},
},
},
Expand Down
5 changes: 4 additions & 1 deletion cmd/commands/initconfig/observe-agent.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ host_monitoring:
logs:
enabled: {{ .HostMonitoring_LogsEnabled }}
metrics:
enabled: {{ .HostMonitoring_MetricsEnabled }}
host:
enabled: {{ .HostMonitoring_Metrics_HostEnabled }}
process:
enabled: {{ .HostMonitoring_Metrics_ProcessEnabled }}

# otel_config_overrides:
# exporters:
Expand Down
10 changes: 9 additions & 1 deletion cmd/connections/hostmonitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ var HostMonitoringConnectionType = ConnectionType{
},
{
configYAMLPath: "metrics::enabled",
colConfigFilePath: "metrics.yaml",
colConfigFilePath: "host_metrics.yaml",
},
{
configYAMLPath: "metrics::host::enabled",
colConfigFilePath: "host_metrics.yaml",
},
{
configYAMLPath: "metrics::process::enabled",
colConfigFilePath: "process_metrics.yaml",
},
{
configYAMLPath: "logs::enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
receivers:
hostmetrics/host-monitoring-host:
collection_interval: 60s
root_path: /hostfs
scrapers:
cpu:
metrics:
system.cpu.utilization:
enabled: true
system.cpu.frequency:
enabled: true
system.cpu.logical.count:
enabled: true
system.cpu.physical.count:
enabled: true
load:
memory:
metrics:
system.memory.utilization:
enabled: true
system.linux.memory.available:
enabled: true
disk:
filesystem:
metrics:
system.filesystem.utilization:
enabled: true
network:
paging:
metrics:
system.paging.utilization:
enabled: true
processes:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rmoved process scraper to other file

service:
pipelines:
metrics/host_monitoring_host:
receivers: [hostmetrics/host-monitoring-host]
processors: [memory_limiter, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
receivers:
hostmetrics/host-monitoring:
collection_interval: 20s
hostmetrics/host-monitoring-process:
collection_interval: 60s
root_path: /hostfs
scrapers:
cpu:
metrics:
system.cpu.utilization:
enabled: true
system.cpu.frequency:
enabled: true
system.cpu.logical.count:
enabled: true
system.cpu.physical.count:
enabled: true
load:
memory:
metrics:
system.memory.utilization:
enabled: true
system.linux.memory.available:
enabled: true
disk:
filesystem:
metrics:
system.filesystem.utilization:
enabled: true
network:
paging:
metrics:
system.paging.utilization:
enabled: true
processes:
process:
metrics:
process.context_switches:
Expand All @@ -56,7 +28,7 @@ receivers:

service:
pipelines:
metrics/host_monitoring:
receivers: [hostmetrics/host-monitoring]
metrics/host_monitoring_process:
receivers: [hostmetrics/host-monitoring-process]
processors: [memory_limiter, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]
5 changes: 4 additions & 1 deletion packaging/linux/config/observe-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ host_monitoring:
logs:
enabled: true
metrics:
enabled: true
host:
enabled: true
process:
enabled: false

# otel_config_overrides:
# exporters:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
receivers:
hostmetrics/host-monitoring-host:
collection_interval: 60s
scrapers:
cpu:
metrics:
system.cpu.utilization:
enabled: true
system.cpu.frequency:
enabled: true
system.cpu.logical.count:
enabled: true
system.cpu.physical.count:
enabled: true
load:
memory:
metrics:
system.memory.utilization:
enabled: true
system.linux.memory.available:
enabled: true
disk:
filesystem:
metrics:
system.filesystem.utilization:
enabled: true
network:
paging:
metrics:
system.paging.utilization:
enabled: true
processes:

service:
pipelines:
metrics/host_monitoring_host:
receivers: [hostmetrics/host-monitoring-host]
processors: [memory_limiter, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
receivers:
hostmetrics/host-monitoring:
collection_interval: 20s
hostmetrics/host-monitoring-process:
collection_interval: 60s
scrapers:
cpu:
metrics:
system.cpu.utilization:
enabled: true
system.cpu.frequency:
enabled: true
system.cpu.logical.count:
enabled: true
system.cpu.physical.count:
enabled: true
load:
memory:
metrics:
system.memory.utilization:
enabled: true
system.linux.memory.available:
enabled: true
disk:
filesystem:
metrics:
system.filesystem.utilization:
enabled: true
network:
paging:
metrics:
system.paging.utilization:
enabled: true
processes:
process:
metrics:
process.context_switches:
Expand All @@ -55,7 +27,7 @@ receivers:

service:
pipelines:
metrics/host_monitoring:
receivers: [hostmetrics/host-monitoring]
metrics/host_monitoring_process:
receivers: [hostmetrics/host-monitoring-process]
processors: [memory_limiter, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
receivers:
hostmetrics/host-monitoring:
collection_interval: 20s
hostmetrics/host-monitoring-host:
collection_interval: 60s
scrapers:
cpu:
metrics:
Expand All @@ -24,7 +24,7 @@ receivers:

service:
pipelines:
metrics/host_monitoring:
receivers: [hostmetrics/host-monitoring]
metrics/host_monitoring_host:
receivers: [hostmetrics/host-monitoring-host]
processors: [memory_limiter, resourcedetection, resourcedetection/cloud, batch]
exporters: [otlphttp/observe]
Loading
Loading