Add support for user-events monitoring (#520)

diff --git a/docs/configurationChoices.md b/docs/configurationChoices.md
index 9232a98..1b0e24c 100644
--- a/docs/configurationChoices.md
+++ b/docs/configurationChoices.md
@@ -254,7 +254,9 @@
 
 ### Metrics and prometheus support
 
-OpenWhisk distinguishes between system and user metrics. System metrics typically contain information about system performance and use Kamon to collect. User metrics encompass information about action performance which is sent to Kafka in a form of events.
+OpenWhisk distinguishes between `system` and `user` metrics. System metrics typically contain information about system performance and use Kamon to collect. User metrics encompass information about action performance which is sent to Kafka in a form of events.
+
+#### System metrics
 
 If you want to collect system metrics, store and display them with prometheus, use below configuration in `mycluster.yaml`:
 
@@ -263,24 +265,34 @@
   prometheusEnabled: true
 ```
 
-You also need to enable your prometheus to scrape those metrics, add below `scrape_configs` to your prometheus configuration file:
-```
-global:
-  scrape_interval: 1s
-scrape_configs:
-  - job_name: 'kamon-metrics'
-    static_configs:
-      - targets:['<controller_host>:8080','<invoker_host>:8080']
-```
-**Note:** replace `<controller_host>` and `<invoker_host>` with the real host name of controller and invoker.
+This will automatically spin up a Prometheus server inside your cluster that will start scraping `controller` and `invoker` metrics.
 
-If you want to enable user metrics, use below configuration in `mycluster.yaml`:
+You can access Prometheus by using port forwarding:
+```
+kubectl port-forward svc/owdev-prometheus-server 9090:9090 --namespace openwhisk
+```
+
+#### User metrics
+
+If you want to enable user metrics, use the below configuration in `mycluster.yaml`:
 
 ```
 metrics:
   userMetricsEnabled: true
 ```
 
+This will install [User-events](https://github.com/apache/openwhisk/tree/master/core/monitoring/user-events), [Prometheus](https://github.com/prometheus/prometheus) and [Grafana](https://github.com/grafana/grafana) on your cluster with already preconfigured Grafana dashboards for visualizing user generated metrics.
+
+The dashboards can be accessed here:
+```
+https://<whisk.ingress.apiHostName>:<whisk.ingress.apiHostPort>/monitoring/dashboards
+```
+All dashboards can be viewed anonymously and by default admin Grafana credentials are `admin/admin`. Use the bellow configuration in `mycluster.yaml` to change Grafana's admin password:
+```
+grafana:
+  adminPassword: admin
+```
+
 # Configure pod disruptions budget
 
 To avoid openwhisk components from [voluntary and nonvoluntary disruptions](https://kubernetes.io/docs/concepts/workloads/pods/disruptions/) which are managed by Kubernetes built-in controllers, you can configure PDB in `mycluster.yaml`.
diff --git a/helm/openwhisk/configMapFiles/prometheus/prometheus.yaml b/helm/openwhisk/configMapFiles/prometheus/prometheus.yaml
new file mode 100644
index 0000000..bce83e7
--- /dev/null
+++ b/helm/openwhisk/configMapFiles/prometheus/prometheus.yaml
@@ -0,0 +1,47 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# See https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml
+# For details on various options
+global:
+  scrape_interval: 10s
+scrape_configs:
+
+  - job_name: 'kubernetes-pods'
+    kubernetes_sd_configs:
+      - role: pod
+    relabel_configs:
+      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
+        action: keep
+        regex: true
+      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
+        action: replace
+        target_label: __metrics_path__
+        regex: (.+)
+      - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
+        action: replace
+        regex: ([^:]+)(?::\d+)?;(\d+)
+        replacement: $1:$2
+        target_label: __address__
+      - action: labelmap
+        regex: __meta_kubernetes_pod_label_(.+)
+      - source_labels: [__meta_kubernetes_namespace]
+        action: replace
+        target_label: kubernetes_namespace
+      - source_labels: [__meta_kubernetes_pod_name]
+        action: replace
+        target_label: kubernetes_pod_name
diff --git a/helm/openwhisk/templates/_helpers.tpl b/helm/openwhisk/templates/_helpers.tpl
index 095d2bd..4c4cf42 100644
--- a/helm/openwhisk/templates/_helpers.tpl
+++ b/helm/openwhisk/templates/_helpers.tpl
@@ -311,3 +311,13 @@
 -Dkubernetes.master=https://$KUBERNETES_SERVICE_HOST -Dwhisk.spi.ContainerFactoryProvider=org.apache.openwhisk.core.containerpool.kubernetes.KubernetesContainerFactoryProvider
 {{- end -}}
 {{- end -}}
+
+{{/* hostname for prometheus server */}}
+{{- define "openwhisk.prometheus_server_host" -}}
+{{ .Release.Name }}-prometheus-server.{{ .Release.Namespace }}.svc.{{ .Values.k8s.domain }}
+{{- end -}}
+
+{{/* hostname for grafana */}}
+{{- define "openwhisk.grafana_host" -}}
+{{ .Release.Name }}-grafana.{{ .Release.Namespace }}.svc.{{ .Values.k8s.domain }}
+{{- end -}}
diff --git a/helm/openwhisk/templates/controller-pod.yaml b/helm/openwhisk/templates/controller-pod.yaml
index e4914ee..211e1ba 100644
--- a/helm/openwhisk/templates/controller-pod.yaml
+++ b/helm/openwhisk/templates/controller-pod.yaml
@@ -34,6 +34,13 @@
       labels:
         name: {{ .Release.Name }}-controller
 {{ include "openwhisk.label_boilerplate" . | indent 8 }}
+
+      {{- if .Values.metrics.prometheusEnabled }}
+      annotations:
+        prometheus.io/scrape: 'true'
+        prometheus.io/port:   '{{ .Values.controller.port }}'
+      {{- end }}
+
     spec:
       serviceAccountName: {{ .Release.Name }}-core
       restartPolicy: {{ .Values.controller.restartPolicy }}
diff --git a/helm/openwhisk/templates/grafana-cm-dashboard.yaml b/helm/openwhisk/templates/grafana-cm-dashboard.yaml
new file mode 100644
index 0000000..ba09a7b
--- /dev/null
+++ b/helm/openwhisk/templates/grafana-cm-dashboard.yaml
@@ -0,0 +1,37 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-grafana-dsb-cfg
+  labels:
+    name: {{ .Release.Name }}-grafana-dsb-cfg
+data:
+  dashboard.yml: |
+    apiVersion: 1
+    providers:
+    - name: 'Prometheus'
+      orgId: 1
+      folder: ''
+      type: file
+      disableDeletion: false
+      editable: true
+      options:
+        path: /var/lib/grafana/dashboards
+{{- end }}
diff --git a/helm/openwhisk/templates/grafana-cm-datasource.yaml b/helm/openwhisk/templates/grafana-cm-datasource.yaml
new file mode 100644
index 0000000..1f417ed
--- /dev/null
+++ b/helm/openwhisk/templates/grafana-cm-datasource.yaml
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-grafana-ds-cfg
+  labels:
+    name: {{ .Release.Name }}-grafana-ds-cfg
+data:
+  datasource.yml: |
+    datasources:
+    - name: Prometheus
+      type: prometheus
+      access: proxy
+      isDefault: true
+      url: http://{{ include "openwhisk.prometheus_server_host" . }}:{{ .Values.prometheus.port }}
+{{- end }}
diff --git a/helm/openwhisk/templates/grafana-cm-download.yaml b/helm/openwhisk/templates/grafana-cm-download.yaml
new file mode 100644
index 0000000..a0f5917
--- /dev/null
+++ b/helm/openwhisk/templates/grafana-cm-download.yaml
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-grafana-download
+  labels:
+    name: {{ .Release.Name }}-grafana-download
+data:
+  download_dashboards.sh: |
+    #!/usr/bin/env sh
+    {{- range $index, $url := .Values.grafana.dashboards }}
+      curl -sk \
+      --connect-timeout 60 \
+      --max-time 60 \
+      -H "Accept: application/json" \
+      -H "Content-Type: application/json;charset=UTF-8" \
+      {{ $url }}  > /var/lib/grafana/dashboards/{{ $index }}.json
+    {{- end }}
+{{- end }}
diff --git a/helm/openwhisk/templates/grafana-pod.yaml b/helm/openwhisk/templates/grafana-pod.yaml
new file mode 100644
index 0000000..9ee5d3d
--- /dev/null
+++ b/helm/openwhisk/templates/grafana-pod.yaml
@@ -0,0 +1,112 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Release.Name }}-grafana
+  labels:
+    name: {{ .Release.Name }}-grafana
+{{ include "openwhisk.label_boilerplate" . | indent 4 }}
+spec:
+  serviceName: {{ .Release.Name }}-grafana
+  replicas: {{ .Values.grafana.replicaCount }}
+  selector:
+    matchLabels:
+      name: {{ .Release.Name }}-grafana
+  template:
+    metadata:
+      labels:
+        name: {{ .Release.Name }}-grafana
+{{ include "openwhisk.label_boilerplate" . | indent 8 }}
+    spec:
+      restartPolicy: {{ .Values.user_events.restartPolicy }}
+      {{- if .Values.affinity.enabled }}
+      affinity:
+{{ include "openwhisk.affinity.core" . | indent 8 }}
+{{ include "openwhisk.affinity.selfAntiAffinity" ( printf "%s-grafana" .Release.Name ) | indent 8 }}
+      {{- end }}
+
+      {{- if .Values.toleration.enabled }}
+      tolerations:
+{{ include "openwhisk.toleration.core" . | indent 8 }}
+      {{- end }}
+
+      initContainers:
+      - name: download-dashboards
+        image: "appropriate/curl:latest"
+        imagePullPolicy: Always
+        command: ["sh", "/etc/grafana/download_dashboards.sh"]
+        resources:
+          limits:
+            cpu: 100m
+            memory: 128Mi
+        volumeMounts:
+        - name: grafana-dashboard-volume
+          mountPath: /var/lib/grafana/dashboards
+        - name: grafana-download-volume
+          mountPath: "/etc/grafana"
+      containers:
+        - name: grafana
+          image: "{{- .Values.docker.registry.name -}}{{- .Values.grafana.imageName -}}:{{- .Values.grafana.imageTag -}}"
+          env:
+          - name: "GF_AUTH_ANONYMOUS_ENABLED"
+            value: "true"
+          - name: "GF_SECURITY_ADMIN_PASSWORD"
+            value: {{ .Values.grafana.adminPassword }}
+          - name: "GF_PATHS_PROVISIONING"
+            value: "/var/lib/grafana/config"
+          - name: "GF_USERS_ALLOW_SIGN_UP"
+            value: "false"
+          - name: "GF_SERVER_ROOT_URL"
+            value: "%(protocol)s://%(domain)s/monitoring"
+          - name: "GF_SERVER_SERVE_FROM_SUB_PATH"
+            value: "true"
+
+          ports:
+            - containerPort: {{ .Values.grafana.port }}
+          livenessProbe:
+            httpGet:
+              path: /api/health
+              port: {{ .Values.grafana.port }}
+            initialDelaySeconds: 30
+            timeoutSeconds: 5
+          readinessProbe:
+            httpGet:
+              path: /api/health
+              port: {{ .Values.grafana.port }}
+          volumeMounts:
+          - name: grafana-datasource-config-volume
+            mountPath: /var/lib/grafana/config/datasources
+          - name: grafana-dashboard-config-volume
+            mountPath: /var/lib/grafana/config/dashboards
+          - name: grafana-dashboard-volume
+            mountPath: /var/lib/grafana/dashboards
+      volumes:
+      - name: grafana-datasource-config-volume
+        configMap:
+          name: "{{ .Release.Name }}-grafana-ds-cfg"
+      - name: grafana-dashboard-config-volume
+        configMap:
+          name: "{{ .Release.Name }}-grafana-dsb-cfg"
+      - name: grafana-download-volume
+        configMap:
+          name: "{{ .Release.Name }}-grafana-download"
+      - name: grafana-dashboard-volume
+        emptyDir: {}
+{{- end }}
diff --git a/helm/openwhisk/templates/grafana-svc.yaml b/helm/openwhisk/templates/grafana-svc.yaml
new file mode 100644
index 0000000..97f147b
--- /dev/null
+++ b/helm/openwhisk/templates/grafana-svc.yaml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Release.Name }}-grafana
+  labels:
+    name: {{ .Release.Name }}-grafana
+spec:
+  selector:
+    name: {{ .Release.Name }}-grafana
+  ports:
+  - port: {{ .Values.grafana.port }}
+    name: http
+{{- end }}
diff --git a/helm/openwhisk/templates/invoker-pod.yaml b/helm/openwhisk/templates/invoker-pod.yaml
index 3a2b481..d529ce9 100644
--- a/helm/openwhisk/templates/invoker-pod.yaml
+++ b/helm/openwhisk/templates/invoker-pod.yaml
@@ -43,6 +43,13 @@
       labels:
         name: {{ .Release.Name }}-invoker
 {{ include "openwhisk.label_boilerplate" . | indent 8 }}
+
+      {{- if .Values.metrics.prometheusEnabled }}
+      annotations:
+        prometheus.io/scrape: 'true'
+        prometheus.io/port:   '{{ .Values.invoker.port }}'
+      {{- end }}
+
     spec:
 {{- if eq .Values.invoker.containerFactory.impl "kubernetes" }}
       serviceAccountName: {{ .Release.Name }}-invoker
diff --git a/helm/openwhisk/templates/nginx-cm.yaml b/helm/openwhisk/templates/nginx-cm.yaml
index 840fe4b..291e003 100644
--- a/helm/openwhisk/templates/nginx-cm.yaml
+++ b/helm/openwhisk/templates/nginx-cm.yaml
@@ -71,6 +71,9 @@
         set $controllers {{ include "openwhisk.controller_host" . }};
 {{- if or (eq .Values.whisk.ingress.type "NodePort") (eq .Values.whisk.ingress.type "LoadBalancer") }}
         set $apigw {{ include "openwhisk.apigw_host" . }};
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+        set $grafana {{ include "openwhisk.grafana_host" . }};
+{{- end }}
 {{- end }}
 
 {{- if or (eq .Values.whisk.ingress.type "NodePort") (eq .Values.whisk.ingress.type "LoadBalancer") }}
@@ -98,6 +101,12 @@
         location /v2 {
             proxy_pass http://$apigw:{{ .Values.apigw.apiPort }};
         }
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+        location /monitoring {
+            proxy_pass http://$grafana:{{ .Values.grafana.port }};
+        }
+{{- end }}
 {{- end }}
         location / {
             if ($namespace) {
diff --git a/helm/openwhisk/templates/prometheus-cm.yaml b/helm/openwhisk/templates/prometheus-cm.yaml
new file mode 100644
index 0000000..ee4f6d8
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-cm.yaml
@@ -0,0 +1,27 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-prometheus-configuration
+  labels:
+    name: {{ .Release.Name }}-prometheus-configuration
+data:
+{{ (.Files.Glob "configMapFiles/prometheus/prometheus.yaml").AsConfig | indent 2 }}
+{{- end }}
diff --git a/helm/openwhisk/templates/prometheus-pod.yaml b/helm/openwhisk/templates/prometheus-pod.yaml
new file mode 100644
index 0000000..4026b68
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-pod.yaml
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  name: {{ .Release.Name }}-prometheus-server
+  labels:
+    name: {{ .Release.Name }}-prometheus-server
+{{ include "openwhisk.label_boilerplate" . | indent 4 }}
+spec:
+  serviceName: {{ .Release.Name }}-prometheus-server
+  replicas: {{ .Values.prometheus.replicaCount }}
+  selector:
+    matchLabels:
+      name: {{ .Release.Name }}-prometheus-server
+  template:
+    metadata:
+      labels:
+        name: {{ .Release.Name }}-prometheus-server
+{{ include "openwhisk.label_boilerplate" . | indent 8 }}
+    spec:
+      restartPolicy: {{ .Values.user_events.restartPolicy }}
+      {{- if .Values.affinity.enabled }}
+      affinity:
+{{ include "openwhisk.affinity.core" . | indent 8 }}
+{{ include "openwhisk.affinity.selfAntiAffinity" ( printf "%s-prometheus-server" .Release.Name ) | indent 8 }}
+      {{- end }}
+
+      {{- if .Values.toleration.enabled }}
+      tolerations:
+{{ include "openwhisk.toleration.core" . | indent 8 }}
+      {{- end }}
+
+      securityContext:
+        fsGroup: 2000
+        runAsUser: 1000
+        runAsNonRoot: true
+      serviceAccountName: {{ .Release.Name }}-prometheus-server
+      containers:
+        - name: prometheus
+          imagePullPolicy: {{ .Values.prometheus.imagePullPolicy | quote }}
+          image: "{{- .Values.docker.registry.name -}}{{- .Values.prometheus.imageName -}}:{{- .Values.prometheus.imageTag -}}"
+          args:
+            - "--config.file=/etc/prometheus/prometheus.yaml"
+            - "--storage.tsdb.path={{ .Values.prometheus.persistentVolume.mountPath }}"
+          ports:
+            - containerPort: {{ .Values.prometheus.port }}
+          livenessProbe:
+            httpGet:
+              path: /-/healthy
+              port: {{ .Values.prometheus.port }}
+            initialDelaySeconds: 30
+            timeoutSeconds: 5
+          readinessProbe:
+            httpGet:
+              path: /-/healthy
+              port: {{ .Values.prometheus.port }}
+
+          volumeMounts:
+            - name: prometheus-config-volume
+              mountPath: /etc/prometheus/
+            - name: prometheus-storage-volume
+              mountPath: {{ .Values.prometheus.persistentVolume.mountPath }}
+
+      volumes:
+      - name: prometheus-config-volume
+        configMap:
+          name: "{{ .Release.Name }}-prometheus-configuration"
+      - name: prometheus-storage-volume
+{{- if and .Values.k8s.persistence.enabled (eq (int .Values.prometheus.replicaCount) 1) }}
+        persistentVolumeClaim:
+          claimName: "{{ .Release.Name }}-prometheus-pvc"
+{{- else }}
+        emptyDir: {}
+{{- end }}
+{{- end }}
diff --git a/helm/openwhisk/templates/prometheus-pvc.yaml b/helm/openwhisk/templates/prometheus-pvc.yaml
new file mode 100644
index 0000000..4602125
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-pvc.yaml
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if and .Values.k8s.persistence.enabled (eq (int .Values.prometheus.replicaCount) 1 ) }}
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: {{ .Release.Name }}-prometheus-pvc
+  labels:
+{{ include "openwhisk.label_boilerplate" . | indent 4 }}
+spec:
+{{- if not .Values.k8s.persistence.hasDefaultStorageClass }}
+  storageClassName: {{ .Values.k8s.persistence.explicitStorageClass }}
+{{- end }}
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: {{ .Values.prometheus.persistence.size }}
+{{- end }}
+{{- end }}
diff --git a/helm/openwhisk/templates/prometheus-role.yaml b/helm/openwhisk/templates/prometheus-role.yaml
new file mode 100644
index 0000000..967461d
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-role.yaml
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRole
+metadata:
+  name: {{ .Release.Name }}-prometheus-server
+rules:
+  - apiGroups: [""]
+    resources:
+      - services
+      - endpoints
+      - pods
+    verbs: ["get", "list", "watch"]
+{{- end }}
diff --git a/helm/openwhisk/templates/prometheus-rolebind.yaml b/helm/openwhisk/templates/prometheus-rolebind.yaml
new file mode 100644
index 0000000..7949962
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-rolebind.yaml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: {{ .Release.Name }}-prometheus-server
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: {{ .Release.Name }}-prometheus-server
+subjects:
+  - kind: ServiceAccount
+    name: {{ .Release.Name }}-prometheus-server
+    namespace: {{ .Release.Namespace }}
+{{- end }}
diff --git a/helm/openwhisk/templates/prometheus-svc.yaml b/helm/openwhisk/templates/prometheus-svc.yaml
new file mode 100644
index 0000000..1ca34d2
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-svc.yaml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Release.Name }}-prometheus-server
+  annotations:
+    prometheus.io/scrape: 'true'
+    prometheus.io/port:   '{{ .Values.prometheus.port }}'
+spec:
+  selector:
+    name: {{ .Release.Name }}-prometheus-server
+  ports:
+    - port: {{ .Values.prometheus.port }}
+{{- end }}
diff --git a/helm/openwhisk/templates/prometheus-svcacct.yaml b/helm/openwhisk/templates/prometheus-svcacct.yaml
new file mode 100644
index 0000000..dc581b1
--- /dev/null
+++ b/helm/openwhisk/templates/prometheus-svcacct.yaml
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if or .Values.metrics.prometheusEnabled .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: {{ .Release.Name }}-prometheus-server
+{{- end}}
diff --git a/helm/openwhisk/templates/user-events-pod.yaml b/helm/openwhisk/templates/user-events-pod.yaml
new file mode 100644
index 0000000..9523957
--- /dev/null
+++ b/helm/openwhisk/templates/user-events-pod.yaml
@@ -0,0 +1,74 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if .Values.metrics.userMetricsEnabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Release.Name }}-user-events
+  labels:
+    name: {{ .Release.Name }}-user-events
+{{ include "openwhisk.label_boilerplate" . | indent 4 }}
+spec:
+  serviceName: {{ .Release.Name }}-user-events
+  replicas: {{ .Values.user_events.replicaCount }}
+  selector:
+    matchLabels:
+      name: {{ .Release.Name }}-user-events
+  template:
+    metadata:
+      labels:
+        name: {{ .Release.Name }}-user-events
+{{ include "openwhisk.label_boilerplate" . | indent 8 }}
+      annotations:
+        prometheus.io/scrape: 'true'
+        prometheus.io/port:   '{{ .Values.user_events.port }}'
+    spec:
+      restartPolicy: {{ .Values.user_events.restartPolicy }}
+
+      {{- if .Values.metrics.userMetricsEnabled }}
+      affinity:
+{{ include "openwhisk.affinity.core" . | indent 8 }}
+{{ include "openwhisk.affinity.selfAntiAffinity" ( printf "%s-user-events" .Release.Name ) | indent 8 }}
+      {{- end }}
+
+      {{- if .Values.toleration.enabled }}
+      tolerations:
+{{ include "openwhisk.toleration.core" . | indent 8 }}
+      {{- end }}
+
+      containers:
+        - name: user-events
+          imagePullPolicy: {{ .Values.user_events.imagePullPolicy | quote }}
+          image: "{{- .Values.docker.registry.name -}}{{- .Values.user_events.imageName -}}:{{- .Values.user_events.imageTag -}}"
+          env:
+          - name: "KAFKA_HOSTS"
+            value: "{{ include "openwhisk.kafka_connect" . }}"
+{{ include "openwhisk.kafkaConfigEnvVars" . | indent 10 }}
+          ports:
+            - containerPort: {{ .Values.user_events.port }}
+          livenessProbe:
+            httpGet:
+              path: /ping
+              port: {{ .Values.user_events.port }}
+            initialDelaySeconds: 30
+            timeoutSeconds: 5
+          readinessProbe:
+            httpGet:
+              path: /ping
+              port: {{ .Values.user_events.port }}
+{{- end }}
diff --git a/helm/openwhisk/templates/user-events-svc.yaml b/helm/openwhisk/templates/user-events-svc.yaml
new file mode 100644
index 0000000..ac726ee
--- /dev/null
+++ b/helm/openwhisk/templates/user-events-svc.yaml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{{ if .Values.metrics.userMetricsEnabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Release.Name }}-user-events
+  labels:
+    name: {{ .Release.Name }}-user-events
+spec:
+  selector:
+    name: {{ .Release.Name }}-user-events
+  ports:
+  - port: {{ .Values.user_events.port }}
+    name: http
+{{- end }}
diff --git a/helm/openwhisk/values-metadata.yaml b/helm/openwhisk/values-metadata.yaml
index 0bbe853..8e7b775 100644
--- a/helm/openwhisk/values-metadata.yaml
+++ b/helm/openwhisk/values-metadata.yaml
@@ -1242,6 +1242,169 @@
         type: "string"
         required: true
 
+user-events:
+  __metadata:
+    label: "User-events Configuration"
+    description: "Update these default values to customize the User-events deployment"
+  imageName:
+    __metadata:
+      label: "Image name"
+      description: "The docker image name"
+      type: "string"
+      required: true
+  imageTag:
+    __metadata:
+      label: "Image tag"
+      description: "The docker image tag"
+      type: "string"
+      required: true
+  imagePullPolicy:
+    __metadata:
+      label: "Image pull policy"
+      description: "The image pull policy to apply for this image."
+      type: "string"
+      required: true
+      options:
+      - label: "Always"
+        value: "Always"
+      - label: "Never"
+        value: "Never"
+      - label: "IfNotPresent"
+        value: "IfNotPresent"
+  replicaCount:
+    __metadata:
+      label: "Replica count"
+      description: "The number of user-events instances to deploy"
+      type: "string"
+      required: true
+  restartPolicy:
+    __metadata:
+      label: "Restart policy"
+      description: "The restart policy for user-events pods"
+      type: "string"
+      required: true
+  port:
+    __metadata:
+      label: "HTTP port"
+      description: "The port to use for HTTP connections"
+      type: "string"
+      required: true
+
+prometheus:
+  __metadata:
+    label: "Prometheus Configuration"
+    description: "Update these default values to customize the prometheus deployment"
+  imageName:
+    __metadata:
+      label: "Image name"
+      description: "The docker image name"
+      type: "string"
+      required: true
+  imageTag:
+    __metadata:
+      label: "Image tag"
+      description: "The docker image tag"
+      type: "string"
+      required: true
+  imagePullPolicy:
+    __metadata:
+      label: "Image pull policy"
+      description: "The image pull policy to apply for this image."
+      type: "string"
+      required: true
+      options:
+      - label: "Always"
+        value: "Always"
+      - label: "Never"
+        value: "Never"
+      - label: "IfNotPresent"
+        value: "IfNotPresent"
+  replicaCount:
+    __metadata:
+      label: "Replica count"
+      description: "The number of prometheus instances to deploy"
+      type: "string"
+      required: true
+  restartPolicy:
+    __metadata:
+      label: "Restart policy"
+      description: "The restart policy for prometheus pods"
+      type: "string"
+      required: true
+  port:
+    __metadata:
+      label: "HTTP port"
+      description: "The port to use for HTTP connections"
+      type: "string"
+      required: true
+    persistence:
+      size:
+        __metadata:
+          label: "Prometheus persistence size"
+          description: "The size of the persistent volume for Prometheus"
+          type: "string"
+          required: true
+
+grafana:
+  __metadata:
+    label: "User-events Configuration"
+    description: "Update these default values to customize the User-events deployment"
+  imageName:
+    __metadata:
+      label: "Image name"
+      description: "The docker image name"
+      type: "string"
+      required: true
+  imageTag:
+    __metadata:
+      label: "Image tag"
+      description: "The docker image tag"
+      type: "string"
+      required: true
+  imagePullPolicy:
+    __metadata:
+      label: "Image pull policy"
+      description: "The image pull policy to apply for this image."
+      type: "string"
+      required: true
+      options:
+      - label: "Always"
+        value: "Always"
+      - label: "Never"
+        value: "Never"
+      - label: "IfNotPresent"
+        value: "IfNotPresent"
+  replicaCount:
+    __metadata:
+      label: "Replica count"
+      description: "The number of user-events instances to deploy"
+      type: "string"
+      required: true
+  restartPolicy:
+    __metadata:
+      label: "Restart policy"
+      description: "The restart policy for user-events pods"
+      type: "string"
+      required: true
+  port:
+    __metadata:
+      label: "HTTP port"
+      description: "The port to use for HTTP connections"
+      type: "string"
+      required: true
+  adminPassword:
+    __metadata:
+      label: "Grafana user admin password"
+      description: "The password used for logging in as an admin user in Grafana"
+      type: "string"
+      required: true
+  dashboards:
+    __metadata:
+      label: "List of dashboards Grafana dashboards"
+      description: "List of dashboards that should be configured in Grafana on container init"
+      type: "string"
+      required: true
+
 providers:
   __metadata:
     label: "OpenWhisk providers configuration"
diff --git a/helm/openwhisk/values.yaml b/helm/openwhisk/values.yaml
index 3b5671b..1c1e26e 100644
--- a/helm/openwhisk/values.yaml
+++ b/helm/openwhisk/values.yaml
@@ -306,6 +306,42 @@
   persistence:
     size: 256Mi
 
+# User-events configuration
+user_events:
+  imageName: "openwhisk/user-events"
+  imageTag: "94043db"
+  imagePullPolicy: "IfNotPresent"
+  replicaCount: 1
+  restartPolicy: "Always"
+  port: 9095
+
+# Prometheus configuration
+prometheus:
+  imageName: "prom/prometheus"
+  imageTag: v2.14.0
+  imagePullPolicy: "IfNotPresent"
+  replicaCount: 1
+  restartPolicy: "Always"
+  port: 9090
+  persistence:
+    size: 1Gi
+  persistentVolume:
+    mountPath: /prometheus/
+
+# Grafana configuration
+grafana:
+  imageName: "grafana/grafana"
+  imageTag: "6.3.0"
+  imagePullPolicy: "IfNotPresent"
+  replicaCount: 1
+  restartPolicy: "Always"
+  port: 3000
+  adminPassword: "admin"
+  dashboards:
+  - https://raw.githubusercontent.com/apache/openwhisk/master/core/monitoring/user-events/compose/grafana/dashboards/openwhisk_events.json
+  - https://raw.githubusercontent.com/apache/openwhisk/master/core/monitoring/user-events/compose/grafana/dashboards/global-metrics.json
+  - https://raw.githubusercontent.com/apache/openwhisk/master/core/monitoring/user-events/compose/grafana/dashboards/top-namespaces.json
+
 # Metrics
 metrics:
   # set true to enable prometheus exporter
diff --git a/tools/travis/collect-logs.sh b/tools/travis/collect-logs.sh
index ba636ba..a75e5b6 100755
--- a/tools/travis/collect-logs.sh
+++ b/tools/travis/collect-logs.sh
@@ -44,4 +44,7 @@
 kubectl -n openwhisk logs -lname=ow4travis-alarmprovider >& logs/kafkaprovider.log
 kubectl -n openwhisk logs -lname=ow4travis-cloudantprovider >& logs/cloudantprovider.log
 kubectl -n openwhisk logs -lname=ow4travis-kafkaprovider >& logs/kafkaprovider.log
+kubectl -n openwhisk logs -lname=ow4travis-user-events >& logs/user-events.log
+kubectl -n openwhisk logs -lname=ow4travis-prometheus >& logs/prometheus.log
+kubectl -n openwhisk logs -lname=ow4travis-grafana >& logs/grafana.log
 kubectl get pods --all-namespaces -o wide >& logs/all-pods.txt
diff --git a/tools/travis/deploy-chart.sh b/tools/travis/deploy-chart.sh
index eab00a7..777db9b 100755
--- a/tools/travis/deploy-chart.sh
+++ b/tools/travis/deploy-chart.sh
@@ -216,6 +216,9 @@
 
 controller:
   lean: ${OW_LEAN_MODE:-false}
+
+metrics:
+  userMetricsEnabled: true
 EOF
 
 echo "Contents of mycluster.yaml are:"
@@ -234,6 +237,11 @@
 
   # Wait for the controller to confirm that it has at least one healthy invoker
   verifyHealthyInvoker
+
+  # Verify that the user-metrics components were deployed successfully
+  deploymentHealthCheck "ow4travis-user-events"
+  # deploymentHealthCheck "ow4travis-prometheus-server"
+  deploymentHealthCheck "ow4travis-grafana"
 fi
 
 # Wait for install-packages job to complete successfully
@@ -243,4 +251,3 @@
 deploymentHealthCheck "ow4travis-alarmprovider"
 deploymentHealthCheck "ow4travis-cloudantprovider"
 deploymentHealthCheck "ow4travis-kafkaprovider"
-