Skip to content

Commit

Permalink
feat(exporter): add Flow component for agent Integration (#5072)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* feat(comp/agent): allow defining multiple blocks of agent's Prom exporter

---------

Co-authored-by: Clayton Cornell <[email protected]>
  • Loading branch information
hainenber and clayton-cornell authored Sep 20, 2023
1 parent 5373c94 commit f8e42f3
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions component/prometheus/exporter/agent/agent.go
Original file line number Diff line number Diff line change
@@ -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{}
}
Original file line number Diff line number Diff line change
@@ -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="<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" >}}

0 comments on commit f8e42f3

Please sign in to comment.