LogoLogo
  • User Guide
    • Getting Started
      • Building a Usage-Based Product in Revenium
      • Setting Up & Using API Analytics & Observability
      • Setting Up & Using Product Analytics
      • Sending Data to Revenium's Metering API
      • Key Concepts & Relationships
    • Connect Your Data
      • cURL Commands for Testing
      • Container-Native Metering
      • Kong
        • Kubernetes Installation
      • Salesforce
        • Revenium Unmanaged Package
          • Anypoint API Experience Hub (AEH)
            • Anypoint API Experience Hub Unmanaged Package Post Installation Instructions
          • Anypoint Community Manager (ACM)
            • Anypoint Community Manager Package Post Installation Instructions
        • Revenium Lightning Web Components
          • Add Components to Experience Cloud site
          • Drop-In Storefront
          • Product Card
          • Product Card (Anypoint)
          • Product Checkout
          • Product Details Button
          • Usage History
          • API Access Requester
      • MuleSoft
        • Metering Policy Configuration
        • Offline Metering Policy Configuration
        • Anypoint API & API Group Synchronization
        • Revenium Connector
        • Disable Default Anypoint Community Manager (ACM) Email Notifications
      • Gravitee
      • Istio
      • Envoy
      • AWS API Gateway
      • Python & Django
      • Golang
      • Spring Boot
      • .Net
      • NodeJs
      • Java/JVM
      • Snowflake
      • Azure API Management
      • IBM
      • Custom Integrations Using Metering Beacons
        • JWT Enrichment
      • Offline Metering via Log Parsing
    • Sources
      • Metering Elements
      • Alerts
        • Alert History
    • API Keys
    • Products & Pricing
      • Product Lines
      • Pricing Rules
        • Revenium Scripting Language
          • RSL Reference
        • Execution Logs
      • SLA Definitions
      • SLA Violation Review
    • Customers
      • Customers
      • Subscribers
      • Subscriptions
      • Subscribers Credentials
      • Subscribers Notifications
    • Billing and Invoicing
      • Manage Refunds
    • Analytics
      • Revenue Analytics
      • Product Analytics
        • Custom Reports (Products)
      • Subscriber Analytics
        • New Subscribers
        • (Daily/Weekly/Monthly) Active Subscribers
        • Most Engaged Subscribers & Customers
        • Historical Usage
      • API Analytics
        • Performance & Availability
        • Compare Periods
        • Traffic by Geography
        • Advanced Search
        • Custom Reports
    • Profile
      • Profile
      • Revenium API Documentation
    • Settings
      • Revenium Users & Organizations
        • Access Permissions by User Type
      • Revenium Subscription
      • Revenium Organizations
      • Notification Templates
      • Transactions Logs
        • Analytics Transaction Log
        • Product Transaction Log
        • Subscription Audit Log
        • No Code Transaction Testing
      • Integrations
        • Data Sync
        • Export Configurations
        • Notification Providers
        • Payment Configurations
          • Customer VAT ID Support
        • ERP Configurations
        • External Integration Logs
        • Identity Providers
      • System Logs
      • Default Configuration Limits
Powered by GitBook

© Revenium - www.revenium.io

On this page
  • Introduction
  • Using the Metering Beacon API
  • Metering Beacon Data Types
  • Examples
  • CURL
  • Kotlin
  • Lua
  1. User Guide
  2. Connect Your Data

Custom Integrations Using Metering Beacons

This guide documents how to write custom integrations to Revenium Metering Beacons.

Last updated 9 months ago

Before investigating a custom integration, we recommend you review our Linux & here, which works in a variety of environments and is configurable with only a few lines of additional code.

Introduction

Revenium Metering Beacons act as bulkheads or “shock absorbers” to collect API transaction telemetry. The telemetry data is buffered in the Metering Beacon’s cache and periodically synchronized to the Revenium Transaction Engine.

Under normal circumstances you should not need to implement custom integrations to the Metering Beacons. Revenium offers out-of-the-box connectivity to most common API Gateways and API platforms, including MuleSoft, Kong, Apigee, Istio, Envoy, Spring Boot and others.

The Revenium Metering Beacon presents a very simple REST API that allows downstream applications, such as API gateway plugins or agents, to send API transaction telemetry via an HTTP POST operation with a JSON payload.

Metering Beacon Architecture

In addition to the REST API Revenium also provides a pre-packaged JVM SDK to simplify integration with JVM based applications (Java, Scala, Clojure, Kotlin, etc.)

The Revenium Metering SDK can be obtained from your Revenium Account Team.

Using the Metering Beacon API

Metering Beacon Data Types

The Metering Beacon API uses the following JSON data types

MeteringRequestDTO

MeteringRequestDTO represents the result of a metered HTTP API transaction. MeteringRequestDTOs are created after the response has been received from a metered API. Use MeteringRequestDTO when you need to meter an API transaction after it has completed. This is used to synchronously meter an API transaction.

Field

Description

api

The Revenium API ID of the metered API

productKey

The Revenium ProductKey ID of the subscriber being billed

method

The HTTP method being called

url

The URL of the API being called

ApiEventDTO

ApiEventDTO represents either the request or response of an HTTP API transaction of a metered API request. ApiEventDTOs are created when the HTTP request is received and when the API response has been completed. This is used to asynchronously meter an API transaction.

Field

Description

requestId

A UUID used to correlate request and response API events

eventType

The type of event, can be either _“REQUEST” _or “RESPONSE”

api

The Revenium API ID of the metered API

productKey

The Revenium ProductKey ID of the subscriber being billed

method

The HTTP method being called

currentMillis

Epoch timestamp of the event in milliseconds

uri

The URL/URI of the API being called

elapsedTime

The elapsed time (in milliseconds) of the event

Metering Beacon Endpoints

The Revenium Beacon API exposes the following endpoints:

Endpoint

Method

Type

Description

/metering/v1/api/meter

POST

MeteringRequestDTO

Insert an API Metering Transaction. This method is used to capture an atomic API request / response in a single class. Use this endpoint when metering API transactions after they’ve completed.

/metering/v1/api/meter

GET

LineItemDTO

Return currently buffered API Metering Requests

/metering/v1/api/event

POST

ApiEventDTO

Insert an API Metering Event. This is used to record API requests and responses independently. Use this endpoint to meter API requests and responses separately. The Metering Beacon will correlate the independent events using the requestId

Revenium uses the /metering/v1/api/meter endpoint to implement metering policies / plugins for traditional API Gateway implementations such as MuleSoft, Kong and Apigee. We use the /metering/v1/api/event to implement metering policies / plugins for cloud API Gateway implementations like AWS and Azure which rely on serverless functionality.

Examples

CURL

Kotlin

This example demonstrates a metering request sent via Kotlin using the Revenium JVM SDK.

val dto = MeteringDTO(apiId, request.getHeader(X-REVENIUM-PRODUCT-KEY), req.method, req.requestURL.toString())

val jsonRequest = mapper.writeValueAsString(dto)

val meteringResponse = client.post().uri(uri!!)
          .body(BodyInserters.fromValue(jsonRequest))
                    .exchange().block()
if (!meteringResponse!!.statusCode().is2xxSuccessful) {
    logger.warn("Failure POSTing metering data to $meteringUrl (${meteringResponse.statusCode()}):" +
                                " ${meteringResponse.bodyToMono<String>()}\n" + jsonRequest)
        }
}

Lua

This example demonstrates a metering request sent via Lua using the REST API.

function envoy_on_response(response_handle)
    local api_client = response_handle:streamInfo():dynamicMetadata():get("revenium")["api_client"]
    local status = tonumber(response_handle:headers():get(":status"))
    if (api_client ~= nil and (status >= 200 and status <= 299)) then
        local method = response_handle:streamInfo():dynamicMetadata():get("revenium")["method"]
        local path = response_handle:streamInfo():dynamicMetadata():get("revenium")["path"]
        local scheme = response_handle:streamInfo():dynamicMetadata():get("revenium")["scheme"]
        local api = response_handle:metadata():get("revenium")
        local body = "api=" .. api .. "&productKey=" .. api_client .. "&method=" .. method .. "&url=" .. path
        local headers, response_body = response_handle:httpCall("revenium",
            {
                [":method"] = "POST",
                [":path"] = "/",
                [":authority"] = "revenium",
            },
            body, 5000)
        local ps_status = tonumber(headers[":status"])
        if (ps_status > 200 or ps_status > 299) then
            response_handle:logError("Could not post body to metering beacon: " .. body)
        else
            response_handle:logDebug("Successfully posted body to metering beacon: " .. body)
        end
    end
end

The full Metering Beacon API documentation is located here:

The detailed example shows how to use CURL to send metering requests via the command line.

https://revenium.readme.io/reference/meter
on this page
container-native metering solution