Obtenir des informations sur l'instance

Cette page explique comment lister toutes les instances d'un projet et obtenir des détails sur les instances de manière programmatique à l'aide des bibliothèques clientes Bigtable ou manuellement à l'aide de la consoleGoogle Cloud , de Google Cloud CLI ou de la CLI cbt :

Répertorier les instances

Pour obtenir la liste des instances, procédez comme suit :

Console

  1. Dans la console Google Cloud , ouvrez la liste des instances Bigtable.

    Ouvrir la liste des instances

    La page Instances affiche la liste des instances.

gcloud

Utilisez la commande bigtable instances list pour afficher la liste des instances :

  gcloud bigtable instances list

cbt

Utilisez la commande listinstances pour afficher la liste des instances :

  cbt listinstances

C++

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Project;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
   std::string const& project_id) {
  std::string project_name = Project(project_id).FullName();
  StatusOr<google::bigtable::admin::v2::ListInstancesResponse> instances =
      instance_admin.ListInstances(project_name);
  if (!instances) throw std::move(instances).status();
  for (auto const& instance : instances->instances()) {
    std::cout << instance.name() << "\n";
  }
  if (!instances->failed_locations().empty()) {
    std::cout << "The Cloud Bigtable service reports that the following "
                 "locations are temporarily unavailable and no information "
                 "about instances in these locations can be obtained:\n";
    for (auto const& failed_location : instances->failed_locations()) {
      std::cout << failed_location << "\n";
    }
  }
}

C#

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

// Lists instances in the project.
// Initialize request argument(s).
ListInstancesRequest listInstancesRequest = new ListInstancesRequest
{
    ParentAsProjectName = new ProjectName(projectId)
};
try
{
    // Make a request.
    Console.WriteLine("Waiting for operation to complete...");
    ListInstancesResponse instances = bigtableInstanceAdminClient.ListInstances(listInstancesRequest);
}
catch (Exception ex)
{
    Console.WriteLine($"Exception while requesting information about instances in {projectId} project");
    Console.WriteLine(ex.Message);
    return -1;
}
Console.WriteLine(new string('-', 50));

Go

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.


import (
	"context"
	"fmt"
	"io"

	bigtableadmin "cloud.google.com/go/bigtable/admin/apiv2"
	bigtableadminpb "google.golang.org/genproto/googleapis/bigtable/admin/v2"
)

// listInstances lists Cloud Bigtable instances in a project.
func listInstances(ctx context.Context, w io.Writer, projectID string) error {
	parent := fmt.Sprintf("projects/%s", projectID)

	client, err := bigtableadmin.NewBigtableInstanceAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("NewBigtableInstanceAdminClient failed: %w", err)
	}
	defer client.Close()

	req := &bigtableadminpb.ListInstancesRequest{
		Parent: parent,
	}

	resp, err := client.ListInstances(ctx, req)
	if err != nil {
		return fmt.Errorf("ListInstances failed: %w", err)
	}

	for _, instance := range resp.GetInstances() {
		fmt.Fprintf(w, "Instance: %s\n", instance.GetName())
	}

	return nil
}

Java

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.


import com.google.bigtable.admin.v2.Instance;
import com.google.bigtable.admin.v2.ListInstancesRequest;
import com.google.bigtable.admin.v2.ListInstancesResponse;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClientV2;
import java.io.IOException;

public class ListInstances {

  /** Lists all Cloud Bigtable instances in the specified project. */
  public static void listInstances(String projectId) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // String projectId = "my-project-id";

    try (BigtableInstanceAdminClientV2 adminClient = BigtableInstanceAdminClientV2.create()) {
      String parent = "projects/" + projectId;
      ListInstancesRequest request = ListInstancesRequest.newBuilder().setParent(parent).build();
      ListInstancesResponse response = adminClient.listInstances(request);
      for (Instance instance : response.getInstancesList()) {
        System.out.println(instance.getName());
      }
    }
  }
}

Node.js

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

'use strict';

const {v2} = require('@google-cloud/bigtable');
const {BigtableInstanceAdminClient} = v2;
const {status} = require('@grpc/grpc-js');

const client = new BigtableInstanceAdminClient();

/**
 * Lists Bigtable instances in a Google Cloud project.
 *
 * @param {string} projectId - The Google Cloud project ID.
 */
async function listInstances(projectId) {
  try {
    const parent = `projects/${projectId}`;
    const [instances] = await client.listInstances({
      parent,
    });

    const instanceList = Array.isArray(instances)
      ? instances
      : instances?.instances || [];

    for (const instance of instanceList) {
      console.log(`Instance: ${instance.name}`);
      console.log(`Display name: ${instance.displayName}`);
      console.log(`State: ${instance.state}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Resource not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied: ${err.message}`);
    } else {
      console.error(`Failed to list instances: ${err.message}`);
    }
  }
}

module.exports = {listInstances};

PHP

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ListInstancesRequest;

/**
 * List Bigtable instances in a project
 *
 * @param string $projectId The Google Cloud project ID
 */
function list_instance(string $projectId): void
{
    $instanceAdminClient = new BigtableInstanceAdminClient();

    $projectName = $instanceAdminClient->projectName($projectId);

    printf('Listing Instances:' . PHP_EOL);
    $listInstancesRequest = (new ListInstancesRequest())
        ->setParent($projectName);

    $getInstances = $instanceAdminClient->listInstances($listInstancesRequest)->getInstances();
    $instances = $getInstances->getIterator();

    foreach ($instances as $instance) {
        print($instance->getName() . PHP_EOL);
    }
}

Python asyncio

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableInstanceAdminAsyncClient() as client:
    project_path = client.common_project_path(project_id)

    print("\nListing instances:")
    instances_response = await client.list_instances(parent=project_path)
    for instance in instances_response.instances:
        print(instance.name.split("/")[-1])

Python

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableInstanceAdminClient()
project_path = client.common_project_path(project_id)

print("\nListing instances:")
instances_response = client.list_instances(parent=project_path)
for instance in instances_response.instances:
    print(instance.name.split("/")[-1])

Ruby

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

bigtable.instances.all do |instance|
  puts "Instance: #{instance.instance_id}"
end

Obtenir les détails de l'instance

Pour obtenir des détails sur une instance, procédez comme suit :

Console

  1. Dans la console Google Cloud , ouvrez la liste des instances Bigtable.

    Ouvrir la liste des instances

  2. Cliquez sur l'instance dont vous souhaitez afficher les détails.

    La page Présentation de l'instance affiche des informations détaillées sur l'instance, telles que l'ID, le nom, le type de stockage, l'utilisation du processeur et l'édition.

gcloud

Exécutez la commande bigtable instances describe pour afficher les détails d'une instance :

    gcloud bigtable instances describe INSTANCE_ID

Remplacez les éléments suivants :

  • INSTANCE_ID : identifiant permanent de l'instance.

cbt

Utilisez la commande listclusters pour afficher les détails d'une instance :

    cbt listclusters INSTANCE_ID

Remplacez les éléments suivants :

  • INSTANCE_ID : identifiant permanent de l'instance.

C++

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
   std::string const& project_id, std::string const& instance_id) {
  std::string instance_name = cbt::InstanceName(project_id, instance_id);
  StatusOr<google::bigtable::admin::v2::Instance> instance =
      instance_admin.GetInstance(instance_name);
  if (!instance) throw std::move(instance).status();
  std::cout << "GetInstance details : " << instance->DebugString() << "\n";
}

C#

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

// Initialize request argument(s).
GetInstanceRequest request = new GetInstanceRequest
{
    InstanceName = new InstanceName(projectId, instanceId)
};
try
{
    // Make Request.
    Console.WriteLine("Waiting for operation to complete...");
    Instance respond = bigtableInstanceAdminClient.GetInstance(request);
}
catch (Exception ex)
{
    Console.WriteLine($"Exception retreiving {instanceId} instance");
    Console.WriteLine(ex.Message);
}

Java

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

Instance instance = null;
try {
  String name = "projects/" + projectId + "/instances/" + instanceId;
  GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name).build();
  instance = adminClient.getInstance(request);
  System.out.println("Instance ID: " + instance.getName());
  System.out.println("Display Name: " + instance.getDisplayName());
  System.out.print("Labels: ");
  Map<String, String> labels = instance.getLabelsMap();
  for (String key : labels.keySet()) {
    System.out.printf("%s - %s", key, labels.get(key));
  }
  System.out.println("\nState: " + instance.getState());
  System.out.println("Type: " + instance.getType());
} catch (NotFoundException e) {
  System.err.println("Failed to get non-existent instance: " + e.getMessage());
}

Node.js

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2;
const instanceAdminClient = new BigtableInstanceAdminClient();
const projectId = await instanceAdminClient.getProjectId();
const [instance2] = await instanceAdminClient.getInstance({
  name: `projects/${projectId}/instances/${instanceID}`,
});
console.log(`Instance ID: ${instance2.name}`);
console.log(`Instance Meta: ${JSON.stringify(instance2.labels)}`);

PHP

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

use Google\ApiCore\ApiException;
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\GetInstanceRequest;
use Google\Cloud\Bigtable\Admin\V2\Instance\State;
use Google\Cloud\Bigtable\Admin\V2\Instance\Type;

/**
 * Get a Bigtable instance
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance
 */
function get_instance(
    string $projectId,
    string $instanceId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);

    printf('Fetching the Instance %s' . PHP_EOL, $instanceId);
    try {
        $getInstanceRequest = (new GetInstanceRequest())
            ->setName($instanceName);
        $instance = $instanceAdminClient->getInstance($getInstanceRequest);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Instance %s does not exists.' . PHP_EOL, $instanceId);
            return;
        }
        throw $e;
    }

    printf('Printing Details:' . PHP_EOL);

    // Fetch some commonly used metadata
    printf('Name: ' . $instance->getName() . PHP_EOL);
    printf('Display Name: ' . $instance->getDisplayName() . PHP_EOL);
    printf('State: ' . State::name($instance->getState()) . PHP_EOL);
    printf('Type: ' . Type::name($instance->getType()) . PHP_EOL);
    printf('Labels: ' . PHP_EOL);

    $labels = $instance->getLabels();

    // Labels are an object of the MapField class which implement the IteratorAggregate, Countable
    // and ArrayAccess interfaces so you can do the following:
    printf("\tNum of Labels: " . $labels->count() . PHP_EOL);
    printf("\tLabel with a key(dev-label): " . ($labels['dev-label'] ?? 'N/A') . PHP_EOL);

    // we can even loop over all the labels
    foreach ($labels as $key => $val) {
        printf("\t$key: $val" . PHP_EOL);
    }
}

Python asyncio

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableInstanceAdminAsyncClient() as client:
    instance_path = client.instance_path(project_id, instance_id)

    inst = await client.get_instance(name=instance_path)
    print(f"\nName of instance: {inst.display_name}\nLabels: {dict(inst.labels)}")

Python

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableInstanceAdminClient()
instance_path = client.instance_path(project_id, instance_id)

inst = client.get_instance(name=instance_path)
print(f"\nName of instance: {inst.display_name}\nLabels: {dict(inst.labels)}")

Ruby

Pour savoir comment installer et utiliser la bibliothèque cliente pour Bigtable, consultez la section Bibliothèques clientes Bigtable.

Pour vous authentifier auprès de Bigtable, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

# instance_id = "my-instance"
instance = bigtable.instance instance_id
puts "Get Instance id: #{instance.instance_id}"

Étapes suivantes