Bookmark this page

Guided Exercise: Monitoring 3Scale Infrastructure

In this exercise, you will configure the monitoring of 3scale API Management resources.

Outcomes

You should be able to:

  • Install the Prometheus operator

  • Install the Grafana operator

  • Enable monitoring within a 3scale API Management installation

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start monitoring-infrastructure

Procedure 6.2. Instructions

  1. Review the available metrics by using the APIcast staging pod.

    1. Within a command line terminal, log in as the admin user and select the 3scale project with the oc command. When prompted, use the password redhat.

      [student@workstation ~]$ oc login -u admin https://api.ocp4.example.com:6443
      ...output omitted...
      Login successful.
      ...output omitted...
      [student@workstation ~]$ oc project 3scale
      Now using project "3scale" ...output omitted...
    2. Open a remote shell connection to the APIcast staging pod.

      [student@workstation ~]$ oc rsh svc/apicast-staging
      sh-4.4$ **
    3. Make a request to localhost, which is the APIcast pod itself, to retrieve the list of available metrics.

      sh-4.4$ curl http://localhost:9421/metrics
      ...output omitted...
      nginx_http_connections{state="accepted"} 129
      nginx_http_connections{state="active"} 1
      nginx_http_connections{state="handled"} 129
      ...output omitted...

      Exit the remote shell by running exit or pressing Control-d.

  2. Deploy the Prometheus operator to the 3scale project.

    1. In a web browser, log in to the Red Hat OpenShift Container Platform (RHOCP) web console by using the htpasswd provider, username admin, and password redhat.

      The URL for the RHOCP web console is https://console-openshift-console.apps.ocp4.example.com.

    2. Navigate to OperatorsOperatorHub and search for prometheus.

    3. Make sure the 3scale project is selected by using the Project selection menu at the top of the page.

    4. Click the Prometheus Operator entry and click Install.

    5. Make sure the Installed Namespace is set to 3scale and click Install.

    6. Review the DO240/labs/monitoring-infrastructure/prometheus-3scale-monitor.yml resource file.

      apiVersion: monitoring.coreos.com/v1
      kind: Prometheus
      metadata:
        name: 3scale-monitor
        namespace: 3scale
      spec:
        serviceAccountName: prometheus-k8s
        podMonitorSelector:
         matchExpressions:
         - key: app
           operator: In
           values:
           - 3scale-api-management
        ruleSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - 3scale-api-management

      Applying the preceding resource creates a new Prometheus instance within the 3scale project. This instance watches for pod monitors and Prometheus rules that have the RHOCP label app=3scale-api-management.

    7. Within a command line terminal, apply the prometheus-3scale-monitor.yml file. Make sure you are logged in as the admin user.

      [student@workstation ~]$ oc apply -f \
      DO240/labs/monitoring-infrastructure/prometheus-3scale-monitor.yml
      prometheus.monitoring.coreos.com/3scale-monitor created
  3. Install the Grafana operator to the 3scale project.

    1. Within a web browser, navigate back to OperatorsOperatorHub and search for grafana.

    2. Click the Grafana Operator entry and click Install.

    3. Make sure the Installed Namespace is set to 3scale and click Install.

    4. Review the DO240/labs/monitoring-infrastructure/grafana-3scale.yml file.

      apiVersion: integreatly.org/v1alpha1
      kind: Grafana
      metadata:
        name: grafana
        namespace: 3scale
      spec:
        ingress:
          enabled: True
        config:
          log:
            mode: "console"
            level: "warn"
          auth:
            disable_login_form: False
            disable_signout_menu: True
          auth.anonymous:
            enabled: True
        dashboardLabelSelector:
        - matchExpressions:
          - key: app
            operator: In
            values:
            - 3scale-api-management

      Applying the preceding resource creates a Grafana instance within the 3scale project. This instance also watches for the app=3scale-api-management RHOCP label.

    5. Within a command line terminal, apply the grafana-3scale.yml file. The Grafana operator creates the relevant resources, including a Grafana pod.

      [student@workstation ~]$ oc apply -f \
      DO240/labs/monitoring-infrastructure/grafana-3scale.yml
      grafana.integreatly.org/grafana created
    6. Review the DO240/labs/monitoring-infrastructure/grafana-prometheus-datasource.yml file.

      apiVersion: integreatly.org/v1alpha1
      kind: GrafanaDataSource
      metadata:
        name: prometheus
        namespace: 3scale
      spec:
        name: middleware
        datasources:
          - name: Prometheus
            type: prometheus
            access: proxy
            url: http://prometheus-operated:9090
            isDefault: true
            version: 1
            editable: true
            jsonData:
              timeInterval: "5s"
    7. Apply the grafana-prometheus-datasource.yml file. This creates a new data source that enables Grafana to connect to the Prometheus instance that you created previously.

      [student@workstation ~]$ oc apply -f \
      DO240/labs/monitoring-infrastructure/grafana-prometheus-datasource.yml
      grafanadatasource.integreatly.org/prometheus created
  4. Enable monitoring for 3scale API Management by updating the APImanager.

    1. Observe that no pod monitors or rules exist in the 3scale project.

      [student@workstation ~]$ oc get podmonitors
      No resources found in 3scale namespace.
      [student@workstation ~]$ oc get prometheusrules
      No resources found in 3scale namespace.
    2. Edit the APImanager you created as part of the 3scale API Management set up:

      [student@workstation ~]$ oc edit apimanager apimanager-sample

      This opens an editor to modify the resource definition.

    3. Within the spec definition, add the following snippet:

      ...output omitted...
      spec:
        ...output omitted...
        monitoring:
          enabled: true
        ...output omitted...

      Save and quit the editor to update the APImanager.

    4. Observe that the 3scale API Management operator creates relevant Prometheus resources.

      [student@workstation ~]$ oc get podmonitors
      ...output omitted...
      apicast-production   1s
      apicast-staging      1s
      ...output omitted...
      [student@workstation ~]$ oc get prometheusrules
      ...output omitted...
      apicast                         51s
      backend-listener                52s
      ...output omitted...
  5. View the 3scale API Management metrics within the Grafana web interface.

    1. In a web browser, navigate to https://grafana-route-3scale.apps.ocp4.example.com/dashboards.

    2. Click 3scale to expand the list of available dashboards. Then, click Apicast to view a dashboard showing APIcast metrics.

    3. In the top right of the page, select Last 5 minutes from the selection menu. This makes it easier to see the data because Prometheus does not receive any data until monitoring is enabled.

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish monitoring-infrastructure

This concludes the guided exercise.

Revision: do240-2.11-40390f6