From f8e42f3df3c5763046f6e07a30f80e21542a4e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Tr=E1=BB=8Dng=20H=E1=BA=A3i?= <41283691+hainenber@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:54:07 +0700 Subject: [PATCH] feat(exporter): add Flow component for agent Integration (#5072) * feat(exporter): add Flow component for agent's integration * doc(changelog): add new Feature entry * chore(comp/agent): correct comp name in comments * Update prometheus.exporter.agent.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> * feat(comp/agent): allow defining multiple blocks of agent's Prom exporter --------- Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com> --- CHANGELOG.md | 1 + component/all/all.go | 1 + component/prometheus/exporter/agent/agent.go | 41 +++++++++++ .../components/prometheus.exporter.agent.md | 68 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 component/prometheus/exporter/agent/agent.go create mode 100644 docs/sources/flow/reference/components/prometheus.exporter.agent.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 4794196b7d9a..e7c92b06a3c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Main (unreleased) - `otelcol.processor.probabilistic_sampler` samples logs and traces based on configuration options. (@mar4uk) - `remote.kubernetes.configmap` loads a configmap's data for use in other components (@captncraig) - `remote.kubernetes.secret` loads a secret's data for use in other components (@captncraig) + - `prometheus.exporter.agent` - scrape agent's metrics. (@hainenber) - Flow: allow the HTTP server to be configured with TLS in the config file using the new `http` config block. (@rfratto) diff --git a/component/all/all.go b/component/all/all.go index daa03dc4bd40..a13b1876438d 100644 --- a/component/all/all.go +++ b/component/all/all.go @@ -87,6 +87,7 @@ import ( _ "github.com/grafana/agent/component/otelcol/receiver/otlp" // Import otelcol.receiver.otlp _ "github.com/grafana/agent/component/otelcol/receiver/prometheus" // Import otelcol.receiver.prometheus _ "github.com/grafana/agent/component/otelcol/receiver/zipkin" // Import otelcol.receiver.zipkin + _ "github.com/grafana/agent/component/prometheus/exporter/agent" // Import prometheus.exporter.agent _ "github.com/grafana/agent/component/prometheus/exporter/apache" // Import prometheus.exporter.apache _ "github.com/grafana/agent/component/prometheus/exporter/azure" // Import prometheus.exporter.azure _ "github.com/grafana/agent/component/prometheus/exporter/blackbox" // Import prometheus.exporter.blackbox diff --git a/component/prometheus/exporter/agent/agent.go b/component/prometheus/exporter/agent/agent.go new file mode 100644 index 000000000000..dbbeba14aed0 --- /dev/null +++ b/component/prometheus/exporter/agent/agent.go @@ -0,0 +1,41 @@ +package agent + +import ( + "github.com/grafana/agent/component" + "github.com/grafana/agent/component/prometheus/exporter" + "github.com/grafana/agent/pkg/integrations" + "github.com/grafana/agent/pkg/integrations/agent" +) + +func init() { + component.Register(component.Registration{ + Name: "prometheus.exporter.agent", + Args: Arguments{}, + Exports: exporter.Exports{}, + NeedsServices: exporter.RequiredServices(), + Build: exporter.New(createExporter, "agent"), + }) +} + +func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) { + a := args.(Arguments) + return a.Convert().NewIntegration(opts.Logger) +} + +// Arguments holds values which are used to configured the prometheus.exporter.agent component. +type Arguments struct{} + +// Exports holds the values exported by the prometheus.exporter.agent component. +type Exports struct{} + +// DefaultArguments defines the default settings +var DefaultArguments = Arguments{} + +// SetToDefault implements river.Defaulter +func (args *Arguments) SetToDefault() { + *args = DefaultArguments +} + +func (a *Arguments) Convert() *agent.Config { + return &agent.Config{} +} diff --git a/docs/sources/flow/reference/components/prometheus.exporter.agent.md b/docs/sources/flow/reference/components/prometheus.exporter.agent.md new file mode 100644 index 000000000000..174fece7fa2c --- /dev/null +++ b/docs/sources/flow/reference/components/prometheus.exporter.agent.md @@ -0,0 +1,68 @@ +--- +canonical: https://grafana.com/docs/agent/latest/flow/reference/components/prometheus.exporter.agent/ +title: prometheus.exporter.agen +--- + +# prometheus.exporter.agent +The `prometheus.exporter.agent` component collects and exposes metrics about the agent itself. + +## Usage + +```river +prometheus.exporter.agent "agent" { +} +``` + +## Arguments +`prometheus.exporter.agent` accepts no arguments. + +## Exported fields + +{{< docs/shared lookup="flow/reference/components/exporters-component-exports.md" source="agent" version="" >}} + +## Component health + +`prometheus.exporter.agent` is only reported as unhealthy if given +an invalid configuration. + +## Debug information + +`prometheus.exporter.agent` does not expose any component-specific +debug information. + +## Debug metrics + +`prometheus.exporter.agent` does not expose any component-specific +debug metrics. + +## Example + +This example uses a [`prometheus.scrape` component][scrape] to collect metrics +from `prometheus.exporter.agent`: + +```river +prometheus.exporter.agent "agent" {} + +// Configure a prometheus.scrape component to collect agent metrics. +prometheus.scrape "demo" { + targets = prometheus.exporter.agent.example.targets + forward_to = [prometheus.remote_write.demo.receiver] +} + +prometheus.remote_write "demo" { + endpoint { + url = PROMETHEUS_REMOTE_WRITE_URL + + basic_auth { + username = USERNAME + password = PASSWORD + } + } +} +``` +Replace the following: + - `PROMETHEUS_REMOTE_WRITE_URL`: The URL of the Prometheus remote_write-compatible server to send metrics to. + - `USERNAME`: The username to use for authentication to the remote_write API. + - `PASSWORD`: The password to use for authentication to the remote_write API. + +[scrape]: {{< relref "./prometheus.scrape.md" >}} \ No newline at end of file