Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrape via Prometheus annotation #13

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 29 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
# monitor-pv

custom stats collector for OpenEBS persistent volumes (jiva, localpv)

### Pre-requisite
## Pre-requisite

- openebs (https://docs.openebs.io/)

### How to use
- Run `kubectl apply -f node-exporter-pv-metrics.yaml`
## How to use

- Run `kubectl apply -f monitor-pv.yaml`
- Verify if the pods are up and running.
<pre>

```console
$ kubectl get pods -n openebs
NAME READY STATUS RESTARTS AGE
cspc-operator-6c4cc7c64d-698ps 1/1 Running 0 6d23h
cvc-operator-77d749c559-9phff 1/1 Running 0 6d23h
maya-apiserver-5fb947d74d-r9skp 1/1 Running 0 6d23h
<b>monitor-pv-bvzgv 2/2 Running 0 8s
monitor-pv-nk76b 2/2 Running 0 11s
monitor-pv-wnvp5 2/2 Running 0 8s</b>
openebs-admission-server-6c4b4998f8-zcg9n 1/1 Running 0 6d23h
openebs-localpv-provisioner-5b744fc789-5wr8d 1/1 Running 0 6d23h
openebs-ndm-g474w 1/1 Running 0 6d23h
openebs-ndm-k2nnp 1/1 Running 0 6d23h
openebs-ndm-operator-b58c79cc5-z8zw6 1/1 Running 1 6d23h
openebs-ndm-rwzrb 1/1 Running 0 6d23h
openebs-provisioner-54d45b55db-rt5rv 1/1 Running 0 6d23h
openebs-snapshot-operator-6d4f5d7688-6g7zw 2/2 Running 0 6d23h
pvc-dd03f0ae-731c-4f78-bdbf-86485f32ab3d-ctrl-89b44f6cb-pbnmk 2/2 Running 0 40h
pvc-dd03f0ae-731c-4f78-bdbf-86485f32ab3d-rep-1-857b65c68d-qrdx9 1/1 Running 0 40h
pvc-dd03f0ae-731c-4f78-bdbf-86485f32ab3d-rep-2-58c4f54f7-m6n45 1/1 Running 0 40h
NAME READY STATUS RESTARTS AGE
...
monitor-pv-bvzgv 2/2 Running 0 8s
monitor-pv-nk76b 2/2 Running 0 11s
monitor-pv-wnvp5 2/2 Running 0 8s
...
```

</pre>
## How it works

### How it works
The monitor PV daemonset pods consist of two containers i.e node-exporter and monitor-pv. The monitor-pv collects the PV size and PV utilization information & places it in a file on the shared mount. The node exporter uses its text-file collector to expose this data as metrics.
The monitor PV daemonset pods consist of two containers i.e nginx and monitor-pv. The monitor-pv collects the PV size via `kubectl` and PV utilization information via `du`, and then places it in a text file on the shared emptydir mount. The nginx exposes this text file via HTTP so that Prometheus can scrape it as metrics.

It exposes two metrics **pv_capacity_bytes** and **pv_utilization_bytes**.

### Prometheus Configuration
To scrape the metrics in prometheus add this configuration in prometheus configuration file:
<pre>
- job_name: 'monitor-pv'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
regex: monitor-pv
action: keep
</pre>
The pods are configured with Prometheus annotations so that a Prometheus instance installed in the cluster knows how to scrape:

```yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
prometheus.io/path: /scrape.txt
prometheus.io/port: "80"
prometheus.io/scrape: "true"
```

If you want to scrape only monitor-pv metrics and drop all other node-exporter metrics use the below configuration:
<pre>
- job_name: 'monitor-pv'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
regex: monitor-pv
action: keep
metric_relabel_configs:
- source_labels: [__name__]
regex: '(pv_capacity_bytes|pv_utilization_bytes)'
action: keep
</pre>
## Example

### Example:
![monitor-pv-1](https://user-images.githubusercontent.com/29499601/81772797-67141a80-9504-11ea-901b-fe165900d60c.png)

![monitor-pv-2](https://user-images.githubusercontent.com/29499601/81772848-8a3eca00-9504-11ea-8d0b-e7a572a06aef.png)
Expand Down
114 changes: 114 additions & 0 deletions monitor-pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# monitor-pv will launch as a daemonset.
# Make sure to update namespace on ClusterRoleBinding below.
apiVersion: v1
kind: ServiceAccount
metadata:
name: openebs-monitor-pv
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: openebs-monitor-pv
rules:
- apiGroups:
- ""
resources:
- persistentvolumes
verbs:
- list
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: openebs-monitor-pv
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: openebs-monitor-pv
subjects:
- kind: ServiceAccount
name: openebs-monitor-pv
namespace: openebs # NOTE: Update namespace here if deploying to a different namespace
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: openebs-monitor-pv
spec:
selector:
matchLabels:
app: openebs-monitor-pv
template:
metadata:
labels:
app: openebs-monitor-pv
annotations:
prometheus.io/path: /scrape.txt
prometheus.io/port: "80"
prometheus.io/scrape: "true"
name: openebs-monitor-pv
spec:
serviceAccount: openebs-monitor-pv
containers:
- name: monitor-pv
image: openebs/monitor-pv:ci
imagePullPolicy: Always
env:
- name: TEXTFILE_PATH
value: /shared_vol/scrape.txt
- name: COLLECT_INTERVAL
value: "10"
- name: PROVISIONER_WHITELIST
value: "openebs.io/provisioner-iscsi,openebs.io/local"
command:
- /bin/bash
args:
- -c
- ./textfile_collector.sh
resources:
requests:
memory: "40M"
cpu: "200m"
limits:
memory: "100M"
cpu: "200m"
volumeMounts:
- mountPath: /host/proc
name: proc
- mountPath: /host/sys
name: sys
- mountPath: /host/root
mountPropagation: HostToContainer
name: root
readOnly: true
- mountPath: /shared_vol
name: shared
- image: nginx:alpine
name: nginx
ports:
- containerPort: 80
name: scrape
resources:
requests:
memory: "60M"
cpu: "1m"
limits:
memory: "100M"
cpu: "10m"
## Uncomment this to also run on control-plane nodes
#tolerations:
# - effect: NoSchedule
# operator: Exists
volumes:
- name: proc
hostPath:
path: /proc
- name: sys
hostPath:
path: /sys
- name: root
hostPath:
path: /
- name: shared
emptyDir: {}
102 changes: 0 additions & 102 deletions node-exporter-pv-metrics.yaml

This file was deleted.

Loading