@emartech/aggregate-metric-logger

中文文档
6.7.6发布于 2026/11/02MITTypeScriptCommonJS近 30 天下载 2860

aggregate metrics in memory for logging

原始使用文档
文档目录5 节
  1. Setup
  2. Usage
  3. Count occurrences
  4. Measure values
  5. Measuring durations

aggregate-metric-logger

Aggregate metrics in memory and send them to GCP them every minute.

Setup

Set METRIC_LOGGER_ENABLED env variable to true for aggregate-metric-logger to start collecting and logging measurements.

Set MONITORING_PROJECT_ID and GCP_CREDENTIALS env variables. HOSTNAME env variable also has to be set, but for a pod running on kubernetes this should already be set.

Add Monitoring Metrics Writer Role to the service account in the GCP project.

Usage

Count occurrences

const metricLogger = require('@emartech/aggregate-metric-logger')

metricLogger.count('etwas-went-wrong', { customer_id: 11 });
metricLogger.count('etwas-went-wrong', { customer_id: 11 });

// will aggregate these to a single metric

Measure values

If you want aggregate measurements about something you need to simply call the measure method for each value:

const metricLogger = require('@emartech/aggregate-metric-logger')

metricLogger.measure('thing-to-measure', 14, { customer_id: 12 })
metricLogger.measure('thing-to-measure', 20, { customer_id: 44 })

Measuring durations

For duration measurements, there are two convenient methods: start, and stop;

You start the measurement with start, the counted value for aggregation will be the duration between this start and the matching stop call;

function exampleIOHeavyFunction() {
  const measurement = metricLogger.start('tag-for-the-measuement', { customer_id: 23 });
  const result = db.findItems();
  metricLogger.stop(measurement);
  return result;
}

版本与发布记录

@emartech/aggregate-metric-logger 共发布 46 个版本,首次发布于 2022/04/06;过去 12 个月发布了 14 个版本。

版本发布日期距今
6.7.6latest2026/11/0211 天前
6.7.52026/11/0211 天前
6.7.42026/10/3014 天前
6.7.32026/10/3014 天前
6.7.22026/10/3014 天前
6.7.12026/10/3014 天前

关于 @emartech/aggregate-metric-logger 的常见问题

@emartech/aggregate-metric-logger 是什么?

aggregate metrics in memory for logging

如何安装 @emartech/aggregate-metric-logger?

在项目目录运行 npm install @emartech/aggregate-metric-logger,或使用 pnpm add / yarn add / bun add。

@emartech/aggregate-metric-logger 支持 TypeScript 吗?

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

@emartech/aggregate-metric-logger 支持 ESM 还是 CommonJS?

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

@emartech/aggregate-metric-logger 可以商用吗?

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

@emartech/aggregate-metric-logger 的下载量有多少?

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

@emartech/aggregate-metric-logger 还在维护吗?

最新版本 6.7.6 发布于 2026/11/02(11 天前);至今共发布 46 个版本,其中过去 12 个月发布了 14 个;首次发布于 2022/04/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。