## Monitoring Microclimate based Node.js applications in IBM Cloud Private During data collector deployment, the Cloud App Management server information must be provided so that the data collector can be configured to connect to the appropriate server, the server information is provided as a configure package for download from the Cloud App Management console. ### Prerequisites The service account that you use to install and configure the data collector must have access to Kubernetes resources. You can run the following commands on the Kubernetes master node to determine if the data collector has access to resources by using your service account: ``` kubectl auth can-i list nodes --as system:serviceaccount:: kubectl auth can-i get pods --as system:serviceaccount:: kubectl auth can-i list services --as system:serviceaccount:: kubectl auth can-i get services --as system:serviceaccount:: kubectl auth can-i list endpoints --as system:serviceaccount:: kubectl auth can-i get endpoints --as system:serviceaccount:: ``` Remember to change the `` and `` in the commands to the namespace of your environment and the name for the service account that you use to configure the data collector. By default, the `` is `default`. If your service account does not have access to Kubernetes resources, follow the instructions in [Configuring the data collector to access Kubernetes resources](nodejsdc_config_access.md). ### Download the Configure package 1. Log in to the Cloud App Management console and click Get Started. 2. Click Administration to open the Administration user interface. 3. Click Integrations to add an integration and then click Configure an integration. 4. In the Standard monitoring agents section, go to the Data Collectors tile and click Configure. 5. Click Download file to download the `ibm-cloud-apm-dc-configpack.tar` file. Extract the `ibm-cloud-apm-dc-configpack.tar` file to get the `global.environmen`t file and the `keyfiles`. This file contains all variables and their values required by data collectors for server connection. ### Install Data Collector As the Node.js application created by Microclimate has required the `appmetrics` automatically, so you need to check the version of appmetrics, if the version is 4.0.0 or later, then the Node.js DC is included already. If the version is less then 4.0.0, you need to upgrade the appmetrics to version 4.0.0 or later. ### Configure Data Collector There are two options to configure the Node.js data collector to monitoring the Node.js applicaton. #### Option 1 (Passing ICAM server configuration via secret - Preferred option) You can create a secret for the file `global.environment` and `keyfile.p12` extracted from the ICAM configuration package, and mount this secret when you deploy the application as a kubenetes deployment. 1. Create the Kubernetes Secret:
    cd ibm-cloud-apm-dc-configpack
    kubectl -n  create secret generic icam-server-secret \
    --from-file=keyfiles/keyfile.p12 \
    --from-file=global.environment
    
Or you can choose to create cert files e.g. keyfile.jks, ca.pem .... In case the other Data collector, which using the keyfile.jks keystore, can share the same Secret with Node.js Data collector. 2. Update the application yaml file to mount the configure map. See the example below.
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: acmeair
    labels:
        app: acmeair
    spec:
    selector:
        matchLabels:
        app: acmeair
        pod: acmeair
    replicas: 1
    template:
        metadata:
        name: acmeair
        labels:
            app: acmeair
            pod: acmeair
        spec:
        containers:
        - name: acmeair
            image: mycluster.icp:8500/default/acmeair:v1
            imagePullPolicy: Always
            ports:
            - containerPort: 3000
            protocol: TCP
            env:        
            - name: KNJ_LOG_TO_FILE
            value: "true"
            - name: KNJ_LOG_LEVEL
            value: "debug"
            - name: APPLICATION_NAME
            value: "acmeair"
            volumeMounts:
            - name: serverconfig
            mountPath: /opt/ibm/apm/serverconfig
        volumes:
        - name: serverconfig
          secret:
            secretName: icam-server-secret
            optional: true
    
3. Build the new Docker image. 4. Update the application yaml file to use the new Docker image. #### Option 2 (Embedding ICAM server configuration into docker image - Not preferred option usually) You can copy the file global.environment and keyfile.p12 extracted from the configure package into the root directory of Node.js application directly. 1. Run apply_configpack.sh tool to copy the file global.environment and keyfile.p12 to the root of Node.js application. ``` ./apply_configpack.sh [] ``` where, `configpack` is path of configure package which you downloaded from the Cloud App Management console. `application folder` is the root folder of the application (where you run application command executed), if you are at application root folder, it can be not specified. 2. Build the new Docker image. 3. Update the application yaml file to use the new Docker image.