Quickstart for Cloud Datalab

This Quickstart shows you how to set up Cloud Datalab to use with your Monitoring projects. Cloud Datalab's dynamic notebooks let you perform ad hoc analyses and visualizations that go beyond the present features of Monitoring.

To preview the Monitoring tutorials in Cloud Datalab, see Monitoring tutorials. You cannot interact with the tutorials unless you are running Cloud Datalab.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a GCP project.

    Go to the project selector page

  3. Verifica che la fatturazione sia attivata per il tuo progetto.

    scopri come attivare la fatturazione

  4. Enable the Compute Engine and Cloud Source Repositories APIs.

    Enable the APIs

  5. Install and initialize the Cloud SDK.

Set up Cloud Datalab

Perform the following steps from a terminal window on your local machine:

  1. Get the latest gcloud command:
    gcloud components update
    
  2. Install the gcloud datalab component:
    gcloud components install datalab
    
  3. To configure gcloud to connect to your GCP project ID, run the following command after replacing [PROJECT_ID] with your GCP project ID:

    gcloud config set project [PROJECT_ID]
    

    To verify the configuration, run the following command:

    gcloud config get-value project
    

  4. To create a Cloud Datalab instance, run the following command after replacing [DATALAB-INSTANCE-NAME] with the name of your instance. Names must begin with a lowercase letter, be followed by no more than 62 lowercase letters, numbers, or hyphens, and must not end with a hyphen:

    datalab create [DATALAB-INSTANCE-NAME]
    

    • If prompted, select a zone from the list.
    • If you are asked to set a SSH passphrase, enter a phrase. Be sure to save this passphrase.
    • After a few moments, a message similar to the one below is displayed.

      Created [https://www.googleapis.com/compute/v1/projects/[PROJECT_ID]/zones/[ZONE]/instances/[DATALAB-INSTANCE-NAME]].
      Connecting to [DATALAB-INSTANCE-NAME].
      This will create an SSH tunnel and may prompt you to create an rsa key pair. To manage these keys, see https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys
      Waiting for Datalab to be reachable at http://localhost:8081/
      

      If prompted, enter your passphrase:

      Enter passphrase for key '[...]/.ssh/google_compute_engine':
      

      After a few minutes, the create command completes successfully and a message similar to the one below is displayed:

      The connection to Datalab is now open and will remain until this command is killed.
      You can connect to Datalab at http://localhost:8081/
      

  5. The connection to your Cloud Datalab instance remains open while the datalab command is active. If the terminal command window is closed or interrupted, the connection is terminated. To reestablish the connection, run the following command:

    datalab connect [DATALAB-INSTANCE-NAME]
    

The Cloud Datalab Interface

To view the Cloud Datalab interface, browse to the URL http://127.0.0.1:8081/ or click the following button. If this is the first time you've used Cloud Datalab, you are asked to agree to the terms of service.

Go to your running Cloud Datalab

Cloud Datalab interface

In the Cloud Datalab docs/ folder there are several Cloud Datalab getting started notebooks you can explore, including notebooks for Stackdriver Monitoring.

Cloud Datalab and Stackdriver Monitoring

Monitoring uses Workspaces to organize resources contained in one or more GCP projects. With a Workspace, you can, among other things, create alerts and dashboards, and configure groups. You must create a Workspace to use groups with Cloud Datalab.

We recommend you create a Workspace for your GCP projects. Workspaces are free and easy to create. For details, go to Getting a Workspace quickly.

Monitoring tutorials

Cloud Datalab is installed with several Monitoring interactive tutorials:

Getting started
Shows how to import the Python Stackdriver API into Cloud Datalab and set your default GCP project ID. There is sample code that calls the API and retrieves monitoring data from your project.
Group metrics
Shows how to look at the group structure in a project and how to use groups to filter and aggregate metric data. To use group metrics, you must have a Workspace. If your Workspace doesn't have groups, change to another Workspace that does. For details on how to create a Workspace, go to Getting a Workspace quickly.
Time-shifted data
Shows how to transform time series data in interesting ways. Since your project might not have enough VM instances to be a good example, the tutorial is set up to optionally use previously-extracted data from a demonstration project.

You can run the tutorials, and optionally modify them, as explained in the following section.

Running the tutorials

To run the tutorials, do the following:

  1. Click on docs, tutorials, and Stackdriver Monitoring in the Cloud Datalab interface. You should see the following page:

    Stackdriver tutorials

  2. Select the tutorial. Click on the name of the tutorial you want to run.

  3. Set the project ID: Edit the cell containing set_datalab_project_id('my-project-id') as follows:

    • If you created a Workspace, replace my-project-id with your Workspace name. You must have a Workspace to use group metrics.
    • If you don't have a Workspace, replace my-project-id with your GCP project ID.
  4. Run the tutorial code. From the menu bar at the top of the interface, select Run > Run all cells. This reruns all the code in the tutorial using your current project ID.

Feel free to modify the code in the tutorials and try out your changes. You can run the code in a single cell by clicking on the cell and choosing Run from the menu to the left of the cell. You can also create your own notebooks.

Clean up

To avoid incurring charges to your GCP account for the resources used in this quickstart:

  1. Click on the Running Sessions icon at the top-right of the Cloud Datalab interface, and shut down any notebooks you are not using. You can restart them later if you need to. Close the associated browser tabs or windows.

  2. Enter CTRL-C in the window where Cloud Datalab is running and close the Cloud Datalab tab in your browser.

  3. You incur charges from the time of creation to the time of deletion of the Cloud Datalab VM instance (see Cloud Datalab Pricing). You are also charged for the Persistent Disk where notebooks are stored. The Persistent Disk remains after the deletion of the Cloud Datalab VM until you delete it.

    To delete the Cloud Datalab VM instance and its Persistent Disk, run the following:

    datalab delete --delete-disk [DATALAB-INSTANCE-NAME]
    

  4. There are additional resources are created by the datalab create command that are reused by other Cloud Datalab instances that you create. You can run the following commands to delete the additional resources listed below if you don't expect to create additional Cloud Datalab instances:

    • Delete the datalab-network-allow-ssh firewall rule, which allows SSH connections to your Cloud Datalab instances:
      gcloud compute firewall-rules delete datalab-network-allow-ssh
      
    • Delete the datalab-network Virtual Private Cloud (VPC) network, to which Datalab instances are connected by default:
      gcloud compute networks delete datalab-network
      
    • Delete the datalab-notebooks Cloud Source Repository, which is set up for you to store your notebooks (see Working with notebooks if you wish to backup notebooks before deleting the repo):
      gcloud source repos delete datalab-notebooks
      
  5. If you created any Workspaces, projects, or VM instances that you don't want to keep, remove them.

What's next

See the following API reference material:

Hai trovato utile questa pagina? Facci sapere cosa ne pensi:

Invia feedback per...

Stackdriver Monitoring
Hai bisogno di assistenza? Visita la nostra pagina di assistenza.