Use the Recommender CLI and API

Network Analyzer uses Recommender commands. Recommender is a Google Cloud service that provides usage recommendations for Google Cloud products and services. For a complete list of Recommender insight types, see the Recommender insight types.

Request insights

gcloud

To list insights for a Google Cloud project, run the following command:

gcloud recommender insights list \
    --project=PROJECT_ID \
    --location=LOCATION \
    --insight-type=INSIGHT_TYPE \
    --filter=EXPRESSION \
    --limit=LIMIT \
    --page-size=PAGE_SIZE \
    --sort-by=SORT_BY \
    --format=json

Replace the following:

  • PROJECT_ID: the project ID that you want to list insights for. You can also list all insights for a folder, organization, or a billing account.
  • LOCATION: the location to list insights for, such as global, europe, asia-east1, or us-central1-a.
  • INSIGHT_TYPE: the Network Analyzer insight type to request, such as google.networkanalyzer.vpcnetwork.connectivityInsight.

    For a complete list of insight types, see Insight groups and types.

The following fields are optional:

  • EXPRESSION: apply this Boolean filter to each resource that you want to list.

    If the expression evaluates as True, that item is listed. For more details and examples of filter expressions, run $ gcloud topic filters or see the gcloud topic filters documentation.

  • LIMIT: the maximum number of resources to list; the default number of resources listed is unlimited.

  • PAGE_SIZE: the maximum number of resources to list per page.

    The default page size is determined by the service; otherwise, there is no paging. Paging might be applied before or after FILTER and LIMIT.

  • SORT_BY: a list of comma-separated field key names to sort by for a resource.

    The default order is ascending. To specify a descending order, prefix a field with ~ (a tilde).

API

To get insights for a Google Cloud project, make a GET request to the projects.locations.insightTypes.insights method:

https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/insightTypes/INSIGHT_TYPE/insights

Replace the following:

  • PROJECT_ID: the project ID.
  • LOCATION: the location to list insights for, such as global, europe, asia-east1, or us-central1-a.
  • INSIGHT_TYPE: the Network Analyzer insight type to list, such as google.networkanalyzer.vpcnetwork.connectivityInsight.

    For a complete list of insight types, see Insight groups and types.

The following example shows a sample response for this command:

{
  "name": "projects/{project_number}/locations/{location}/insightTypes/google.networkanalyzer.hybridconnectivity.dynamicRouteInsight/insights/{insight_id}",
  "description": "Dynamic route is fully shadowed by a peering subnet route",
  "content": {
    "networkUri": "//compute.googleapis.com/projects/{project_id}/global/networks/{network_name}",
    "region": "{location}",
    "ipRange": "{ip_range}",
    "priority": 100,
    "nextHopUri": "//compute.googleapis.com/projects/{project_id}/regions/{location}/vpnTunnels/{tunnel_name}",
    "cloudRouterUri": "//compute.googleapis.com/projects/{project_id}/regions/{location}/routers/{router_name}",
    "shadowingRouteUris": [
      "//compute.googleapis.com/projects/{project_id}/global/routes/{route_name}"
    ],
    "shadowingRouteType": "PEERING_SUBNET"
  },
  "lastRefreshTime": "2022-09-15T21:10:57.187942979Z",
  "observationPeriod": "611870.625920374s",
  "stateInfo": {
    "state": "ACTIVE"
  },
  "category": "PERFORMANCE",
  "targetResources": [
    "//compute.googleapis.com/projects/{project_id}/regions/{location}/vpnTunnels/{tunnel_name}"
  ],
  "insightSubtype": "DYNAMIC_ROUTE_FULLY_SHADOWED",
  "severity": "MEDIUM"
}

Describe insight details

gcloud

To list details of a particular insight, run the following command:

gcloud recommender insights describe INSIGHT_ID \
    --project=PROJECT_ID \
    --location=LOCATION \
    --insight-type=INSIGHT_TYPE

Replace the following:

  • INSIGHT_ID: the ID of the insight to describe.
  • PROJECT_ID: the ID of the project containing the insight.
  • LOCATION: the location to list insights for.
  • INSIGHT_TYPE: the Network Analyzer insight type of the insight, such as google.networkanalyzer.vpcnetwork.connectivityInsight.

    For a complete list of insight types, see Insight groups and types.

API

To get details for an insight, make a GET request to the projects.locations.insightTypes.insights method:

https://recommender.googleapis.com/v1/projects/PROJECT/locations/LOCATION/insightTypes/INSIGHT_TYPE/insights/INSIGHT_ID

Replace the following:

  • PROJECT_ID: the project ID.
  • LOCATION: the location of the insight.
  • INSIGHT_TYPE: the Network Analyzer insight type of the insight, such as google.networkanalyzer.vpcnetwork.connectivityInsight.

    For a complete list of insight types, see Insight groups and types.

  • INSIGHT_ID: the insight ID for the insight.

Insight groups and types

For more information about Network Analyzer insights, see Insight groups and types.