Skip to main content
Version: Next

Metrics Setup

The Metrics Setup page provides step-by-step guidance on configuring and monitoring key metrics in Lunar.dev’s API Consumption Gateway. Lunar.dev supports exporting these metrics to popular monitoring tools such as Datadog, Grafana, and Prometheus for real-time tracking and analysis of API traffic and system performance.

Why Metrics Matter

Tracking and analyzing API traffic and system performance metrics is essential for optimizing API usage, ensuring system health, and diagnosing issues. By exposing these metrics, Lunar.dev helps you maintain a comprehensive view of your API operations and system health, allowing you to act quickly when needed.


Default Metrics Configuration

Lunar.dev’s default metrics configuration auto-exposes metrics via the /metrics endpoint on port 3000. These metrics can be viewed or integrated with monitoring tools by editing the metrics.yaml file found at /etc/lunar-proxy/metrics.yaml.

The file is organized into two primary categories:

  1. General Metrics: Track API traffic with labels like http_method, url, status_code, and consumer_tag.
  2. System Metrics: Monitor internal flow efficiency and performance with metrics such as active_flows and flow_invocations.

Template metrics.yaml File

Below is an example template for configuring your metrics.yaml file. You can customize the metrics according to your needs, adding new labels or adjusting the types of metrics as required.

general_metrics:
label_value:
- http_method
- url
- status_code
- consumer_tag # Allows tracking of consumer-specific API usage

metric_value:
- name: api_call_count
type: counter # Tracks the number of API calls made
- name: api_call_size
type: gauge # Measures the size of each API request

system_metrics:
- name: active_flows
type: gauge # Tracks the number of active flows
- name: flow_invocations
type: counter # Counts how many times a flow is invoked
- name: requests_through_flows
type: counter # Tracks the number of requests passing through all flows
- name: avg_flow_execution_time
type: gauge # Measures the average execution time of each flow
- name: avg_processor_execution_time
type: gauge # Measures the average execution time of each processor within a flow

Example Metrics Configuration

In the default setup, metrics are auto-exposed at the /metrics endpoint on port 3000. Here’s how the two key metric categories are structured:

  1. General Metrics

    These provide insights into API traffic patterns and performance across different labels like http_method, url, status_code, and consumer_tag.

    • Metrics:
      • api_call_count (Counter): Total number of API calls.
      • api_call_size (Gauge): Tracks the size of each API call.
  2. System Metrics

    These focus on the internal performance of the Lunar Gateway, helping to monitor the efficiency of flows and processors.

    • Metrics:
      • active_flows (Gauge): Number of active flows at any time.
      • flow_invocations (Counter): How many times flows have been invoked.
      • requests_through_flows (Counter): Total number of requests passing through flows.
      • avg_flow_execution_time (Gauge): Average time taken to execute each flow.
      • avg_processor_execution_time (Gauge): Average time for processors within a flow.

Next Steps: Integrating with Monitoring Tools

Once you’ve customized your metrics configuration, you can integrate it with popular tools like Grafana, Prometheus, or Datadog for real-time visualization and analysis.

For Prometheus Integration, visit the Prometheus Integration page for detailed instructions on how to set up scraping for your metrics. This guide will walk you through the steps to configure Prometheus to pull data from the Lunar.dev API Consumption Gateway’s /metrics endpoint and display it in your preferred dashboard tool.


Need Help?

If you encounter issues or need further assistance, feel free to reach out to our support team, or refer to the Prometheus Integration page for specific instructions.

CTRL + M