Skip to content
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

[Ingest Management] Agent expose metrics #22793

Merged
merged 23 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion x-pack/elastic-agent/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/spf13/cobra"

"github.com/elastic/beats/v7/libbeat/service"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
Expand Down
61 changes: 61 additions & 0 deletions x-pack/elastic-agent/pkg/agent/operation/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configrequest"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/install"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/program"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/app"
)
Expand All @@ -24,6 +25,7 @@ const (
logsProcessName = "filebeat"
metricsProcessName = "metricbeat"
artifactPrefix = "beats"
agentName = "elastic-agent"
)

func (o *Operator) handleStartSidecar(s configrequest.Step) (result error) {
Expand Down Expand Up @@ -324,6 +326,65 @@ func (o *Operator) getMonitoringMetricbeatConfig(output interface{}) (map[string
},
})
}

fixedAgentName := strings.ReplaceAll(agentName, "-", "_")
// setup cpu, memory and fd monitors for agents
modules = append(modules, map[string]interface{}{
"module": "system",
"period": "10s",
"metricsets": []string{"process"},
"index": fmt.Sprintf("metrics-elastic_agent.%s-default", fixedAgentName),
"processes": []string{install.BinaryName},
"processors": []map[string]interface{}{
{
"add_fields": map[string]interface{}{
"target": "data_stream",
"fields": map[string]interface{}{
"type": "metrics",
"dataset": fmt.Sprintf("elastic_agent.%s", fixedAgentName),
Copy link
Contributor

Choose a reason for hiding this comment

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

Still question if it should have the ending .elastic_agent? Why not just metrics-elastic_agent-default? Or does that not match the logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was thinking about following convention, i like shorter one better as well

"namespace": "default",
},
},
},
{
"add_fields": map[string]interface{}{
"target": "event",
"fields": map[string]interface{}{
"dataset": fmt.Sprintf("elastic_agent.%s", fixedAgentName),
},
},
},
{
"add_fields": map[string]interface{}{
"target": "elastic_agent",
"fields": map[string]interface{}{
"id": o.agentInfo.AgentID(),
"version": o.agentInfo.Version(),
"snapshot": o.agentInfo.Snapshot(),
},
},
},
{
"drop_event": map[string]interface{}{
"when": map[string]interface{}{
"not": map[string]interface{}{
"equals": map[string]interface{}{
"process.name": install.BinaryName,
},
},
},
},
},
{
// maps to keyword incorrectly, TODO: fix later, not that important field for our use-case
"drop_fields": map[string]interface{}{
"fields": []string{"system.process.cpu.start_time"},
"ignore_missing": true,
},
},
},
})

result := map[string]interface{}{
"metricbeat": map[string]interface{}{
"modules": modules,
Expand Down