@bmatei/apollo-prometheus-exporter

中文文档
3.0.0发布于 2023/11/23MITTypeScriptCommonJS零依赖近 30 天下载 3.9万

Plugin for Apollo Server to export metrics in Prometheus format

原始使用文档
文档目录4 节
  1. Metrics
  2. Usage
  3. Options
  4. Thanks

Apollo Prometheus Exporter

GitHub Workflow Status npm

Plugin for Apollo Server to export metrics in Prometheus format.

It uses prom-client under the hood the export the metrics.

Since Apollo Server released a new major version, a new version (v2.x.y) of the exporter has been launched. Apollo Server v2 is still supported in v1.x.y. The two versions will be features-matched as much as possible.

Metrics

NameDescriptionType
apollo_server_startingThe last timestamp when Apollo Server was starting.Gauge
apollo_server_closingThe last timestamp when Apollo Server was closing.Gauge
apollo_query_startedThe amount of received queries.Counter
apollo_query_failedThe amount of queries that failed.Counter
apollo_query_parse_startedThe amount of queries for which parsing has started.Counter
apollo_query_parse_failedThe amount of queries for which parsing has failed.Counter
apollo_query_validation_startedThe amount of queries for which validation has started.Counter
apollo_query_validation_failedThe amount of queries for which validation has failed.Counter
apollo_query_resolvedThe amount of queries which could be resolved.Counter
apollo_query_execution_startedThe amount of queries for which execution has started.Counter
apollo_query_execution_failedThe amount of queries for which execution has failed.Counter
apollo_query_durationThe total duration of a query.Histogram
apollo_query_field_resolution_durationThe total duration for resolving fields.Histogram

For default metrics, please refer to prom-client default metrics.

Usage

  1. Install prom-client and @bmatei/apollo-prometheus-exporter

    npm install prom-client @bmatei/apollo-prometheus-exporter
    
  2. Create an instance of the plugin

    const app = express();
    
    const prometheusExporterPlugin = createPrometheusExporterPlugin({ app });
    
  3. Add the plugin to ApolloServer

    const server = new ApolloServer({
      plugins: [prometheusExporterPlugin]
    });
    

For a complete working example, please have a look over the example project in this repository.

Options

NameDescriptionTypeDefault Value
appExpress instance. For the moment it is used for defining the metrics endpoint. It is mandatory unless metricsEndpoint is set to false.Expressundefined
defaultLabelsAn object containing default labels to be sent with each metric.Object{}
defaultMetricsFlag to enable/disable the default metrics registered by prom-client.Booleantrue
defaultMetricsOptionsConfiguration object for the default metrics.DefaultMetricsCollectorConfiguration{}
durationHistogramBucketsA list of durations that should be used by histograms.number[][0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1, 5, 10]
hostnameLabelFlag to enable/disable hostname label.Booleantrue
hostnameLabelNameThe name of the hostname label.Stringhostname
metricsEndpointFlag to enable/disable the metrics endpoint. If you disable this, you can use the registerPrometheusMetricsEndpoint method to enable the metrics endpoint.Booleantrue
metricsEndpointPathHTTP path where the metrics will be published.String"/metrics"
registerPrometheus client registry to be used by Apollo Metrics. By default, it is also used by the default metrics.Registryregister
skipMetricsA key-value map that controls if a metric is enabled or disabled.SkipMetricsMap{}

Thanks

版本与发布记录

@bmatei/apollo-prometheus-exporter 共发布 13 个版本,首次发布于 2020/12/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.0latest2023/11/232 年前
2.1.12021/10/235 年前
1.3.1release-1.x2021/10/235 年前
1.3.02021/10/125 年前
2.1.02021/10/125 年前
2.0.02021/10/125 年前

关于 @bmatei/apollo-prometheus-exporter 的常见问题

@bmatei/apollo-prometheus-exporter 是什么?

Plugin for Apollo Server to export metrics in Prometheus format

如何安装 @bmatei/apollo-prometheus-exporter?

在项目目录运行 npm install @bmatei/apollo-prometheus-exporter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:prom-client(^12.0.0 || ^13.0.0 || ^14.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bmatei/apollo-prometheus-exporter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bmatei/apollo-prometheus-exporter 支持 ESM 还是 CommonJS?

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

@bmatei/apollo-prometheus-exporter 可以商用吗?

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

@bmatei/apollo-prometheus-exporter 的下载量有多少?

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

@bmatei/apollo-prometheus-exporter 还在维护吗?

最新版本 3.0.0 发布于 2023/11/23(2 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/12/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。