For Portworx 2.7.x or earlier: Monitor PXB Clusters
This topic describes how you can monitor your Portworx Backup clusters with Prometheus and Grafana. This section is exclusively for the users who want to use external Prometheus and Grafana for extensive monitoring data of PXB clusters.
If you are referring to this topic, opt out of using PXB Prometheus stack for monitoring.
Configure Service Monitor
If Grafana already exists in the cluster where PXB is deployed, then you just have to configure service monitor to monitor PXB clusters. Apply the following spec in <pxb-namespace> for extensive monitoring:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
name: px-backup-sm
name: px-backup-sm
namespace: <pxb-namespace>
spec:
endpoints:
- metricRelabelings:
- action: labeldrop
regex: (instance|pod)
- action: drop
regex: process_.*
sourceLabels:
- __name__
- action: drop
regex: go_.*
sourceLabels:
- __name__
- action: drop
regex: grpc_.*
sourceLabels:
- __name__
port: rest-api
targetPort: 10001
namespaceSelector:
any: true
selector:
matchLabels:
app: px-backup
Prerequisites
- A Portworx Backup cluster
- Environment required to install Prometheus and Grafana
- You must have
kubectlaccess to your Portworx Backup cluster
Below topic explains the deployment of monitoring stack in Portworx Backup namespace. If Portworx Backup is deployed in a different namespace, please ensure to modify the namespace wherever required.
Install and configure Prometheus
For Portworx Backup 2.7.0 or above, see Configure your Own Prometheus which covers OpenShift Clusters, Rancher, and Kubernetes Vanilla environments.
-
(Optional) Enter the following combined spec and
kubectlcommand to install the Prometheus Operator:Skip this step if you have not configured your own Prometheus stack in Portworx Backup version 2.7.0 and above. If no, execute the following steps.
kubectl apply -f - <<'_EOF'---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: prometheus-operatornamespace: <pxb-namespace>roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: prometheus-operatorsubjects:- kind: ServiceAccountname: prometheus-operatornamespace: <pxb-namespace>---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: prometheus-operatornamespace: <pxb-namespace>rules:- apiGroups:- extensionsresources:- thirdpartyresourcesverbs: ["*"]- apiGroups:- apiextensions.k8s.ioresources:- customresourcedefinitionsverbs: ["*"]- apiGroups:- monitoring.coreos.comresources:- alertmanagers- prometheuses- prometheuses/finalizers- servicemonitors- prometheusrules- podmonitors- thanosrulers- alertmanagerconfigs- probesverbs: ["*"]- apiGroups:- appsresources:- statefulsetsverbs: ["*"]- apiGroups: [""]resources:- configmaps- secretsverbs: ["*"]- apiGroups: [""]resources:- podsverbs: ["list", "delete"]- apiGroups: [""]resources:- services- endpointsverbs: ["get", "create", "update", "delete"]- apiGroups: [""]resources:- nodesverbs: ["list", "watch"]- apiGroups: [""]resources:- namespacesverbs: ["list", "watch", "get"]---apiVersion: v1kind: ServiceAccountmetadata:name: prometheus-operatornamespace: <pxb-namespace>---apiVersion: apps/v1kind: Deploymentmetadata:labels:k8s-app: prometheus-operatorname: prometheus-operatornamespace: <pxb-namespace>spec:selector:matchLabels:k8s-app: prometheus-operatorreplicas: 1template:metadata:labels:k8s-app: prometheus-operatorspec:containers:- args:- --kubelet-service=kube-system/kubelet- --prometheus-config-reloader=docker.io/portworx/prometheus-config-reloader:v0.56.3- --namespaces=<pxb-namespace>name: prometheus-operatorimage: docker.io/portworx/prometheus-operator:v0.56.3ports:- containerPort: 8080name: httpresources:limits:cpu: 200mmemory: 100Mirequests:cpu: 100mmemory: 50MisecurityContext:runAsNonRoot: truerunAsUser: 65534serviceAccountName: prometheus-operator -
To grant Prometheus access to the metrics API, create the
ClusterRole,ClusterRoleBinding,Service, andServiceAccountKubernetes objects:kubectl apply -f - <<'_EOF'---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: px-backup-prometheusnamespace: <pxb-namespace>rules:- apiGroups:- ""resources:- nodes- services- endpoints- podsverbs:- get- list- watch- apiGroups:- ""resources:- configmapsverbs:- get- nonResourceURLs:- /metrics- /federateverbs:- get---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: px-backup-prometheusnamespace: <pxb-namespace>roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: px-backup-prometheussubjects:- kind: ServiceAccountname: px-backup-prometheusnamespace: <pxb-namespace>---apiVersion: v1kind: Servicemetadata:name: px-backup-prometheusnamespace: <pxb-namespace>spec:type: ClusterIPports:- name: webport: 9090protocol: TCPtargetPort: 9090selector:prometheus: px-backup-prometheus---apiVersion: v1kind: ServiceAccountmetadata:name: px-backup-prometheusnamespace: <pxb-namespace> -
To specify the monitoring rules for Portworx Backup, create a
ServiceMonitorobject by entering the following combined spec andkubectlcommand:kubectl apply -f - <<'_EOF'---apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata:namespace: <pxb-namespace>name: px-backup-prometheus-smlabels:name: px-backup-prometheus-smspec:selector:matchLabels:app: px-backupnamespaceSelector:any: trueendpoints:- port: rest-apitargetPort: 10001 -
Apply Prometheus specs for Portworx Backup metrics:
kubectl apply -f - <<'_EOF'---apiVersion: monitoring.coreos.com/v1kind: Prometheusmetadata:name: px-backup-prometheusnamespace: <pxb-namespace>spec:replicas: 2logLevel: debugserviceAccountName: px-backup-prometheusserviceMonitorSelector:matchLabels:name: px-backup-prometheus-sm