Quickstart for Datalab

This Quickstart shows you how to set up Datalab to use with your Monitoring projects. 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 Datalab, see Monitoring tutorials. You cannot interact with the tutorials unless you are running 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. In the Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.

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

    Enable the APIs

  5. Install and initialize the Cloud SDK.

Set up 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 Google Cloud project ID, run the following command after replacing [PROJECT_ID] with your Google Cloud 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 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 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 Datalab Interface

To view the 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 Datalab, you are asked to agree to the terms of service.

Go to your running Datalab

Datalab interface

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

Datalab and Stackdriver Monitoring

Monitoring uses Workspaces to organize resources contained in one or more Google Cloud 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 Datalab.

We recommend you create a Workspace for your Google Cloud projects. Workspaces are free and easy to create. For details, go to Creating a single-project Workspace.

Monitoring tutorials

Datalab is installed with several Monitoring interactive tutorials:

Getting started
Shows how to import the Python Stackdriver API into Datalab and set your default Google Cloud 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 Creating a single-project Workspace.
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 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 Google Cloud 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 Google Cloud account for the resources used in this quickstart, follow these steps.

  1. Click on the Running Sessions icon at the top-right of the 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 Datalab is running and close the Datalab tab in your browser.

  3. You incur charges from the time of creation to the time of deletion of the 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 Datalab VM until you delete it.

    To delete the 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 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 Datalab instances:

    • Delete the datalab-network-allow-ssh firewall rule, which allows SSH connections to your 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:

Was this page helpful? Let us know how we did:

Send feedback about...

Stackdriver Monitoring
Need help? Visit our support page.