> For the complete documentation index, see [llms.txt](https://ilogtail.gitbook.io/ilogtail-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ilogtail.gitbook.io/ilogtail-docs/pre-release/plugins/shu-chu-cha-jian/kuo-zhan-shu-chu-cha-jian/flusher-prometheus.md).

# Prometheus

## 简介

`flusher_prometheus` `flusher`插件可以实现将采集到的数据，经过处理后，通过http格式发送到指定的 Prometheus RemoteWrite 地址。 参数配置大部分继承`flusher_http`，详见[flusher\_http](/ilogtail-docs/pre-release/plugins/shu-chu-cha-jian/kuo-zhan-shu-chu-cha-jian/flusher-http.md)。

## 事件能力

列含义见 [概览 · 事件能力列说明](https://ilogtail.gitbook.io/ilogtail-docs/pre-release/plugins/shu-chu-cha-jian/kuo-zhan-shu-chu-cha-jian/pages/V3l051tHPlzCBkmzOfvu#事件能力列说明)。

| v1 接口 | v2 接口 | Log | Metric | Span |
| ----- | ----- | --- | ------ | ---- |
| —     | ✓     | —   | v2     | —    |

## 版本

[Alpha](/ilogtail-docs/pre-release/plugins/stability-level.md)

## 版本说明

* 推荐版本：LoongCollector v3.0.5 及以上

## 配置参数

| 参数                     | 类型                  | 是否必选 | 说明                                                                                                                                                                                                                                                                              |
| ---------------------- | ------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type                   | string              | 是    | 插件类型，固定为`flusher_prometheus`                                                                                                                                                                                                                                                    |
| Endpoint               | string              | 是    | 要发送到的URL地址，遵从Prometheus RemoteWrite协议，示例：`http://localhost:8086/api/v1/write`                                                                                                                                                                                                   |
| SeriesLimit            | int                 | 否    | 一次序列化 Prometheus RemoteWrite 请求的时间序列的最大长度，默认1000                                                                                                                                                                                                                                |
| Headers                | Map\<string,string> | 否    | <p>发送时附加的http请求header，如可添加 Authorization、Content-Type等信息，支持动态变量写法，如<code>{"x-db":"%{tag.db}"}</code></p><p>v2版本支持从Group的Metadata或者Group.Tags中获取动态变量，如<code>{"x-db":"%{metadata.db}"}</code>或者<code>{"x-db":"%{tag.db}"}</code></p><p>默认注入prometheus相关的Header（e.g. snappy压缩）</p> |
| Query                  | Map\<string,string> | 否    | <p>发送时附加到url上的query参数，支持动态变量写法，如<code>{"db":"%{tag.db}"}</code></p><p>v2版本支持从Group的Metadata或者Group.Tags中获取动态变量，如<code>{"db":"%{metadata.db}"}</code>或者<code>{"db":"%{tag.db}"}</code></p>                                                                                       |
| Timeout                | string              | 否    | 请求的超时时间，默认 `60s`                                                                                                                                                                                                                                                                |
| Retry.Enable           | bool                | 否    | 是否开启失败重试，默认为 `true`                                                                                                                                                                                                                                                             |
| Retry.MaxRetryTimes    | int                 | 否    | 最大重试次数，默认为 `3`                                                                                                                                                                                                                                                                  |
| Retry.InitialDelay     | string              | 否    | 首次重试时间间隔，默认为 `1s`，重试间隔以会2的倍数递增                                                                                                                                                                                                                                                  |
| Retry.MaxDelay         | string              | 否    | 最大重试时间间隔，默认为 `30s`                                                                                                                                                                                                                                                              |
| Concurrency            | int                 | 否    | 向url发起请求的并发数，默认为`1`                                                                                                                                                                                                                                                             |
| MaxConnsPerHost        | int                 | 否    | 每个host上的最大HTTP连接数（包含了拨号阶段的、活跃的、空闲的），默认`50`                                                                                                                                                                                                                                      |
| MaxIdleConnsPerHost    | int                 | 否    | 每个host上的最大空闲的HTTP连接数，默认`50`                                                                                                                                                                                                                                                     |
| IdleConnTimeout        | string              | 否    | <p>HTTP连接在关闭前保持闲置状态的最长时间，默认<code>90s</code></p><p>当其值大于http.DefaultTransport.(\*http.Transport).IdleConnTimeout时（当前是<code>90s</code>），会采用该值</p>                                                                                                                                 |
| WriteBufferSize        | int                 | 否    | 写缓冲区的大小，默认`64KB`                                                                                                                                                                                                                                                                |
| QueueCapacity          | int                 | 否    | 内部channel的缓存大小，默认为1024                                                                                                                                                                                                                                                          |
| Authenticator          | Struct              | 否    | 鉴权扩展插件配置                                                                                                                                                                                                                                                                        |
| Authenticator.Type     | string              | 否    | 鉴权扩展插件类型                                                                                                                                                                                                                                                                        |
| Authenticator.Options  | Map\<string,Struct> | 否    | 鉴权扩展插件配置内容                                                                                                                                                                                                                                                                      |
| AsyncIntercept         | bool                | 否    | 异步过滤数据，默认为否                                                                                                                                                                                                                                                                     |
| DropEventWhenQueueFull | bool                | 否    | 当队列满时是否丢弃数据，否则需要等待，默认为丢弃                                                                                                                                                                                                                                                        |

## 样例

采集Prometheus指标，并将指标以Prometheus协议发送到`PROMETHEUS_REMOTEWRITE_ADDRESS`。 这里用到了`ext_default_encoder`插件（默认集成，无需用户手动配置），该插件可以配置使用Prometheus Encoder，从而支持将采集到的数据转换为Prometheus协议。

```yaml
enable: true
global:
  StructureType: v2
inputs:
- Type: service_prometheus
  ConfigFilePath: '/etc/prometheus/prometheus.yml'
flushers:
- Type: flusher_prometheus
  Endpoint: 'http://PROMETHEUS_REMOTEWRITE_ADDRESS/api/v1/write'
  Concurrency: 10
  QueueCapacity: 4096
  DropEventWhenQueueFull: true
  Authenticator:
    Type: ext_basicauth
extensions:
- Type: ext_basicauth
  Username: 'YOUR_USERNAME'
  Password: 'YOUR_PASSWORD'
```
