메인 콘텐츠로 건너뛰기

사용 사례

시간 범위 청사진에서 지원하는 일반적인 시나리오를 살펴보세요:

Serverless Functions

함수 실행 시간과 메모리 사용량을 기준으로 청구합니다.

Container Runtime

사용량 기반 청구를 위해 컨테이너 실행 시간을 추적합니다.

Compute Instances

VM 런타임을 모니터링하고 분 또는 시간 단위로 과금합니다.

Background Jobs

데이터 내보내기, 보고서 및 배치 작업의 처리 시간을 추적합니다.
컴퓨트 시간, 함수 실행 시간, 컨테이너 런타임 또는 기타 시간 기반 사용량을 기준으로 청구할 때 이상적입니다.

빠른 시작

시간 지속에 따라 리소스 사용량을 추적합니다:
1

Install the SDK

npm install @dodopayments/ingestion-blueprints
2

Get Your API Keys

3

Create a Meter

Dodo Payments Dashboard에서 측정기를 생성합니다:
  • Event Name: time_range_usage (또는 원하는 이름)
  • Aggregation Type: sum (총 지속 시간 추적용)
  • Over Property: durationSeconds, durationMinutes 또는 durationMs
4

Track Time Usage

import { Ingestion, trackTimeRange } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'function_execution'
});

// Track function execution time
const startTime = Date.now();

// Execute your function (example: image processing)
const result = await yourImageProcessingLogic();

const durationMs = Date.now() - startTime;

await trackTimeRange(ingestion, {
  customerId: 'customer_123',
  durationMs: durationMs
});

구성

수집 구성

apiKey
string
필수
대시보드에서 가져온 Dodo Payments API 키입니다.
environment
string
필수
환경 모드: test_mode 또는 live_mode.
eventName
string
필수
측정기 구성과 일치하는 이벤트 이름입니다.

시간 범위 추적 옵션

customerId
string
필수
청구 연결을 위한 고객 ID입니다.
durationMs
number
밀리초 단위 지속 시간. 초단위 이하 정밀도에 사용합니다.
durationSeconds
number
초 단위 지속 시간. 함수 실행 및 짧은 작업에 가장 일반적으로 사용됩니다.
durationMinutes
number
분 단위 지속 시간. VM과 같은 장시간 실행 리소스에 유용합니다.
metadata
object
CPU, 메모리, 리전 등 리소스에 대한 선택적 메타데이터입니다.

모범 사례

적절한 단위 선택: 짧은 작업에는 밀리초, 함수에는 초, 장시간 실행 리소스에는 분을 사용하세요.
정확한 시간 측정: 특히 서버리스 함수의 경우 정확한 시간 추적을 위해 Date.now() 또는 performance.now()를 사용하세요.