diff --git a/entrypoint.sh b/entrypoint.sh index 0e19d58..2c2aead 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,6 +22,7 @@ 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_VERSION=${OVPN_STATUS_VERSION:-2} if [ ! -d "${EASYRSA_PKI}" ]; then echo "PKI directory missing. Did you mount in your Secret?" @@ -101,7 +102,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/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 e11ea85..b68f8fb 100644 --- a/kube/deployment.yaml +++ b/kube/deployment.yaml @@ -9,12 +9,15 @@ spec: metadata: labels: openvpn: ${OVPN_CN} + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9176" spec: restartPolicy: Always terminationGracePeriodSeconds: 60 containers: - name: openvpn - image: ptlange/openvpn:latest + image: quay.io/plange/openvpn:latest securityContext: capabilities: add: @@ -35,6 +38,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 +68,19 @@ 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: + - name: openvpn + containerPort: 9176 + volumeMounts: + - mountPath: /etc/openvpn_exporter/ + name: openvpn-status volumes: - name: openvpn-pki secret: @@ -75,3 +96,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