SMI Traffic Metrics

How to set up and view SMI traffic metrics

Overview

Traffic Metrics are a mechanism through which you can view important information about your running workloads. Exposed by the SMI spec, this allows you to migrate functionality from your existing service mesh. The NGINX Service Mesh creates an extension API Server and shim that queries Prometheus and returns the results in a traffic metrics format. You can access these metrics through a variety of methods ranging from the nginx-meshctl tool to querying the Kubernetes API manually.

Traffic Metrics depends on Prometheus to get the critical service information needed to visualize your applications.

Important:
In version 1.5, NGINX Service Mesh won’t deploy Prometheus. Refer to the Monitoring and Tracing guide for instructions on using your own servers with NGINX Service Mesh.
Note:
You can configure NGINX Service Mesh to use a different Prometheus server when deploying. Refer to the Monitoring and Tracing task for instructions.

If you are deploying NGINX Plus Ingress Controller with the NGINX Service Mesh, make sure to configure the NGINX Plus Ingress Controller to export metrics. Refer to the Metrics section of the NGINX Plus Ingress Controller Deployment tutorial for instructions.

How to View Traffic Metrics

There are multiple ways you can view the traffic metrics generated by NGINX Service Mesh.

Note:
Occasionally metrics are reset when the nginx-mesh-sidecar reloads NGINX Plus. If traffic is flowing and you fail to see metrics, retry after 30 seconds.

nginx-meshctl top

The nginx-meshctl top command uses traffic metrics to give information at a glance of traffic currently flowing through the mesh. An example output looks like this:

$ nginx-meshctl top

Deployment      Incoming Success  Outgoing Success  NumRequests
productpage-v1  100.00%           100.00%           221
reviews-v2      100.00%           100.00%           112
reviews-v3      100.00%           100.00%           110
reviews-v1      100.00%                             54
details-v1      100.00%                             165
ratings-v1      100.00%                             54

You can also view additional golden metrics and edge information by specifying a specific resource in the top command. An example of this is:

$ nginx-meshctl top deployments/productpage-v1

Deployment      Direction  Resource            Success Rate  P99    P90   P50   NumRequests
productpage-v1
                To         reviews-v2          100.00%       91ms   22ms  15ms  54
                To         details-v1          100.00%       15ms   4ms   2ms   160
                To         reviews-v1          100.00%       91ms   16ms  5ms   54
                To         reviews-v3          100.00%       183ms  20ms  14ms  52
                From       nginx-plus-ingress  100.00%       183ms  47ms  31ms  161
Note:
A success rate of <nil> means that traffic metrics are still populating. Send additional traffic and wait for success rate to properly appear.

Raw

To view individual traffic metrics, use the kubectl get command shown below.

kubectl get --raw /apis/metrics.smi-spec.io/v1alpha1/namespaces/default/deployments/reviews-v3/edges

The output looks similar to that shown below.

{
  "kind": "TrafficMetricsList",
  "apiVersion": "metrics.smi-spec.io/v1alpha1",
  "metadata": {
    "selfLink": "/apis/metrics.smi-spec.io/v1alpha1/namespaces/default/deployments/reviews-v3/edges"
  },
  "resource": {
    "kind": "Deployment",
    "namespace": "default",
    "name": "reviews-v3"
  },
  "items": [
    {
      "kind": "TrafficMetrics",
      "apiVersion": "metrics.smi-spec.io/v1alpha1",
      "metadata": {
        "name": "reviews-v3",
        "namespace": "default",
        "selfLink": "/apis/metrics.smi-spec.io/v1alpha1/namespaces/default/deployments/reviews-v3/edges",
        "creationTimestamp": "2019-10-16T22:33:02Z"
      },
      "timestamp": "2019-10-16T22:33:02Z",
      "window": "30s",
      "resource": {
        "kind": "Deployment",
        "namespace": "default",
        "name": "reviews-v3"
      },
      "edge": {
        "direction": "to",
        "resource": {
          "kind": "Deployment",
          "namespace": "default",
          "name": "ratings-v1"
        }
      },
      "metrics": [
        {
          "name": "p99_response_latency",
          "unit": "ms",
          "value": "2969m"
        },
        {
          "name": "p90_response_latency",
          "unit": "ms",
          "value": "2700m"
        },
        {
          "name": "p50_response_latency",
          "unit": "ms",
          "value": "1499m"
        },
        {
          "name": "success_count",
          "value": "9"
        },
        {
          "name": "failure_count",
          "value": "0"
        }
      ]
    },
    {
      "kind": "TrafficMetrics",
      "apiVersion": "metrics.smi-spec.io/v1alpha1",
      "metadata": {
        "name": "reviews-v3",
        "namespace": "default",
        "selfLink": "/apis/metrics.smi-spec.io/v1alpha1/namespaces/default/deployments/reviews-v3/edges",
        "creationTimestamp": "2019-10-16T22:33:02Z"
      },
      "timestamp": "2019-10-16T22:33:02Z",
      "window": "30s",
      "resource": {
        "kind": "Deployment",
        "namespace": "default",
        "name": "reviews-v3"
      },
      "edge": {
        "direction": "from",
        "resource": {
          "kind": "Deployment",
          "namespace": "default",
          "name": "productpage-v1"
        }
      },
      "metrics": [
        {
          "name": "p99_response_latency",
          "unit": "ms",
          "value": "29600m"
        },
        {
          "name": "p90_response_latency",
          "unit": "ms",
          "value": "26"
        },
        {
          "name": "p50_response_latency",
          "unit": "ms",
          "value": "13333m"
        },
        {
          "name": "success_count",
          "value": "11"
        },
        {
          "name": "failure_count",
          "value": "0"
        }
      ]
    }
  ]
}
Supported Metrics Endpoints

NGINX Service Mesh supports the SMI-spec endpoints shown in the table below.

Endpoint Description
/apis/metrics.smi-spec.io/v1alpha1/ gets supported resource kinds.
…/namespaces retrieves generic information for traffic between namespaces.
…/namespaces/{namespace} retrieves generic information for traffic to and from a particular namespace.
…/namespaces/{namespace}/edges retrieves specific information for traffic to and from a particular namespace.
…/namespaces/{namespace}/{resourceKind} retrieves generic information for traffic between resourceKind types.
…/namespace/{namespace}/{resourceKind}/{resourceName} retrieves generic information for traffic between named resource of specified kind.
…/namespace/{namespace}/{resourceKind}/{resourceName}/edges retrieves specific edge information to and from named resource of specified kind.