Skip to content

Commit

Permalink
documents fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed May 5, 2023
1 parent d91b3b8 commit 607d827
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion component/prometheus/source/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c *Component) createNewServer(args Arguments) (error, *fnet.TargetServer)

s, err := fnet.NewTargetServer(
c.opts.Logger,
"agent_prometheus_source_api",
"prometheus_source_api",
serverRegistry,
args.Server,
)
Expand Down
62 changes: 39 additions & 23 deletions docs/sources/flow/reference/components/prometheus.source.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,59 @@ The HTTP API exposed is compatible with [Prometheus `remote_write` API][promethe
## Usage

```river
prometheus.source.api LABEL {
http_address = "LISTEN_ADDRESS"
http_port = PORT
forward_to = RECEIVER_LIST
prometheus.source.api "LABEL" {
http {
listen_address = "LISTEN_ADDRESS"
listen_port = PORT
}
forward_to = RECEIVER_LIST
}
```

The component will listen for HTTP POST requests on `/api/v1/metrics/write` path. The request format must match that of [Prometheus `remote_write` API][prometheus-remote-write-docs]. One way to send valid requests to this component is to use Grafana Agent with a [`prometheus.remote_write`][prometheus.remote_write] component.
The component will start HTTP server supporting the following requests:

- POST on `/api/v1/metrics/write` - Send metrics to the component, which in turn will be forwarded to the receivers as configured in `forward_to` argument. The request format must match that of [Prometheus `remote_write` API][prometheus-remote-write-docs]. One way to send valid requests to this component is to use another Grafana Agent with a [`prometheus.remote_write`][prometheus.remote_write] component.

## Arguments

`prometheus.source.api` supports the following arguments:

Name | Type | Description | Default | Required
----------------|------------------|----------------------------------------------------|---------|----------
`http_port` | `int` | The host port for the HTTP server to listen on. | | yes
`http_address` | `string` | The host address for the HTTP server to listen on. | | yes
`forward_to` | `list(receiver)` | List of receivers to send metrics to. | | yes
Name | Type | Description | Default | Required
--------------|------------------|---------------------------------------|---------|----------
`forward_to` | `list(receiver)` | List of receivers to send metrics to. | | yes

## Blocks

The following blocks are supported inside the definition of `prometheus.source.api`:

Hierarchy | Name | Description | Required
-----------|----------|----------------------------------------------------|----------
`http` | [http][] | Configures the HTTP server that receives requests. | no

[http]: #http

### http

{{< docs/shared lookup="flow/reference/components/loki-server-http.md" source="agent" >}}

## Exported fields

`prometheus.source.api` does not export any fields.

## Component health

`prometheus.source.api` is reported as unhealthy if:

- it is given an invalid configuration
- embedded server exits with an error
`prometheus.source.api` is reported as unhealthy if it is given an invalid configuration.

## Debug metrics

The following are some of the metrics that are exposed when this component is used. Note that the metrics include labels such as `status_code` where relevant, which can be used to measure request success rates.

* `agent_prometheus_source_api_request_duration_seconds` (histogram): Time (in seconds) spent serving HTTP requests.
* `agent_prometheus_source_api_request_message_bytes` (histogram): Size (in bytes) of messages received in the request.
* `agent_prometheus_source_api_response_message_bytes` (histogram): Size (in bytes) of messages sent in response.
* `agent_prometheus_source_api_tcp_connections` (gauge): Current number of accepted TCP connections.
* `prometheus_source_api_request_duration_seconds` (histogram): Time (in seconds) spent serving HTTP requests.
* `prometheus_source_api_request_message_bytes` (histogram): Size (in bytes) of messages received in the request.
* `prometheus_source_api_response_message_bytes` (histogram): Size (in bytes) of messages sent in response.
* `prometheus_source_api_tcp_connections` (gauge): Current number of accepted TCP connections.
* `agent_prometheus_fanout_latency` (histogram): Write latency for sending metrics to other components.
* `agent_prometheus_forwarded_samples_total` (counter): Total number of samples sent to downstream components.

## Example

Expand All @@ -61,9 +75,11 @@ This example creates a `prometheus.source.api` component which starts an HTTP se
```river
// Receives metrics over HTTP
prometheus.source.api "api" {
http_address = "0.0.0.0"
http_port = 9999
forward_to = [prometheus.remote_write.local.receiver]
http {
listen_address = "0.0.0.0"
listen_port = 9999
}
forward_to = [prometheus.remote_write.local.receiver]
}
// Writes metrics to a specified address, e.g. cloud-hosted Prometheus instance
Expand All @@ -74,7 +90,7 @@ prometheus.remote_write "local" {
}
```

In order to send metrics to the `prometheus.source.api` component defined above, another agent can be run with the following configuration:
In order to send metrics to the `prometheus.source.api` component defined above, another Grafana Agent can run with the following configuration:

```river
// Collects metrics of localhost:12345
Expand All @@ -85,7 +101,7 @@ prometheus.scrape "agent_self" {
forward_to = [prometheus.remote_write.local.receiver]
}
// Writes metrics to localhost:9999/api/v1/metrics/write - served by
// Writes metrics to localhost:9999/api/v1/metrics/write - e.g. served by
// the prometheus.source.api component from the example above.
prometheus.remote_write "local" {
endpoint {
Expand Down

0 comments on commit 607d827

Please sign in to comment.