Updated on 2024-04-30 GMT+08:00

Installing and Configuring Grafana on a Notebook Instance

Prerequisites

  • A running CPU- or GPU-based notebook instance is available.
  • A terminal is opened.

Procedure

  1. Run the following commands in sequence in your terminal to download and install Grafana:
    mkdir -p /home/ma-user/work/grf
    cd /home/ma-user/work/grf
    wget https://dl.grafana.com/oss/release/grafana-9.1.6.linux-amd64.tar.gz
    tar -zxvf grafana-9.1.6.linux-amd64.tar.gz

  2. Register Grafana with jupyter-server-proxy.
    1. Run the following commands in your terminal:
      mkdir -p /home/ma-user/.local/etc/jupyter
      vi /home/ma-user/.local/etc/jupyter/jupyter_notebook_config.py

    1. In jupyter_notebook_config.py, add the following code, press Esc to exit, and type :wq to save the changes:
      c.ServerProxy.servers = {
        'grafana': {
          'command': ['/home/ma-user/work/grf/grafana-9.1.6/bin/grafana-server', '--homepath', '/home/ma-user/work/grf/grafana-9.1.6', 'web'],
          'timeout': 1800,
          'port': 3000
        }
      }

    If jupyter_notebook_config.py (path: /home/ma-user/.local/etc/jupyter/jupyter_notebook_config.py) contains the c.ServerProxy.servers field, add the corresponding key-value pair.

  3. Modify the URL for accessing Grafana in JupyterLab.
    1. In the navigation pane on the left, open the vi /home/ma-user/work/grf/grafana-9.1.6/conf/defaults.ini file.
    1. Change the root_url and serve_from_sub_path fields in [server].
      Figure 1 Modifying the defaults.ini file

      In the file:

      • The value of root_url is in the format of https:{Jupyterlab domain name}/{Instance ID}/grafana. You can obtain the domain name and instance ID from the address box of the JupyterLab page.

      • Set Serve_from_sub_path to true.
  4. Save the image of the notebook instance.
    1. Log in to the ModelArts console and choose DevEnviron > Notebook. In the notebook instance list, choose More > Save Image in the Operation column of the target instance.

    1. In the Save Image dialog box, configure parameters. Click OK to save the image.
      Figure 2 Saving an image
    1. The image will be saved as a snapshot, and it will take about 5 minutes. During this period of time, do not perform any operations on the instance.
      Figure 3 Snapshotting
    2. After the image is saved, the instance status changes to Running. Then, restart the notebook instance.
      Figure 4 Image saved
  5. Open the Grafana page.

    Open a browser window and type the value of root_url configured in 3 in the address box. If the Grafana login page is displayed, Grafana is installed and configured in the notebook instance. The default username and password for the first login are admin. After the login is successful, change the password as prompted.