# @echo-health/koa-prometheus-exporter 中文文档

规范地址：https://npmcn.com/package/%40echo-health/koa-prometheus-exporter/

版本：1\.0\.4
npm 元数据更新时间：2025-12-05T16:33:21.049Z
中文译文更新时间：2026-11-13T04:58:53.682Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40echo-health/koa-prometheus-exporter
原文对照：https://npmcn.com/package/%40echo-health/koa-prometheus-exporter/?lang=original
项目主页：https://github.com/echo-health/koa-prometheus-exporter#readme
源码仓库：https://github.com/echo-health/koa-prometheus-exporter

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：16.3 kB，11 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=8\.11\.0
- 运行依赖：3 个
- 首次发布：2017-10-03T12:22:32.257Z
- 最新版本发布：2019-06-07T08:49:13.470Z
- 近 30 天下载量：2745（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：13（近 12 个月 0 个）

## 中文简介

暂无中文简介

## 安装

```sh
npm install @echo-health/koa-prometheus-exporter
```

也可以使用：`pnpm add @echo-health/koa-prometheus-exporter`、`yarn add @echo-health/koa-prometheus-exporter`、`bun add @echo-health/koa-prometheus-exporter`

## README

# koa - prometheus - 出口商

□ 安装

需要 koa 运行

使用 npm

```
npm install @echo-health/koa-prometheus-exporter
```

要使用 pridetheus 中间dlware 模块导出一个名为 async 中间软件的函数 `middleware`

譬如说.

```
const Koa = require('koa');
const prometheus = require('koa-prometheus-exporter');
const app = new Koa();

// middleware is a function that returns the middleware async 
// function, this is so you can pass configuration settings into
// the middleware.
app.use(prometheus.middleware({}));
```

选项可以传递到中间软件.

```
Name: path
Type: String
Desciption: overrides the path the middleware listens on.
e.g. "/overriden_path_to_export_metrics_on

Name: headerBlacklist: 
Type: Array
Description: will block any access to the metrics path if the
request has a header in this list
e.g. ["x-forwarded-for"]
```

这将截取路径/ 度量, 并导出默认值 [舞会客户](https://github.com/siimon/prom-client) 节点的度量,加上通过 [节点正反相](https://github.com/SimenB/node-prometheus-gc-stats)

如果您想要添加额外的衡量标准,您可以通过两种方式访问客户端.

`const client = require('koa-prometheus-exporter').client;`

指的是强调舞会客户模块.

同一客户端也通过Ctx objet被通过中间软件链被活塞而暴露出. 因此,任何中间器件都可以在波波斯之后使用。 包含中间软件.

```
const Koa = require('koa');
const prometheus = require('koa-prometheus-exporter');
const app = new Koa();

app.use(prometheus.middleware());
app.use(async (ctx, next) => {
    const counter = ctx.state.prometheus.Counter('counter', 'counter');
    counter.inc();
})
```

□ 跟踪 HTTP 计量

如果您想要跟踪 HTTP 度量衡, 您可以添加一个额外的中件 .

```
const Koa = require('koa');
const prometheus = require('koa-prometheus-exporter');
const app = new Koa();

// this has to be before any other middleware if you want accurate timing of request duration.
app.use(prometheus.httpMetricMiddleware());
app.use(prometheus.middleware());
```

XQO 选项可以传递到中间软件

```
Name: httpTimingDisable
Type: Boolean
Desciption: turns off tracking HTTP timing information, histograms are expensive and can produce a lot of data.
e.g. true
```

```
Name: pathTransform
Type: function
Desciption: Can transform the path before it's set as the URI label. This is important if you're submitting unbounded metrics like rest API's with id's in the path. You need to strip this out to make sure you don't make a very large amount of unique metrics.
e.g.
function(path) {
    if (path && path.includes("/")) {
        return `/${path.split("/")[1]}`;
    }
    return p;
}
```

```
Name: httpTimingBuckets: 
Type: Array
Description: Override the histogram buckets used to track quantiles, this is so you can specify your own bucket configuration. 
Defaault: array produced by calling require('prom-client').exponentialBuckets(0.05, 1.3, 20)
e.g. [
  0.05,
  0.065,
  0.0845,
  0.10985000000000002,
  0.14280500000000002,
  0.18564650000000002,
  0.24134045000000004,
  0.3137425850000001,
  0.4078653605000001,
  0.5302249686500001,
  0.6892924592450002,
  0.8960801970185003,
  1.1649042561240504,
  1.5143755329612656,
  1.9686881928496454,
  2.559294650704539,
  3.327083045915901,
  4.325207959690672,
  5.622770347597873,
  7.309601451877235
]
```

这暴露出四个标准:

```
 - name: http_server_requests_seconds
   type: Histogram
 - name: http_request_size_bytes
   type: Summary
 - name: http_response_size_bytes
   type: Summary
 - name: http_requests_total
   type: Counter
```

这些镜像是同一种由Paletheus服务器本身输出的HTTP度量衡.

## 常见问题

### 如何安装 @echo-health/koa-prometheus-exporter？

在项目目录运行 npm install @echo-health/koa-prometheus-exporter，或使用 pnpm add / yarn add / bun add。

### @echo-health/koa-prometheus-exporter 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/echo-health\_\_koa-prometheus-exporter 是否存在。

### @echo-health/koa-prometheus-exporter 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @echo-health/koa-prometheus-exporter 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=8\.11\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @echo-health/koa-prometheus-exporter 可以商用吗？

@echo-health/koa-prometheus-exporter 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @echo-health/koa-prometheus-exporter 的下载量有多少？

根据 npm 官方下载统计，@echo-health/koa-prometheus-exporter 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,745 次，日均约 92 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @echo-health/koa-prometheus-exporter 还在维护吗？

最新版本 1\.0\.4 发布于 2019/06/07（7 年前）；至今共发布 13 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/10/03。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

