From 8d2fdfa04679f3121ac67e1721467196d3583018 Mon Sep 17 00:00:00 2001 From: Pieter Lange Date: Mon, 2 Apr 2018 18:41:54 +0200 Subject: [PATCH 1/2] Refactor metrics collection --- entrypoint.sh | 4 +++- kube/deployment.yaml | 17 ++++++++++++++++- print-status.sh | 19 ------------------- 3 files changed, 19 insertions(+), 21 deletions(-) delete mode 100755 print-status.sh diff --git a/entrypoint.sh b/entrypoint.sh index 0e19d58..9876fdd 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,6 +22,8 @@ OVPN_PROTO="${OVPN_PROTO:-tcp}" OVPN_NATDEVICE="${OVPN_NATDEVICE:-eth0}" OVPN_K8S_DOMAIN="${OVPN_K8S_DOMAIN:-svc.cluster.local}" OVPN_VERB=${OVPN_VERB:-3} +OVPN_STATUS="${OVPN_STATUS:-${OPENVPN}/status/server.status}" +OVPN_STATUS_VERSION=${OVPN_STATUS_VERSION:-2} if [ ! -d "${EASYRSA_PKI}" ]; then echo "PKI directory missing. Did you mount in your Secret?" @@ -101,7 +103,7 @@ fi if [ -n "${OVPN_STATUS}" ]; then addArg "--status" "${OVPN_STATUS}" - /sbin/print-status.sh ${OVPN_STATUS} & + addArg "--status-version" "${OVPN_STATUS_VERSION}" fi if [ $DEBUG ]; then diff --git a/kube/deployment.yaml b/kube/deployment.yaml index e11ea85..df76cc6 100644 --- a/kube/deployment.yaml +++ b/kube/deployment.yaml @@ -14,7 +14,7 @@ spec: terminationGracePeriodSeconds: 60 containers: - name: openvpn - image: ptlange/openvpn:latest + image: quay.io/plange/openvpn:latest securityContext: capabilities: add: @@ -35,6 +35,11 @@ spec: name: openvpn-ccd - mountPath: /etc/openvpn/portmapping name: openvpn-portmapping + - mountPath: /etc/openvpn/status + name: openvpn-status + ports: + - name: openvpn + containerPort: 1194 env: - name: PODIPADDR valueFrom: @@ -60,6 +65,14 @@ spec: configMapKeyRef: name: openvpn-settings key: domain + - name: metrics + image: quay.io/plange/openvpn_exporter:latest + ports: + - name: openvpn + containerPort: 9176 + volumeMounts: + - mountPath: /etc/openvpn_exporter/ + name: openvpn-status volumes: - name: openvpn-pki secret: @@ -75,3 +88,5 @@ spec: - name: openvpn-portmapping configMap: name: openvpn-portmapping + - name: openvpn-status + emptyDir: {} diff --git a/print-status.sh b/print-status.sh deleted file mode 100755 index e181e5f..0000000 --- a/print-status.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -statusfile=$1 - -while true; do - sleep 60 - if [ ! -r $statusfile ]; then - echo "Cannot read statusfile at $statusfile" - break - fi - while read line; do - IFS=',' read -r -a client <<< $line - - # Opportunistic filtering, only the client section has 5 fields - if [ ! -z "${client[4]}" -a "${client[0]}" != "Common Name" ]; then - echo -e "{ \"common_name\": \"${client[0]}\", \"bytes_received\": ${client[2]}, \"bytes_sent\": ${client[3]}, \"connected_since\": \"${client[4]}\" }" - fi - done < $statusfile -done From 9e635e5055cca4b3774ada586c24d153e97821ca Mon Sep 17 00:00:00 2001 From: Pieter Lange Date: Mon, 2 Apr 2018 22:22:17 +0200 Subject: [PATCH 2/2] Do not enable prometheus by default & and add prometheus annotations --- entrypoint.sh | 1 - kube/deploy.sh | 1 + kube/deployment.yaml | 8 ++++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9876fdd..2c2aead 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,7 +22,6 @@ OVPN_PROTO="${OVPN_PROTO:-tcp}" OVPN_NATDEVICE="${OVPN_NATDEVICE:-eth0}" OVPN_K8S_DOMAIN="${OVPN_K8S_DOMAIN:-svc.cluster.local}" OVPN_VERB=${OVPN_VERB:-3} -OVPN_STATUS="${OVPN_STATUS:-${OPENVPN}/status/server.status}" OVPN_STATUS_VERSION=${OVPN_STATUS_VERSION:-2} if [ ! -d "${EASYRSA_PKI}" ]; then diff --git a/kube/deploy.sh b/kube/deploy.sh index cd70478..95c2b66 100755 --- a/kube/deploy.sh +++ b/kube/deploy.sh @@ -65,6 +65,7 @@ data: podcidr: "${podcidr}" serverurl: "${serverurl}" domain: "${domain}" + statusfile: "/etc/openvpn/status/server.status" --- EOCONFIGMAP diff --git a/kube/deployment.yaml b/kube/deployment.yaml index df76cc6..b68f8fb 100644 --- a/kube/deployment.yaml +++ b/kube/deployment.yaml @@ -9,6 +9,9 @@ spec: metadata: labels: openvpn: ${OVPN_CN} + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9176" spec: restartPolicy: Always terminationGracePeriodSeconds: 60 @@ -65,6 +68,11 @@ spec: configMapKeyRef: name: openvpn-settings key: domain + - name: OVPN_STATUS + valueFrom: + configMapKeyRef: + name: openvpn-settings + key: statusfile - name: metrics image: quay.io/plange/openvpn_exporter:latest ports: