メインコンテンツへスキップ

ユースケース

時間範囲ブループリントでサポートされている一般的なシナリオを探ります:

サーバーレス関数

関数の実行時間とメモリ使用量に基づいて請求します。

コンテナランタイム

使用量に基づく請求のためにコンテナの稼働時間を追跡します。

コンピュートインスタンス

VMの稼働時間を監視し、分または時間単位で請求します。

バックグラウンドジョブ

データエクスポート、レポート、およびバッチジョブの処理時間を追跡します。
コンピュート時間、関数実行時間、コンテナランタイム、または任意の時間ベースの使用に基づく請求に最適です。

クイックスタート

時間の経過に基づいてリソース使用量を追跡します:
1

SDKをインストール

npm install @dodopayments/ingestion-blueprints
2

APIキーを取得

3

メーターを作成

Dodo Payments Dashboardでメーターを作成します:
  • イベント名: time_range_usage(またはお好みの名前)
  • 集計タイプ: sumで合計時間を追跡します
  • プロパティの上に: durationSecondsdurationMinutes、またはdurationMs
4

時間使用量を追跡

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
required
ダッシュボードからのDodo Payments APIキー。
environment
string
required
環境モード:test_modeまたはlive_mode
eventName
string
required
メーター設定に一致するイベント名。

時間範囲オプションの追跡

customerId
string
required
請求の帰属のための顧客ID。
durationMs
number
ミリ秒単位の期間。サブ秒精度に使用します。
durationSeconds
number
秒単位の期間。関数の実行や短いタスクに最も一般的です。
durationMinutes
number
分単位の期間。VMのような長時間実行されるリソースに便利です。
metadata
object
CPU、メモリ、リージョンなどのリソースに関するオプションのメタデータ。

ベストプラクティス

適切な単位を選択: 短い操作にはミリ秒、関数には秒、長時間実行されるリソースには分を使用します。
正確なタイミング: 特にサーバーレス関数の正確な時間追跡には、Date.now()またはperformance.now()を使用してください。