Configuring OpenShift monitoring in Unified Agent

When you deploy the Unified Agent, you can select to install OpenShift plug-in to monitor OpenShift route traffic performance and router performance. The plug-in monitors each route response time, volume and error, and also integrates with Kubernetes data collector to enable exploring the associated services and application data.

Procedure

To deploy the Unified Agent with OpenShift monitoring, you need to create a script and then run the script to get all the required variables for CR configuration.

  1. Create a script. Copy the following text to a script and name it as router_discovery.sh:
    #!/bin/bash
    OCPVERSION=$1
    function ocp4() {
     dpname=$(oc get deploy -n ${ROUTERNS} -L ${routerLabel}|grep -v NAME|awk '{print $1}')
     res=$(oc describe deploy $dpname -n ${ROUTERNS}|grep STATS_USERNAME|cut -d':' -f 2)
     susername=$(echo $res|cut -d"'" -f 2);suserkey=$(echo $res|cut -d"'" -f 4)
     res=$(oc describe deploy $dpname -n ${ROUTERNS}|grep STATS_PASSWORD|cut -d':' -f 2)
     spassname=$(echo $res|cut -d"'" -f 2); spasskey=$(echo $res|cut -d"'" -f 4)
     username=$(oc get secret ${suserkey} -n ${ROUTERNS} -o=jsonpath='{.data.'"$susername"' }'|base64 -d)
     password=$(oc get secret ${spasskey} -n ${ROUTERNS} -o=jsonpath='{.data.'"$spassname"' }'|base64 -d)
     port=$(oc describe deploy $dpname -n ${ROUTERNS}|grep STATS_PORT|cut -d':' -f 2|sed -e 's/^[[:space:]]*//')
     echo "  routernamespace: $ROUTERNS"
     echo "  podcpulimit: $(oc get deploy $dpname -n ${ROUTERNS} -o=jsonpath='{.spec.template.spec.containers[0].resources.requests.cpu}')"
     echo "  podmemlimit: $(oc get deploy $dpname -n ${ROUTERNS} -o=jsonpath='{.spec.template.spec.containers[0].resources.requests.memory}')"
    }
    function ocp3() {
     dpname=$rn
     username=$(oc describe rc $dpname -n ${ROUTERNS}|grep STATS_USERNAME|cut -d':' -f 2|sed -e 's/^[[:space:]]*//')
     password=$(oc describe rc $dpname -n ${ROUTERNS}|grep STATS_PASSWORD|cut -d':' -f 2|sed -e 's/^[[:space:]]*//')
     port=$(oc describe rc $dpname -n ${ROUTERNS}|grep STATS_PORT|cut -d':' -f 2|sed -e 's/^[[:space:]]*//')
     echo "  routernamespace: $ROUTERNS"
     echo "  routercpulimit: $(oc get rc $dpname -n ${ROUTERNS} -o=jsonpath='{.spec.template.spec.containers[0].resources.requests.cpu}')"
     echo "  routermemlimit: $(oc get rc $dpname -n ${ROUTERNS} -o=jsonpath='{.spec.template.spec.containers[0].resources.requests.memory}')"
    }
    if [[ "$OCPVERSION" == "ocp3" ]];then
      ROUTERNS=default
      ROUTERSELECTOR=router
      routerlist=$(oc get rc -n ${ROUTERNS} -l ${ROUTERSELECTOR}|grep -v NAME|awk '{print $1}')
    else if [[ "$OCPVERSION" == "ocp4" ]];then
      ROUTERNS=openshift-ingress
      ROUTERSELECTOR=ingresscontroller.operator.openshift.io/owning-ingresscontroller
      routerlist=$(oc get svc -n ${ROUTERNS} -l ${ROUTERSELECTOR}|grep -v NAME|awk '{print $1}')
      else echo "not supported version: $OCPVERSION";exit;fi;fi
    ocpid=`kubectl cluster-info |grep https|cut -d' ' -f 6|sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"`
    CID=`echo -n $ocpid|md5sum|awk '{print $1}'`;echo; echo " cid: $CID";echo
    for rn in $routerlist;do
     if [[ "$OCPVERSION" == "ocp3" ]];then routerLabel=$(oc describe rc ${rn} -n ${ROUTERNS} |grep "Selector:"|awk '{print $2}')
     else if [[ "$OCPVERSION" == "ocp4" ]];then routerLabel=$(oc describe svc ${rn} -n ${ROUTERNS} |grep "Selector:"|awk '{print $2}');fi;fi
     podlist=$(oc get pod -o wide -n ${ROUTERNS} -l ${routerLabel} 2>/dev/null|grep -v 'NAME'|awk '{print $1}')
     if [[ "$podlist" == "" ]]; then continue;fi
     echo "routername: $rn"
     if [[ "$OCPVERSION" == "ocp3" ]];then ocp3; else if [[ "$OCPVERSION" == "ocp4" ]];then ocp4; fi; fi
      echo "  POD list:"
      for pn in $podlist; do echo "    routerpod: $pn";echo "    MetricsURL: http://${username}:${password}@$(oc get pod $pn -o wide -n ${ROUTERNS}|grep -v 'NAME'|awk '{print $6}' 2>&1):${port}/metrics";done
    done
    
  2. Run the script to get the required configuration parameters:
    # ./router_discovery.sh ocp4  # or ocp3 for ocp3  env
    
  3. You can get the following output. The information of the output is needed when you configure OpenShift plug-in CR in step 6.
     cid: 59d32a90add5658cdc884d900820e12d
    routername: router-internal-default
      routernamespace: openshift-ingress
      podcpulimit: 100m
      podmemlimit: 256Mi
      POD list:
        router-default-77b8ddc78-2q6pp
        MetricsURL: http://dXNlcmpra2Nz:cGFzc2J3Zjh2@10.16.51.225:1936/metrics
        router-default-77b8ddc78-gtj2m
        MetricsURL: http://dXNlcmpra2Nz:cGFzc2J3Zjh2@10.16.51.229:1936/metrics
    
  4. Edit the ua-openshift CR by running the following command:
    kubectl edit UA ua-openshift
    
  5. Locate the section of [[inputs.openshift]].

  6. Complete the configuration values based on the output that you get in step 3.

    [[inputs.openshiftua]]
    
      urls = ["$MetricsURL1;$MetricsURL2"]
      routernames = ["router-internal-default"]
      routercpulimits = ["$podcpulimit"]
      routermemlimits = ["$podmemlimit"]
      routernamespaces = ["openshift-ingress"]
      routerpods = ["router-default-94753cc6rr-6dcrj;router-default-94753cc6rr-dg633"]
      providerID = ""
      cid = "6227adb0bc1951fb22edc748127e9a10"
      response_timeout = "5s"
    

    Note:

    • For the urls field, paste the MetricsURL value that you get in step 3. If there are more than one url, separate them by semicolon, for example, urls = ["http://dyMldeXoZnRr:cKFzc2M4ZYos@10.26.14.149:1936/metrics;http:// dyMldeXoZnRr:cKFzc2M4ZYos@10.26.14.150:1936/metrics"].
    • For routernames and routernamespaces, paste the corresponding values that you get in step 3. If there are multiple routers, separate each router name by comma with no space.
    • For routercpulimits and routermemlimits, paste the podcpulimit and podmemlimit values that you get in step 3.
    • For routerpods, paste the POD list value that you get in step 3. If the router has multiple pods, separate them by semicolon, for example, routerpods = ["router-default-94753cc6rr-6dcrj;router-default-94753cc6rr-dg633"].
    • Leave the providerID = "" as it is.
    • Fill in the cid value that you get in step 3.
  7. Make sure that the enabled state is true and save the CR.

    Note: If you change any router and route configuration in your OpenShift environment, you must do step 2-7 again to update the CR.

Results

The OpenShift plug-in is successfully installed and configured in Unified Agent.