Install Prometheus and Grafana using Daemonset

About Prometheus

Prometheus is an opensource monitoring and alerting toolkit. Prometheus consists of several components some of which are listed below:

  • The Prometheus server which scrapes(collects) and stores time series data based on a pull mechanism.
  • A rules engine which allows generation of Alerts based on the scraped metrics.
  • An alertmanager for handling alerts.
  • Multiple integrations for graphing and dashboarding.

This document walks you through the steps required to monitor your Portworx cluster with Prometheus and Grafana. Portworx natively supports Prometheus since it exposes the metrics on a REST endpoint. Then, Prometheus can scrape this endpoint.

The following instructions allows you to monitor Portworx via Prometheus and allow the Alertmanager to provide alerts based on configured rules.

The Prometheus Operator creates, configures and manages a prometheus cluster.

The Prometheus operator manages 3 customer resource definitions namely:

  • Prometheus: The Prometheus CRD defines a Prometheus setup to be run on a Kubernetes cluster. The Operator creates a Statefulset for each definition of the Prometheus resource.
  • ServiceMonitor: The ServiceMonitor CRD allows the definition of how Kubernetes services could be monitored based on label selectors. The Service abstraction allows Prometheus to in turn monitor underlying Pods.
  • Alertmanager: The Alertmanager CRD allows the definition of an Alertmanager instance within the Kubernetes cluster. The alertmanager expects a valid configuration in the form of a secret called alertmanager-name.

About Grafana

Grafana is a dashboarding and visualization tool with integrations to several timeseries datasources. It is used to create dashboards for the monitoring data with customizable visualizations. We would use Prometheus as the source of data to view Portworx monitoring metrics.


  • A running Portworx cluster.


If you installed Portworx using the Operator, skip to Installing Grafana.

Install the Prometheus Operator

Enter the following commands to download and apply the Prometheus Operator YAML for your Kubernetes version:

VER=$(kubectl version --short | awk -Fv '/Server Version: / {print $3}')
kubectl apply -f  "$VER"

Install the Service Monitor

Create a file named service-monitor.yaml with the below contents:

kind: ServiceMonitor
  namespace: kube-system
  name: portworx-prometheus-sm
    name: portworx-prometheus-sm
      name: portworx
    any: true
  - port: px-api
    targetPort: 9001
kind: ServiceMonitor
  name: autopilot-prometheus-sm
  namespace: kube-system
    name: portworx-prometheus-sm
      name: autopilot-service
    any: true
    - port: autopilot

Next, apply the spec:

kubectl apply -f <service-monitor.yaml>

Optional: Specify alerting rules for Prometheus Alertmanager

  1. Specify your alerting rules. Create a file named alertmanager.yaml, specifying your configuration options for the following:

    • email_configs:
      • to: with the address of the recipient
      • from: with the address of the sender
      • smarthost: with the address of your SMTP server
      • auth_username: with your STMP username
      • auth_identity: with the address of the sender
      • auth_password: with your SMTP password.
      • text: with the text the notification
    • slack_configs:

      • api_url: with your Slack API URL. To retrieve your Slack API URL, you must follow the steps in the Sending messages using Incoming Webhooks page of the Slack documentation.
      • channel: with the Slack channel you want to send notifications to.
      • text: with the text of the notification

          # Global variables
          group_by: [Alertname]
          receiver: email_and_slack
        - name: email_and_slack
          - to:
            text: |-
              {{ range .Alerts }}
                *Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
                *Description:* {{ .Annotations.description }}
                {{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
                {{ end }}
              {{ end }}
          - api_url:
            text: |-
              {{ range .Alerts }}
                *Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
                *Description:* {{ .Annotations.description }}
                {{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
                {{ end }}
              {{ end }}
    For a description of the properties in this schema, see the Configuration file section of the Prometheus documentation.
  2. Create a secret from the alertmanager.yaml file:

    kubectl create secret generic alertmanager-portworx --from-file=alertmanager.yaml -n kube-system
    secret/alertmanager-portworx created

Install and configure Prometheus Alertmanager

  1. Create a file named alertmanager-cluster.yaml, and copy in the following spec:

    kind: Alertmanager
      name: portworx #This name is important since the Alertmanager pods wont start unless a secret named alertmanager-${ALERTMANAGER_NAME} is created. in this case if would expect alertmanager-portworx secret in the kube-system namespace
      namespace: kube-system
        alertmanager: portworx
      replicas: 3
  2. Apply the spec by entering the following command:

    kubectl apply -f alertmanager-cluster.yaml created
  3. Create a file named alertmanager-service.yaml with the following content:

    apiVersion: v1
    kind: Service
      name: alertmanager-portworx
      namespace: kube-system
      type: NodePort
      - name: web
        port: 9093
        protocol: TCP
        targetPort: web
        alertmanager: portworx
  4. Apply the spec by entering the following command:

    kubectl apply -f alertmanager-service.yaml
    service/alertmanager-portworx created

Install Prometheus

Download prometheus-rules.yaml and apply it:

kubectl apply -f prometheus-rules.yaml

Download prometheus-cluster.yaml and apply it:

kubectl apply -f prometheus-cluster.yaml

Post Install verification

Prometheus access details

Find out what endpoint prometheus has, by default it deploys as a ClusterIP

kubectl get svc -n kube-system prometheus

Navigate to the Prometheus web UI by going to the service ip. You should be able to navigate to the Targets and Rules section of the Prometheus dashboard which lists the Portworx cluster endpoints as well as the Alerting rules as specified earlier.

Installing Grafana

  1. Download grafana-dashboard-config.yaml file and create the configmap:

    kubectl -n kube-system create configmap grafana-dashboard-config --from-file=grafana-dashboard-config.yaml
  2. Download grafana-datasource.yaml file and create the configmap:

    kubectl -n kube-system create configmap grafana-source-config --from-file=grafana-datasource.yaml
    NOTE: If you did not follow the steps in this document to install Prometheus, make sure you edit this file to match your environment.
  3. Download and apply the following Grafana templates:

    curl "" -o portworx-cluster-dashboard.json && \
    curl "" -o portworx-node-dashboard.json && \
    curl "" -o portworx-volume-dashboard.json && \
    curl "" -o portworx-performance-dashboard.json && \
    curl "" -o portworx-etcd-dashboard.json && \
    kubectl -n kube-system create configmap grafana-dashboards --from-file=portworx-cluster-dashboard.json --from-file=portworx-performance-dashboard.json --from-file=portworx-node-dashboard.json --from-file=portworx-volume-dashboard.json --from-file=portworx-etcd-dashboard.json
  4. Finally, download the grafana.yaml file and apply it:

    kubectl apply -f grafana.yaml

Grafana access details

Find out what endpoint grafana has, by default it deploys as a ClusterIP

  kubectl get svc -n kube-system grafana

Access the Grafana dashboard by navigating to the service ip.

Post install verification

Select the Portworx volume metrics dashboard on Grafana to view the Portworx metrics. grafanadashboard

For information on the available Portworx metrics, refer to the Portworx metrics for monitoring reference.

Last edited: Friday, Oct 28, 2022