Skip to content

Commit

Permalink
fix(gazer): Handle for units in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
isala404 committed Feb 17, 2022
1 parent 93d0cab commit 562f72d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 19 additions & 2 deletions gazer/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
#apiVersion: v1
#kind: Namespace
#metadata:
Expand All @@ -10,7 +11,6 @@
# namespace: lazy-koala
#data:
# config.yaml: |
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand Down Expand Up @@ -159,11 +159,28 @@ spec:
volumeMounts:
- name: config-volume
mountPath: /etc/prometheus
nodeName: minikube
- name: prom-pvc
mountPath: /etc/prometheus/data
volumes:
- name: config-volume
configMap:
name: prometheus-config
- name: prom-pvc
persistentVolumeClaim:
claimName: prometheus-lazy-koala-pv
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: prometheus-lazy-koala-pv
namespace: lazy-koala
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 8Gi
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
12 changes: 10 additions & 2 deletions gazer/gazer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from config import config_watcher
import requests
from prometheus_client import Histogram, Counter, Gauge
import re

ms = Histogram("request_duration_seconds", "TCP event latency", ["namespace", "serviceName", "podName"])
tx_kb = Histogram("transmitted_bytes", "Number of sent bytes during TCP event", ["namespace", "serviceName", "podName"])
Expand Down Expand Up @@ -101,8 +102,8 @@ def poll_kube_api(self):
headers={"Authorization": f"Bearer {self.kube_token}"}, verify=False)
data = r.json()
for container in data['containers']:
cpu_usage += int(container['usage']['cpu'])
memory_usage += int(container['usage']['memory'][:-2]) * 1024
cpu_usage += int(re.sub('\D', '', container['usage']['cpu']))
memory_usage += int(re.sub('\D', '', container['usage']['memory'])) * 1024

# Write to prometheus
cpu.labels(pod['namespace'], pod['serviceName'], pod['name']).set(cpu_usage)
Expand Down Expand Up @@ -180,3 +181,10 @@ def poll_data_in_bg(self):
poll_syn_backlog.join()
poll_requests.join()
poll_kube_api.join()

def extract_number(text):
res = [int(i) for i in text.split() if i.isdigit()]
if len(res) == 1:
return int(res)
else:
return 0

0 comments on commit 562f72d

Please sign in to comment.