Skip to content

Commit d8aad32

Browse files
committed
[Ingest Manager] Proxy processes/elastic-agent to stats (#25193)
[Ingest Manager] Proxy processes/elastic-agent to stats (#25193)
1 parent 2f4b0ce commit d8aad32

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

x-pack/elastic-agent/pkg/core/monitoring/server/process.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/gorilla/mux"
1919

2020
"github.com/elastic/beats/v7/metricbeat/mb/parse"
21+
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
2122
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/program"
2223
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact"
2324
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/monitoring/beats"
@@ -51,7 +52,7 @@ var (
5152
}
5253
)
5354

54-
func processHandler() func(http.ResponseWriter, *http.Request) error {
55+
func processHandler(statsHandler func(http.ResponseWriter, *http.Request) error) func(http.ResponseWriter, *http.Request) error {
5556
return func(w http.ResponseWriter, r *http.Request) error {
5657
w.Header().Set("Content-Type", "application/json; charset=utf-8")
5758

@@ -62,6 +63,11 @@ func processHandler() func(http.ResponseWriter, *http.Request) error {
6263
return errorfWithStatus(http.StatusNotFound, "productID not found")
6364
}
6465

66+
if id == paths.BinaryName {
67+
// proxy stats for elastic agent process
68+
return statsHandler(w, r)
69+
}
70+
6571
metricsBytes, statusCode, metricsErr := processMetrics(r.Context(), id)
6672
if metricsErr != nil {
6773
return metricsErr

x-pack/elastic-agent/pkg/core/monitoring/server/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ func New(
4444

4545
func exposeMetricsEndpoint(log *logger.Logger, config *common.Config, ns func(string) *monitoring.Namespace, routesFetchFn func() *sorted.Set, enableProcessStats bool) (*api.Server, error) {
4646
r := mux.NewRouter()
47-
r.Handle("/stats", createHandler(statsHandler(ns("stats"))))
47+
statsHandler := statsHandler(ns("stats"))
48+
r.Handle("/stats", createHandler(statsHandler))
4849

4950
if enableProcessStats {
5051
r.HandleFunc("/processes", processesHandler(routesFetchFn))
51-
r.Handle("/processes/{processID}", createHandler(processHandler()))
52+
r.Handle("/processes/{processID}", createHandler(processHandler(statsHandler)))
5253
}
5354

5455
mux := http.NewServeMux()

0 commit comments

Comments
 (0)