Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[filebeat][httpjson] Add http metrics to httpjson input (#35392)
* Add http metrics to httpjson input * Add changelog entry * Document the exposed metrics * Move response total counter out of error block * Instrument chain HTTP client * Add httpjson interval metrics * Update docs * Format imports * Account for possible existing metric on passed in registry * Count pages for all responses * Rename metrics to be flat and add metrics gathering test * Rename in docs * Rename in docs * Add total body bytes metrics * Add _total suffix to all relevant metrics * Make test check against runtime values * Use http variables * Simplify test for runtime variability
- Loading branch information
Showing
13 changed files
with
561 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package httpjson | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/rcrowley/go-metrics" | ||
|
||
"github.com/elastic/elastic-agent-libs/monitoring" | ||
"github.com/elastic/elastic-agent-libs/monitoring/adapter" | ||
) | ||
|
||
type inputMetrics struct { | ||
intervalExecutionTime metrics.Sample // histogram of the total time elapsed during an interval | ||
intervalPageExecutionTime metrics.Sample // histogram of per page execution time during an interval | ||
intervalPages metrics.Sample // histogram of pages per interval | ||
intervals *monitoring.Uint // total number of intervals executed | ||
intervalErrs *monitoring.Uint // total number of interval errors | ||
} | ||
|
||
func newInputMetrics(reg *monitoring.Registry) *inputMetrics { | ||
if reg == nil { | ||
return nil | ||
} | ||
|
||
out := &inputMetrics{ | ||
intervals: monitoring.NewUint(reg, "httpjson_interval_total"), | ||
intervalErrs: monitoring.NewUint(reg, "httpjson_interval_errors_total"), | ||
intervalExecutionTime: metrics.NewUniformSample(1024), | ||
intervalPageExecutionTime: metrics.NewUniformSample(1024), | ||
intervalPages: metrics.NewUniformSample(1024), | ||
} | ||
|
||
_ = adapter.GetGoMetrics(reg, "httpjson_interval_execution_time", adapter.Accept). | ||
GetOrRegister("histogram", metrics.NewHistogram(out.intervalExecutionTime)) | ||
_ = adapter.GetGoMetrics(reg, "httpjson_interval_pages_execution_time", adapter.Accept). | ||
GetOrRegister("histogram", metrics.NewHistogram(out.intervalPageExecutionTime)) | ||
_ = adapter.GetGoMetrics(reg, "httpjson_interval_pages_total", adapter.Accept). | ||
GetOrRegister("histogram", metrics.NewHistogram(out.intervalPages)) | ||
|
||
return out | ||
} | ||
|
||
func (m *inputMetrics) updateIntervalMetrics(err error, t time.Time) { | ||
if m == nil { | ||
return | ||
} | ||
m.intervals.Add(1) | ||
m.intervalExecutionTime.Update(time.Since(t).Nanoseconds()) | ||
if err != nil { | ||
m.intervalErrs.Add(1) | ||
} | ||
} | ||
|
||
func (m *inputMetrics) updatePageExecutionTime(t time.Time) { | ||
if m == nil { | ||
return | ||
} | ||
m.intervalPageExecutionTime.Update(time.Since(t).Nanoseconds()) | ||
} | ||
|
||
func (m *inputMetrics) updatePagesPerInterval(npages int64) { | ||
if m == nil { | ||
return | ||
} | ||
m.intervalPages.Update(npages) | ||
} |
Oops, something went wrong.