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
Review the available metrics by using the APIcast staging pod.
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 3scaleNow using project "3scale" ...output omitted...
Open a remote shell connection to the APIcast staging pod.
[student@workstation ~]$ oc rsh svc/apicast-staging
sh-4.4$ **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.
Deploy the Prometheus operator to the 3scale project.
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.
Navigate to → and search for prometheus.
Make sure the 3scale project is selected by using the selection menu at the top of the page.
Click the entry and click .
Make sure the Installed Namespace is set to 3scale and click .
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-managementApplying 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.
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 createdInstall the Grafana operator to the 3scale project.
Within a web browser, navigate back to → and search for grafana.
Click the entry and click .
Make sure the Installed Namespace is set to 3scale and click .
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-managementApplying the preceding resource creates a Grafana instance within the 3scale project.
This instance also watches for the app=3scale-api-management RHOCP label.
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 createdReview 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"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 createdEnable monitoring for 3scale API Management by updating the APImanager.
Observe that no pod monitors or rules exist in the 3scale project.
[student@workstation ~]$oc get podmonitorsNo resources found in 3scale namespace. [student@workstation ~]$oc get prometheusrulesNo resources found in 3scale namespace.
Edit the APImanager you created as part of the 3scale API Management set up:
[student@workstation ~]$ oc edit apimanager apimanager-sampleThis opens an editor to modify the resource definition.
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.
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...
View the 3scale API Management metrics within the Grafana web interface.
In a web browser, navigate to https://grafana-route-3scale.apps.ocp4.example.com/dashboards.
Click to expand the list of available dashboards. Then, click to view a dashboard showing APIcast metrics.
In the top right of the page, select from the selection menu. This makes it easier to see the data because Prometheus does not receive any data until monitoring is enabled.
This concludes the guided exercise.