Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/yellow-symbols-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@naverpay/prometheus-core": major
"@naverpay/prometheus-hono": major
"@naverpay/prometheus-koa": major
---

add @naverpay/prometheus-hono

PR: [add @naverpay/prometheus-hono](https://github.com/NaverPayDev/prometheus/pull/7)
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @naverpay/prometheus

Prometheus 메트릭 수집 및 내보내기를 위한 TypeScript 라이브러리 모음입니다. PM2 클러스터링 환경에서의 메트릭 수집을 지원하며, Koa 및 Next.js 프레임워크와의 통합을 제공합니다.
Prometheus 메트릭 수집 및 내보내기를 위한 TypeScript 라이브러리 모음입니다. PM2 클러스터링 환경에서의 메트릭 수집을 지원하며, Koa, Hono 및 Next.js 프레임워크와의 통합을 제공합니다.

## 패키지 구조

Expand All @@ -16,7 +16,7 @@ Prometheus 메트릭 수집 및 내보내기를 위한 TypeScript 라이브러
- PM2 프로세스 간 메트릭 수집 및 집계
- Next.js 라우트 정규화
- HTTP 상태 코드 그룹화
- 기본 Node.js 메트릭 수집
- 기본 Node.js 메트릭 수집 (기본값: true)

### 📦 [@naverpay/prometheus-koa](./packages/koa)

Expand All @@ -29,6 +29,17 @@ Koa.js 프레임워크용 Prometheus 미들웨어 및 라우터를 제공합니
- API 트레이싱 미들웨어
- 요청 경로 정규화 지원

### 📦 [@naverpay/prometheus-hono](./packages/hono)

Hono 프레임워크용 Prometheus 미들웨어 및 라우터를 제공합니다.

**주요 기능:**

- HTTP 요청 메트릭 수집 미들웨어
- 메트릭 엔드포인트 라우터
- API 트레이싱 미들웨어
- 요청 경로 정규화 지원

### 📦 [@naverpay/prometheus-next](./packages/next)

Next.js 애플리케이션용 통합 서버 솔루션을 제공합니다.
Expand All @@ -50,6 +61,9 @@ npm install @naverpay/prometheus-core
# Koa 사용 시
npm install @naverpay/prometheus-koa

# Hono 사용 시
npm install @naverpay/prometheus-hono

# Next.js 사용 시
npm install @naverpay/prometheus-next
```
Expand Down
20 changes: 18 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ PM2 연결을 해제하고 메트릭 레지스트리를 초기화합니다.
await pm2Connector.disconnect()
```

### Standalone 메트릭

#### `getStandaloneMetrics()`

PM2 없이 단일 프로세스에서 메트릭을 수집합니다.

```typescript
import { getStandaloneMetrics } from '@naverpay/prometheus-core'

const { metrics, contentType } = await getStandaloneMetrics()
console.log(metrics) // Prometheus 형식의 메트릭 문자열
console.log(contentType) // 'text/plain; version=0.0.4; charset=utf-8'
```

### Next.js 유틸리티

#### `getNextRoutesManifest()`
Expand Down Expand Up @@ -268,8 +282,10 @@ async function handleRequest(req, res) {

```typescript
interface CommonPrometheusExporterOptions {
/** PM2 클러스터링 지원 활성화 여부 */
pm2: boolean
/** 메트릭 수집 활성화 여부 (기본값: true) */
enabled?: boolean
/** PM2 클러스터링 지원 활성화 여부 (기본값: false) */
pm2?: boolean
/** Next.js 라우트 정규화 활성화 여부 */
nextjs?: boolean
/** 메트릭 엔드포인트 경로 */
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './constants'
export * from './histogram'
export * from './metrics/collect'
export * from './metrics/pm2-connector'
export * from './metrics/standalone'
export * from './metrics/util'
export * from './pm2/messages'
export * from './pm2/promisify'
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/metrics/standalone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import promClient from 'prom-client'

/**
* Gets metrics from prom-client registry for standalone (non-PM2) mode
* @returns Promise resolving to metrics string and content type
*/
export async function getStandaloneMetrics() {
const metrics = await promClient.register.metrics()
return {metrics, contentType: promClient.register.contentType}
}
6 changes: 4 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** Common configuration options for Prometheus exporters */
export interface CommonPrometheusExporterOptions {
/** Whether to enable PM2 clustering support */
pm2: boolean
/** Whether to enable metrics collection (default: true) */
enabled?: boolean
/** Whether to enable PM2 clustering support for aggregating metrics across workers */
pm2?: boolean
/** Whether to enable Next.js route normalization */
nextjs?: boolean
/** Custom path for metrics endpoint */
Expand Down
Loading