Skip to main content

Metrics

Metrics provide aggregated, quantitative data about the performance and behavior of an API over time. They offer insights into the overall health of the system. Here’s how you can leverage metrics for API observability:
  • Key Performance Indicators (KPIs): Define and track essential metrics such as request rate, response time, error rate and resource utilization to monitor the overall health and performance of the API.
  • Custom Metrics: Create custom metrics that are specific to your API’s functionality or business objectives. For example, track the number of successful payments processed or the number of users signed up.
  • Threshold Alerts: Set up alerts based on predefined thresholds for metrics to receive notifications when API performance deviates from the expected norm.
  • Trend Analysis: Analyze metric trends over time to identify long-term performance patterns, plan for scaling and detect anomalies.
Tyk Dashboard offers a traffic analytics function that provides insights into API usage, traffic patterns and response times. The built-in metrics allow you to track overall API traffic, detailed API analytics including: request count, response time distribution and error rates. API usage can be tracked on a per-client (per-key) basis. This analysis uses the traffic logs generated by Tyk Gateway from API requests and responses. Tyk Pump is used to aggregate and transfer the logs to Tyk Dashboard’s aggregate analytics storage. You can also use Tyk Pump to export those metrics to different back-ends. Here is an example of using Tyk Pump to send API analytics metrics to Prometheus and Grafana. You can also leverage the OpenTelemetry spans exported from Tyk Gateway to calculate and export span metrics from the OpenTelemetry collector.

Metric Collection

Metrics collection and analysis are key components of an Observability strategy, providing real-time insight into system behaviour and performance. Tyk Gateway, Pump and Dashboard have been instrumented for StatsD monitoring. Additionally, Tyk Gateway has also been instrumented for New Relic metrics.

StatsD Instrumentation

StatsD is a network daemon that listens for statistics, like counters and timers, sent over UDP or TCP and sends aggregates to one or more pluggable backend services. It’s a simple yet powerful tool for collecting and aggregating application metrics.

Configuring StatsD instrumentation

To enable instrumentation for StatsD, you must set the environment variable: TYK_INSTRUMENTATION=1 and then configure the statsd_connection_string field for each component. statsd_connection_string is a formatted string that specifies how to connect to the StatsD server. It typically includes information such as the host address, port number, and sometimes additional configuration options. Optionally you can set statsd_prefix to a custom prefix value that will be applied to each metric generated by Tyk. For example, you can configure separate prefixes for your production and staging environments to make it easier to differentiate between the metrics in your analysis tool.

StatsD Keys

There are plenty of keys (metrics) available when you enable the StatsD instrumentation, but these are the basics:
  • API traffic handled by Gateway: gauges.<prefix>.Load.rps (requests per second)
  • Tyk Gateway API: counters.<prefix>.SystemAPICall.called.count (calls count) and timers.<prefix>.SystemAPICall.success (response time)
  • Tyk Dashboard API: counters.<prefix>.SystemAPICall.SystemCallComplete.count (requests count), counters.<prefix>.DashSystemAPIError.* (API error reporting)
  • Tyk Pump records: counters.<prefix>.record.count (number of records processed by pump)

New Relic Instrumentation

Tyk Gateway has been instrumented for New Relic metrics since v2.5. Simply add the following config section to tyk.conf to enable the instrumentation and generation of data:
{
  "newrelic": {
    "app_name": "<app-name>",
    "license_key": "<license_key>"
  }
}