├── web ├── __init__.py ├── .dockerignore ├── requirements.txt ├── config.py ├── Dockerfile ├── app.py ├── templates │ └── index.html └── static │ └── styles.css ├── exporter ├── .dockerignore ├── Dockerfile ├── modules │ ├── tcp.go │ ├── icmp.go │ └── http.go ├── go.mod ├── go.sum └── main.go ├── CHANGELOG.md ├── .gitignore ├── kubeping-web.gif ├── helm ├── templates │ ├── serviceaccount.yaml │ ├── configmap.yaml │ ├── service-web.yaml │ ├── rbac.yaml │ ├── service-exporter.yaml │ ├── ingress.yaml │ ├── _helpers.tpl │ ├── deployment.yaml │ └── daemonset.yaml ├── Chart.yaml ├── .helmignore └── values.yaml ├── .github └── workflows │ └── release.yaml ├── skaffold.yaml ├── README.md ├── LICENSE.md └── kubeping.drawio /web/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/.dockerignore: -------------------------------------------------------------------------------- 1 | .Dockerfile 2 | .dockerignore -------------------------------------------------------------------------------- /exporter/.dockerignore: -------------------------------------------------------------------------------- 1 | .Dockerfile 2 | .dockerignore -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## [1.0.0] - 2025-03-03 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | __pycache__/ 3 | values-dev.yaml 4 | bin/ 5 | config.yaml -------------------------------------------------------------------------------- /kubeping-web.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teymurgahramanov/kubeping/HEAD/kubeping-web.gif -------------------------------------------------------------------------------- /web/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.0.1 2 | requests==2.25.1 3 | gunicorn==20.1.0 4 | Werkzeug==2.1.2 5 | kubernetes==30.1.0 6 | gevent==24.2.1 7 | dotenv==0.9.9 -------------------------------------------------------------------------------- /web/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | from dotenv import load_dotenv 3 | 4 | load_dotenv() 5 | 6 | class Config: 7 | 8 | APP_VERSION = '1.0.0' 9 | 10 | config = Config() -------------------------------------------------------------------------------- /helm/templates/serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: {{ include "kubeping.fullname" . }} 5 | labels: 6 | {{- include "kubeping.labels" . | nindent 4 }} -------------------------------------------------------------------------------- /web/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9-slim 2 | WORKDIR /app 3 | COPY requirements.txt . 4 | RUN pip install --no-cache-dir -r requirements.txt 5 | COPY . . 6 | ENV GUNICORN_CMD_ARGS="--workers 2 --bind 0.0.0.0:8000 --log-level info" 7 | ENTRYPOINT ["gunicorn"] 8 | CMD ["app:app"] -------------------------------------------------------------------------------- /helm/templates/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: {{ include "kubeping.fullname" . }}-exporter 5 | labels: 6 | {{- include "kubeping.labels" . | nindent 4 }} 7 | data: 8 | config.yaml: |- 9 | {{ toYaml .Values.exporter.config | indent 4 }} -------------------------------------------------------------------------------- /helm/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: kubeping 3 | description: A Helm chart for KubePing 4 | type: application 5 | version: "1.0.0" 6 | appVersion: "1.0.0" 7 | sources: 8 | - https://github.com/teymurgahramanov/kubeping 9 | maintainers: 10 | - email: teymur_gahramanov@outlook.com 11 | name: Teymur Gahramanov 12 | -------------------------------------------------------------------------------- /exporter/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.21.6 AS build 2 | WORKDIR /app 3 | COPY . . 4 | RUN \ 5 | if ! test -f bin/kubeping-exporter; then \ 6 | CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -o bin/kubeping-exporter; \ 7 | fi 8 | FROM scratch as final 9 | COPY --from=build /app/bin/kubeping-exporter / 10 | ENTRYPOINT [ "/kubeping-exporter" ] -------------------------------------------------------------------------------- /exporter/modules/tcp.go: -------------------------------------------------------------------------------- 1 | package modules 2 | 3 | import ( 4 | "net" 5 | "time" 6 | ) 7 | 8 | // ProbeTCP is for probe TCP endpoints 9 | func ProbeTCP(address string, timeout int) (bool,error) { 10 | conn, err := net.DialTimeout("tcp", address, time.Duration(timeout)*time.Second) 11 | if err != nil { 12 | return false, err 13 | } 14 | defer conn.Close() 15 | return true, nil 16 | } -------------------------------------------------------------------------------- /exporter/modules/icmp.go: -------------------------------------------------------------------------------- 1 | package modules 2 | 3 | import ( 4 | probing "github.com/prometheus-community/pro-bing" 5 | ) 6 | 7 | func ProbeICMP(address string) (bool, error) { 8 | pinger, err := probing.NewPinger(address) 9 | if err != nil { 10 | return false, err 11 | } 12 | pinger.Count = 3 13 | // SET TIMEOUT 14 | err = pinger.Run() 15 | if err != nil { 16 | return false, err 17 | } 18 | return true, nil 19 | } -------------------------------------------------------------------------------- /helm/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *.orig 18 | *~ 19 | # Various IDEs 20 | .project 21 | .idea/ 22 | *.tmproj 23 | .vscode/ 24 | -------------------------------------------------------------------------------- /helm/templates/service-web.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "kubeping.fullname" . }}-web 5 | labels: 6 | {{- include "kubeping.labels" . | nindent 4 }} 7 | spec: 8 | type: {{ .Values.web.service.type }} 9 | ports: 10 | - port: 8000 11 | targetPort: http 12 | protocol: TCP 13 | name: http 14 | {{- if eq .Values.web.service.type "NodePort" }} 15 | nodePort: {{ .Values.web.service.nodePort }} 16 | {{- end }} 17 | selector: 18 | {{- include "kubeping-web.selectorLabels" . | nindent 4 }} -------------------------------------------------------------------------------- /helm/templates/rbac.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: Role 4 | metadata: 5 | name: {{ include "kubeping.fullname" . }} 6 | rules: 7 | - apiGroups: [""] 8 | resources: ["pods"] 9 | verbs: ["get", "list", "watch"] 10 | --- 11 | apiVersion: rbac.authorization.k8s.io/v1 12 | kind: RoleBinding 13 | metadata: 14 | name: {{ include "kubeping.fullname" . }} 15 | subjects: 16 | - kind: ServiceAccount 17 | name: {{ include "kubeping.fullname" . }} 18 | roleRef: 19 | kind: Role 20 | name: {{ include "kubeping.fullname" . }} 21 | apiGroup: rbac.authorization.k8s.io -------------------------------------------------------------------------------- /helm/templates/service-exporter.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "kubeping.fullname" . }}-exporter 5 | labels: 6 | {{- include "kubeping.labels" . | nindent 4 }} 7 | spec: 8 | type: {{ .Values.exporter.service.type }} 9 | ports: 10 | - port: 8000 11 | targetPort: http 12 | protocol: TCP 13 | name: http 14 | {{- if eq .Values.exporter.service.type "NodePort" }} 15 | nodePort: {{ .Values.exporter.service.nodePort }} 16 | {{- end }} 17 | selector: 18 | {{- include "kubeping-exporter.selectorLabels" . | nindent 4 }} -------------------------------------------------------------------------------- /exporter/modules/http.go: -------------------------------------------------------------------------------- 1 | package modules 2 | 3 | import ( 4 | "crypto/tls" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | // ProbeHTTP is for probe HTTP endpoints 10 | func ProbeHTTP(address string, timeout int) (bool,error) { 11 | tr := &http.Transport{ 12 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 13 | } 14 | client := &http.Client{ 15 | Transport: tr, 16 | Timeout: time.Duration(timeout)*time.Second, 17 | } 18 | resp, err := client.Get(address) 19 | if err != nil { 20 | return false, err 21 | } 22 | defer resp.Body.Close() 23 | if resp.StatusCode != http.StatusOK { 24 | return false, nil 25 | } 26 | return true, nil 27 | } -------------------------------------------------------------------------------- /helm/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.web.ingress.enabled -}} 2 | apiVersion: networking.k8s.io/v1 3 | kind: Ingress 4 | metadata: 5 | name: {{ include "kubeping.fullname" . }} 6 | labels: 7 | {{- include "kubeping.labels" . | nindent 4 }} 8 | {{- with .Values.web.ingress.annotations }} 9 | annotations: 10 | {{- toYaml . | nindent 4 }} 11 | {{- end }} 12 | spec: 13 | {{- with .Values.web.ingress.className }} 14 | ingressClassName: {{ . }} 15 | {{- end }} 16 | rules: 17 | - host: {{ .Values.web.ingress.host }} 18 | http: 19 | paths: 20 | - path: / 21 | pathType: ImplementationSpecific 22 | backend: 23 | service: 24 | name: {{ include "kubeping.fullname" $ }}-web 25 | port: 26 | number: 8000 27 | {{- end }} -------------------------------------------------------------------------------- /exporter/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/teymurgahramanov/KubePing/exporter 2 | 3 | go 1.21.6 4 | 5 | require ( 6 | github.com/prometheus/client_golang v1.18.0 7 | gopkg.in/yaml.v3 v3.0.1 8 | ) 9 | 10 | require ( 11 | github.com/beorn7/perks v1.0.1 // indirect 12 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 13 | github.com/google/uuid v1.6.0 // indirect 14 | github.com/kr/text v0.2.0 // indirect 15 | github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect 16 | github.com/prometheus-community/pro-bing v0.3.0 // indirect 17 | github.com/prometheus/client_model v0.5.0 // indirect 18 | github.com/prometheus/common v0.46.0 // indirect 19 | github.com/prometheus/procfs v0.12.0 // indirect 20 | golang.org/x/net v0.21.0 // indirect 21 | golang.org/x/sync v0.6.0 // indirect 22 | golang.org/x/sys v0.17.0 // indirect 23 | google.golang.org/protobuf v1.32.0 // indirect 24 | ) 25 | -------------------------------------------------------------------------------- /helm/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{- define "kubeping.name" -}} 2 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} 3 | {{- end }} 4 | 5 | {{- define "kubeping.fullname" -}} 6 | {{- if .Values.fullnameOverride }} 7 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} 8 | {{- else }} 9 | {{- $name := default .Chart.Name .Values.nameOverride }} 10 | {{- if contains $name .Release.Name }} 11 | {{- .Release.Name | trunc 63 | trimSuffix "-" }} 12 | {{- else }} 13 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} 14 | {{- end }} 15 | {{- end }} 16 | {{- end }} 17 | 18 | {{- define "kubeping.chart" -}} 19 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} 20 | {{- end }} 21 | 22 | {{- define "kubeping.labels" -}} 23 | helm.sh/chart: {{ include "kubeping.chart" . }} 24 | app.kubernetes.io/name: {{ include "kubeping.fullname" . }} 25 | {{- if .Chart.AppVersion }} 26 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 27 | {{- end }} 28 | app.kubernetes.io/managed-by: {{ .Release.Service }} 29 | {{- end }} 30 | 31 | {{- define "kubeping-exporter.selectorLabels" -}} 32 | kubeping/component: exporter 33 | {{- end }} 34 | 35 | {{- define "kubeping-web.selectorLabels" -}} 36 | kubeping/component: web 37 | {{- end }} -------------------------------------------------------------------------------- /helm/values.yaml: -------------------------------------------------------------------------------- 1 | nameOverride: "" 2 | fullnameOverride: "" 3 | imagePullSecrets: [] 4 | imagePullPolicy: IfNotPresent 5 | 6 | exporter: 7 | image: 8 | repository: teymurgahramanov/kubeping-exporter 9 | tag: 1.0.0 10 | config: {} 11 | # exporter: 12 | # listenPort: 8000 13 | # defaultProbeInterval: 15 14 | # defaultProbeTimeout: 10 15 | # targets: 16 | # target1: 17 | # address: api.example.com:8080 18 | # module: tcp 19 | # timeout: 15 20 | # target2: 21 | # address: https://example.com 22 | # module: http 23 | # interval: 60 24 | # target3: 25 | # address: 192.168.0.1 26 | # module: icmp 27 | service: 28 | type: ClusterIP 29 | nodePort: "" 30 | daemonsetAnnotations: {} 31 | podLabels: {} 32 | podAnnotations: {} 33 | nodeSelector: {} 34 | affinity: {} 35 | tolerations: [] 36 | resources: {} 37 | volumes: {} 38 | volumeMounts: {} 39 | podSecurityContext: {} 40 | securityContext: {} 41 | 42 | web: 43 | image: 44 | repository: teymurgahramanov/kubeping-web 45 | tag: 1.0.0 46 | service: 47 | type: ClusterIP 48 | nodePort: "" 49 | deploymentAnnotations: {} 50 | ingress: 51 | enabled: false 52 | annotations: {} 53 | className: "" 54 | host: "" 55 | env: {} 56 | podLabels: {} 57 | podAnnotations: {} 58 | nodeSelector: {} 59 | affinity: {} 60 | tolerations: [] 61 | resources: {} 62 | volumes: {} 63 | volumeMounts: {} 64 | podSecurityContext: {} 65 | securityContext: {} -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | release-name: 7 | type: string 8 | description: Release name 9 | required: true 10 | 11 | jobs: 12 | release: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | contents: write 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: Set up Docker Buildx 21 | uses: docker/setup-buildx-action@v3 22 | 23 | - name: Login to Docker Hub 24 | uses: docker/login-action@v3 25 | with: 26 | username: ${{ secrets.DOCKERHUB_USERNAME }} 27 | password: ${{ secrets.DOCKERHUB_TOKEN }} 28 | 29 | - name: Build and push exporter 30 | uses: docker/build-push-action@v5 31 | with: 32 | context: ./exporter 33 | file: ./exporter/Dockerfile 34 | push: true 35 | tags: ${{ github.repository }}-exporter:${{ inputs.release-name }}, ${{ github.repository }}-exporter:latest 36 | 37 | - name: Build and push web 38 | uses: docker/build-push-action@v5 39 | with: 40 | context: ./web 41 | file: ./web/Dockerfile 42 | push: true 43 | tags: ${{ github.repository }}-web:${{ inputs.release-name }}, ${{ github.repository }}-web:latest 44 | 45 | - name: Package Helm chart 46 | run: | 47 | helm package ./helm --destination ./helm-packaged 48 | 49 | - name: Create Release 50 | uses: ncipollo/release-action@v1 51 | with: 52 | name: ${{ inputs.release-name }} 53 | tag: ${{ inputs.release-name }} 54 | bodyFile: "CHANGELOG.md" 55 | artifacts: "./helm-packaged/*.tgz" 56 | allowUpdates: true 57 | artifactErrorsFailBuild: true 58 | makeLatest: true 59 | -------------------------------------------------------------------------------- /skaffold.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: skaffold/v3 3 | kind: Config 4 | metadata: 5 | name: kubeping 6 | 7 | build: 8 | artifacts: 9 | - image: kubeping-exporter 10 | context: ./exporter 11 | docker: 12 | dockerfile: Dockerfile 13 | - image: kubeping-web 14 | context: ./web 15 | docker: 16 | dockerfile: Dockerfile 17 | 18 | deploy: 19 | helm: 20 | releases: 21 | - name: kubeping 22 | namespace: kubeping 23 | createNamespace: true 24 | chartPath: ./helm 25 | setValueTemplates: 26 | exporter.image.repository: "{{ .IMAGE_REPO_kubeping_exporter }}" 27 | exporter.image.tag: "{{ .IMAGE_TAG_kubeping_exporter }}" 28 | web.image.repository: "{{ .IMAGE_REPO_kubeping_web }}" 29 | web.image.tag: "{{ .IMAGE_TAG_kubeping_web }}" 30 | setValues: 31 | exporter.config.exporter.defaultProbeInterval: "31" 32 | exporter.config.exporter.defaultProbeTimeout: "13" 33 | exporter.config.targets.target1.address: "example.com:443" 34 | exporter.config.targets.target1.module: "tcp" 35 | exporter.config.targets.target1.timeout: "18" 36 | exporter.config.targets.target2.address: "https://example.com" 37 | exporter.config.targets.target2.module: "http" 38 | exporter.config.targets.target2.interval: "12" 39 | exporter.config.targets.target3.address: "example.com" 40 | exporter.config.targets.target3.module: "icmp" 41 | exporter.config.targets.target4.address: "api.example.com:8000" 42 | exporter.config.targets.target4.module: "tcp" 43 | exporter.config.targets.target4.timeout: "15" 44 | exporter.config.targets.target5.address: "https://example.com/x/y/z" 45 | exporter.config.targets.target5.module: "http" 46 | exporter.config.targets.target5.interval: "60" 47 | exporter.config.targets.target6.address: "192.168.168.168" 48 | exporter.config.targets.target6.module: "icmp" 49 | 50 | portForward: 51 | - resourceType: deployment 52 | resourceName: kubeping-web 53 | namespace: kubeping 54 | port: 8000 55 | localPort: 9001 56 | - resourceType: daemonset 57 | resourceName: kubeping-exporter 58 | namespace: kubeping 59 | port: 8000 60 | localPort: 9002 61 | 62 | profiles: 63 | - name: docker-desktop 64 | activation: 65 | - kubeContext: docker-desktop 66 | command: dev -------------------------------------------------------------------------------- /web/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, session, redirect, url_for 2 | from kubernetes import client, config as k8s_config 3 | from config import config 4 | import requests 5 | import concurrent.futures 6 | 7 | k8s_config.load_incluster_config() 8 | with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: 9 | current_namespace = f.read().strip() 10 | v1 = client.CoreV1Api() 11 | 12 | label_selector = "kubeping/component=exporter" 13 | exporter_port = 8000 14 | exporter_probe_path = '/probe' 15 | app_version = config.APP_VERSION 16 | 17 | app = Flask(__name__) 18 | app.secret_key = 'secret' 19 | 20 | @app.route('/') 21 | def index(): 22 | return render_template('index.html', version=app_version) 23 | 24 | @app.route('/submit', methods=['POST']) 25 | def submit(): 26 | data = { 27 | "module": "tcp", 28 | "address": request.form['address'], 29 | "timeout": int(request.form['timeout']) 30 | } 31 | exporters = {} 32 | session['results'] = [] 33 | pods = v1.list_namespaced_pod(namespace=current_namespace, label_selector=label_selector) 34 | 35 | if not pods.items: 36 | session['results'].append({ 37 | "host": 0, 38 | "result": f"Can't find kubeping-exporter pods with label selector {label_selector}" 39 | }) 40 | else: 41 | for pod in pods.items: 42 | exporters[pod.metadata.name] = { 43 | "host": pod.status.host_ip, 44 | "api_url": f"http://{pod.status.pod_ip}:{exporter_port}{exporter_probe_path}" 45 | } 46 | 47 | with concurrent.futures.ThreadPoolExecutor() as executor: 48 | futures = [executor.submit(probe, exporter, data) for exporter in exporters.values()] 49 | for future in concurrent.futures.as_completed(futures): 50 | result = future.result() 51 | if result: 52 | session['results'].append(result) 53 | 54 | return render_template('index.html', version=app_version, results=session['results']) 55 | 56 | def probe(exporter, data): 57 | try: 58 | response = requests.post(exporter["api_url"], json=data, timeout=data['timeout']*2) 59 | response_data = response.json() 60 | result = response_data.get("error", response_data.get("result")) 61 | except Exception as e: 62 | result = str(e) 63 | 64 | return { 65 | "host": exporter["host"], 66 | "result": result 67 | } 68 | 69 | if __name__ == '__main__': 70 | app.run() -------------------------------------------------------------------------------- /helm/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ include "kubeping.fullname" . }}-web 5 | labels: 6 | {{- include "kubeping.labels" . | nindent 4 }} 7 | annotations: 8 | {{- with .Values.web.deploymentAnnotations }} 9 | {{- toYaml . | nindent 4 }} 10 | {{- end }} 11 | spec: 12 | replicas: 1 13 | selector: 14 | matchLabels: 15 | {{- include "kubeping-web.selectorLabels" . | nindent 6 }} 16 | template: 17 | metadata: 18 | {{- with .Values.web.podAnnotations }} 19 | annotations: 20 | {{- toYaml . | nindent 8 }} 21 | {{- end }} 22 | labels: 23 | {{- include "kubeping.labels" . | nindent 8 }} 24 | {{- include "kubeping-web.selectorLabels" . | nindent 8 }} 25 | {{- with .Values.web.podLabels }} 26 | {{- toYaml . | nindent 8 }} 27 | {{- end }} 28 | spec: 29 | {{- with .Values.imagePullSecrets }} 30 | imagePullSecrets: 31 | {{- toYaml . | nindent 8 }} 32 | {{- end }} 33 | {{- with .Values.web.podSecurityContext }} 34 | securityContext: 35 | {{- toYaml . | nindent 8 }} 36 | {{- end }} 37 | serviceAccountName: {{ include "kubeping.fullname" . }} 38 | containers: 39 | - name: {{ .Chart.Name }} 40 | {{- with .Values.web.securityContext }} 41 | securityContext: 42 | {{- toYaml . | nindent 12 }} 43 | {{- end }} 44 | image: "{{ .Values.web.image.repository }}:{{ .Values.web.image.tag | default .Chart.AppVersion }}" 45 | imagePullPolicy: {{ .Values.imagePullPolicy }} 46 | ports: 47 | - name: http 48 | containerPort: 8000 49 | protocol: TCP 50 | {{- with .Values.web.livenessProbe }} 51 | livenessProbe: 52 | {{- toYaml . | nindent 12 }} 53 | {{- end }} 54 | {{- with .Values.web.readinessProbe }} 55 | readinessProbe: 56 | {{- toYaml . | nindent 12 }} 57 | {{- end }} 58 | {{- with .Values.web.env }} 59 | env: 60 | {{- toYaml .Values.web.env | nindent 12 }} 61 | {{- end }} 62 | {{- with .Values.web.resources }} 63 | resources: 64 | {{- toYaml . | nindent 12 }} 65 | {{- end }} 66 | {{- with .Values.web.volumeMounts }} 67 | volumeMounts: 68 | {{- toYaml . | nindent 12 }} 69 | {{- end }} 70 | {{- with .Values.web.volumes }} 71 | volumes: 72 | {{- toYaml . | nindent 8 }} 73 | {{- end }} 74 | {{- with .Values.web.nodeSelector }} 75 | nodeSelector: 76 | {{- toYaml . | nindent 8 }} 77 | {{- end }} 78 | {{- with .Values.web.affinity }} 79 | affinity: 80 | {{- toYaml . | nindent 8 }} 81 | {{- end }} 82 | {{- with .Values.web.tolerations }} 83 | tolerations: 84 | {{- toYaml . | nindent 8 }} 85 | {{- end }} -------------------------------------------------------------------------------- /helm/templates/daemonset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: DaemonSet 3 | metadata: 4 | name: {{ include "kubeping.fullname" . }}-exporter 5 | labels: 6 | {{- include "kubeping.labels" . | nindent 4 }} 7 | annotations: 8 | {{- with .Values.exporter.daemonsetAnnotations }} 9 | {{- toYaml . | nindent 4 }} 10 | {{- end }} 11 | spec: 12 | selector: 13 | matchLabels: 14 | {{- include "kubeping-exporter.selectorLabels" . | nindent 6 }} 15 | template: 16 | metadata: 17 | {{- with .Values.exporter.podAnnotations }} 18 | annotations: 19 | {{- toYaml . | nindent 8 }} 20 | {{- end }} 21 | labels: 22 | {{- include "kubeping.labels" . | nindent 8 }} 23 | {{- include "kubeping-exporter.selectorLabels" . | nindent 8 }} 24 | {{- with .Values.exporter.podLabels }} 25 | {{- toYaml . | nindent 8 }} 26 | {{- end }} 27 | spec: 28 | {{- with .Values.imagePullSecrets }} 29 | imagePullSecrets: 30 | {{- toYaml . | nindent 8 }} 31 | {{- end }} 32 | {{- with .Values.exporter.podSecurityContext }} 33 | securityContext: 34 | {{- toYaml . | nindent 8 }} 35 | {{- end }} 36 | containers: 37 | - name: {{ .Chart.Name }} 38 | {{- with .Values.exporter.securityContext }} 39 | securityContext: 40 | {{- toYaml . | nindent 12 }} 41 | {{- end }} 42 | image: "{{ .Values.exporter.image.repository }}:{{ .Values.exporter.image.tag | default .Chart.AppVersion }}" 43 | imagePullPolicy: {{ .Values.imagePullPolicy }} 44 | ports: 45 | - name: http 46 | containerPort: 8000 47 | protocol: TCP 48 | {{- with .Values.exporter.livenessProbe }} 49 | livenessProbe: 50 | {{- toYaml . | nindent 12 }} 51 | {{- end }} 52 | {{- with .Values.exporter.readinessProbe }} 53 | readinessProbe: 54 | {{- toYaml . | nindent 12 }} 55 | {{- end }} 56 | {{- with .Values.exporter.env }} 57 | env: 58 | {{- toYaml .Values.exporter.env | nindent 12 }} 59 | {{- end }} 60 | {{- with .Values.exporter.resources }} 61 | resources: 62 | {{- toYaml . | nindent 12 }} 63 | {{- end }} 64 | volumeMounts: 65 | - name: config 66 | mountPath: /config.yaml 67 | subPath: config.yaml 68 | {{- with .Values.exporter.volumeMounts }} 69 | {{- toYaml . | nindent 12 }} 70 | {{- end }} 71 | volumes: 72 | - name: config 73 | configMap: 74 | name: {{ include "kubeping.fullname" . }}-exporter 75 | {{- with .Values.exporter.volumes }} 76 | {{- toYaml . | nindent 8 }} 77 | {{- end }} 78 | {{- with .Values.exporter.nodeSelector }} 79 | nodeSelector: 80 | {{- toYaml . | nindent 8 }} 81 | {{- end }} 82 | {{- with .Values.exporter.affinity }} 83 | affinity: 84 | {{- toYaml . | nindent 8 }} 85 | {{- end }} 86 | {{- with .Values.exporter.tolerations }} 87 | tolerations: 88 | {{- toYaml . | nindent 8 }} 89 | {{- end }} -------------------------------------------------------------------------------- /web/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | KubePing 7 | 8 | 9 | 10 | 11 |
12 |
13 |

KubePing

14 |
15 | 16 |
17 |
18 |
19 |
20 | 23 | 24 |
25 |
26 | 29 | 30 |
31 |
32 |
33 | 43 |
44 |
45 |
46 | 47 | {% if results %} 48 |
49 |

Results

50 |
51 | {% for result in results %} 52 |
53 |
54 | 55 | {{ result.host }} 56 |
57 |
58 | {% if result.result == true %} 59 | 60 | {% else %} 61 | {{ result.result }} 62 | {% endif %} 63 |
64 |
65 | {% endfor %} 66 |
67 |
68 | {% endif %} 69 |
70 | 71 | 80 | 81 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KubePing 2 | 3 | It is a Kubernetes solution designed to monitor the availability of external endpoints from each node of the Kubernetes cluster over TCP, HTTP, and ICMP. It exports Prometheus metrics and has a user-friendly web interface that helps you save time instead of making telnet/curl on each node. 4 | 5 |

6 | 7 |

8 | 9 | ## Use case 10 | In Kubernetes environments, ensuring the accessibility of external endpoints is crucial. Whether it's databases, APIs, or third-party services, connectivity issues can lead to degraded application performance or outages. Traditionally, engineers troubleshoot these issues by manually running telnet, curl, or ping commands on individual nodes. However, this process is time-consuming and inefficient, especially in large-scale clusters. 11 | 12 | __KubePing__ helps to solve these issues🎉 13 | 14 | Imagine a situation where your pods were evicted because of a node failure. The pods were then relocated to new nodes that had recently been added to the cluster. Unfortunately, this caused errors and resulted in service unavailability due to a lack of access to essential external endpoints. It was later discovered that the security department had failed to apply the appropriate access rules to the new cluster nodes. 15 | 16 | This is just one scenario that highlights how KubePing can help you identify potential issues before they escalate into major problems. 17 | 18 | ## How It Works 19 | The solution runs a lightweight DaemonSet in Kubernetes, ensuring that each node has a running instance. These instances probe external endpoints over: 20 | 21 | __TCP__ – Checking port availability (e.g., database:5432, api:443)\ 22 | __HTTP__ – Ensuring services respond with the expected status codes\ 23 | __ICMP (Ping)__ – Verifying network reachability 24 | 25 | The results are aggregated and exposed as Prometheus metrics: 26 | ``` 27 | probe_result{address="api.example.com:8080", instance="worker-node-1", job="kubeping", module="tcp", target="target1"}=1 28 | probe_result{address="api.example.com:8080", instance="worker-node-2", job="kubeping", module="tcp", target="target1"}=0 29 | probe_result{address="api.example.com:8080", instance="worker-node-3", job="kubeping", module="tcp", target="target1"}=1 30 | 31 | probe_result{address="https://example.com", instance="worker-node-1", job="kubeping", module="http", target="target2"}=0 32 | probe_result{address="https://example.com", instance="worker-node-2", job="kubeping", module="http", target="target2"}=1 33 | probe_result{address="https://example.com", instance="worker-node-3", job="kubeping", module="http", target="target2"}=1 34 | 35 | probe_result{address="192.168.0.1", instance="worker-node-1", job="kubeping", module="icmp", target="target3"}=1 36 | probe_result{address="192.168.0.1", instance="worker-node-2", job="kubeping", module="icmp", target="target3"}=0 37 | probe_result{address="192.168.0.1", instance="worker-node-3", job="kubeping", module="icmp", target="target3"}=1 38 | ``` 39 | 40 | And instead of SSH-ing into nodes, you can simply visit the web UI, where you can perform an ad-hoc connectivity test: 41 |

42 | 43 |

44 | 45 | Here is how KubePing can be integrated into your workflow: 46 |

47 | 48 |

49 | 50 | ## Installation 51 | ### Helm 52 | Clone repository 53 | ``` 54 | git clone https://github.com/teymurgahramanov/kubeping.git && cd kubeping 55 | ``` 56 | Install Helm chart 57 | ``` 58 | helm upgrade --install kubeping ./helm 59 | ``` 60 | Test Web UI 61 | ``` 62 | kubectl port-forward svc/kubeping-web 8000:8000 63 | ``` 64 | To configure the exporter with static targets, refer to [values.yaml](./helm/values.yaml). Here is an example: 65 | ```yaml 66 | exporter: 67 | config: 68 | exporter: 69 | defaultProbeInterval: 31 70 | defaultProbeTimeout: 13 71 | targets: 72 | target1: 73 | address: api.example.com:8080 74 | module: tcp 75 | timeout: 15 76 | target2: 77 | address: https://example.com 78 | module: http 79 | interval: 60 80 | target3: 81 | address: 192.168.0.1 82 | module: icmp 83 | ``` 84 | 85 | ### Prometheus 86 | Example job configuration: 87 | ```yaml 88 | - job_name: kubeping 89 | kubernetes_sd_configs: 90 | - role: endpoints 91 | relabel_configs: 92 | - source_labels: [__meta_kubernetes_endpoints_name] 93 | regex: kubeping-exporter 94 | action: keep 95 | - source_labels: [__meta_kubernetes_endpoint_node_name] 96 | action: replace 97 | target_label: instance 98 | ``` 99 | -------------------------------------------------------------------------------- /web/static/styles.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --primary-color: #4f46e5; 3 | --primary-hover: #4338ca; 4 | --success-color: #22c55e; 5 | --error-color: #ef4444; 6 | --background-color: #f8fafc; 7 | --card-background: #ffffff; 8 | --text-color: #1e293b; 9 | --text-secondary: #64748b; 10 | --border-color: #e2e8f0; 11 | --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1); 12 | --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); 13 | } 14 | 15 | * { 16 | margin: 0; 17 | padding: 0; 18 | box-sizing: border-box; 19 | } 20 | 21 | body { 22 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; 23 | background-color: var(--background-color); 24 | color: var(--text-color); 25 | line-height: 1.5; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | } 30 | 31 | .container { 32 | max-width: 1200px; 33 | margin: 0 auto; 34 | padding: 2rem; 35 | flex: 1; 36 | } 37 | 38 | .header { 39 | text-align: center; 40 | margin-bottom: 2rem; 41 | } 42 | 43 | .header h1 { 44 | font-size: 2.5rem; 45 | color: var(--primary-color); 46 | display: flex; 47 | align-items: center; 48 | justify-content: center; 49 | gap: 0.75rem; 50 | } 51 | 52 | .card { 53 | background: var(--card-background); 54 | border-radius: 12px; 55 | padding: 2rem; 56 | box-shadow: var(--shadow-md); 57 | margin-bottom: 2rem; 58 | transition: transform 0.2s ease-in-out; 59 | } 60 | 61 | .card:hover { 62 | transform: translateY(-2px); 63 | } 64 | 65 | .form-row { 66 | display: grid; 67 | grid-template-columns: 1fr 1fr; 68 | gap: 1.5rem; 69 | margin-bottom: 1.5rem; 70 | } 71 | 72 | @media (max-width: 640px) { 73 | .form-row { 74 | grid-template-columns: 1fr; 75 | } 76 | } 77 | 78 | .form-group { 79 | display: flex; 80 | flex-direction: column; 81 | gap: 0.5rem; 82 | } 83 | 84 | label { 85 | font-weight: 500; 86 | color: var(--text-color); 87 | display: flex; 88 | align-items: center; 89 | gap: 0.5rem; 90 | } 91 | 92 | input { 93 | padding: 0.75rem 1rem; 94 | border: 1px solid var(--border-color); 95 | border-radius: 8px; 96 | font-size: 1rem; 97 | transition: all 0.2s ease; 98 | } 99 | 100 | input:focus { 101 | outline: none; 102 | border-color: var(--primary-color); 103 | box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1); 104 | } 105 | 106 | .form-submit { 107 | text-align: center; 108 | } 109 | 110 | button { 111 | background-color: var(--primary-color); 112 | color: white; 113 | border: none; 114 | padding: 0.75rem 2rem; 115 | border-radius: 8px; 116 | font-size: 1rem; 117 | font-weight: 500; 118 | cursor: pointer; 119 | transition: all 0.2s ease; 120 | display: inline-flex; 121 | align-items: center; 122 | gap: 0.5rem; 123 | } 124 | 125 | button:hover { 126 | background-color: var(--primary-hover); 127 | transform: translateY(-1px); 128 | } 129 | 130 | button .btn-loading { 131 | display: none; 132 | } 133 | 134 | button.loading .btn-content { 135 | display: none; 136 | } 137 | 138 | button.loading .btn-loading { 139 | display: inline-flex; 140 | align-items: center; 141 | gap: 0.5rem; 142 | } 143 | 144 | .results-container { 145 | margin-top: 3rem; 146 | } 147 | 148 | .results-container h2 { 149 | color: var(--text-color); 150 | margin-bottom: 1.5rem; 151 | display: flex; 152 | align-items: center; 153 | gap: 0.75rem; 154 | } 155 | 156 | .results-grid { 157 | display: grid; 158 | grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); 159 | gap: 1rem; 160 | } 161 | 162 | .result-card { 163 | background: var(--card-background); 164 | border-radius: 10px; 165 | padding: 1.5rem; 166 | box-shadow: var(--shadow-sm); 167 | transition: transform 0.2s ease; 168 | } 169 | 170 | .result-card:hover { 171 | transform: translateY(-2px); 172 | } 173 | 174 | .result-card.success { 175 | border-left: 4px solid var(--success-color); 176 | } 177 | 178 | .result-card.error { 179 | border-left: 4px solid var(--error-color); 180 | } 181 | 182 | .result-header { 183 | display: flex; 184 | align-items: center; 185 | gap: 0.75rem; 186 | margin-bottom: 1rem; 187 | color: var(--text-secondary); 188 | } 189 | 190 | .result-content { 191 | font-size: 1rem; 192 | word-break: break-word; 193 | } 194 | 195 | .success-icon { 196 | font-size: 1.5rem; 197 | } 198 | 199 | .footer { 200 | text-align: center; 201 | padding: 2rem; 202 | background-color: var(--card-background); 203 | border-top: 1px solid var(--border-color); 204 | } 205 | 206 | .footer p { 207 | display: flex; 208 | align-items: center; 209 | justify-content: center; 210 | gap: 1rem; 211 | color: var(--text-secondary); 212 | } 213 | 214 | .footer a { 215 | color: var(--primary-color); 216 | text-decoration: none; 217 | display: flex; 218 | align-items: center; 219 | gap: 0.5rem; 220 | transition: color 0.2s ease; 221 | } 222 | 223 | .footer a:hover { 224 | color: var(--primary-hover); 225 | } 226 | 227 | .separator { 228 | color: var(--border-color); 229 | } -------------------------------------------------------------------------------- /exporter/go.sum: -------------------------------------------------------------------------------- 1 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 2 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 3 | github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= 4 | github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 5 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 6 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 9 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 10 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 11 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 12 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 13 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 14 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 15 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 16 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 17 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 18 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 19 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 20 | github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= 21 | github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= 22 | github.com/prometheus-community/pro-bing v0.3.0 h1:SFT6gHqXwbItEDJhTkzPWVqU6CLEtqEfNAPp47RUON4= 23 | github.com/prometheus-community/pro-bing v0.3.0/go.mod h1:p9dLb9zdmv+eLxWfCT6jESWuDrS+YzpPkQBgysQF8a0= 24 | github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= 25 | github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= 26 | github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= 27 | github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= 28 | github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= 29 | github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= 30 | github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y= 31 | github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ= 32 | github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= 33 | github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= 34 | github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= 35 | github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= 36 | golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= 37 | golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= 38 | golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= 39 | golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= 40 | golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= 41 | golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= 42 | golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= 43 | golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 44 | golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= 45 | golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 46 | golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= 47 | golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 48 | golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= 49 | golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 50 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 51 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 52 | google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= 53 | google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 54 | google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= 55 | google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 56 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 57 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 58 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 59 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 60 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 61 | -------------------------------------------------------------------------------- /exporter/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log/slog" 7 | "net/http" 8 | "os" 9 | "sync" 10 | "time" 11 | 12 | "github.com/prometheus/client_golang/prometheus" 13 | "github.com/prometheus/client_golang/prometheus/promhttp" 14 | "github.com/teymurgahramanov/KubePing/exporter/modules" 15 | "gopkg.in/yaml.v3" 16 | ) 17 | 18 | type configuration struct { 19 | Targets map[string]targetConfig `yaml:"targets"` 20 | Exporter exporterConfig `yaml:"exporter"` 21 | } 22 | 23 | type targetConfig struct { 24 | Address string `yaml:"address"` 25 | Module string `yaml:"module"` 26 | Interval int `yaml:"interval"` 27 | Timeout int `yaml:"timeout"` 28 | } 29 | 30 | type exporterConfig struct { 31 | ListenPort int `yaml:"listenPort"` 32 | DefaultProbeInterval int `yaml:"defaultProbeInterval"` 33 | DefaultProbeTimeout int `yaml:"defaultProbeTimeout"` 34 | } 35 | 36 | type probeRequest struct { 37 | Module string `json:"module"` 38 | Address string `json:"address"` 39 | Timeout int `json:"timeout"` 40 | } 41 | 42 | type probeResponse struct { 43 | Result bool `json:"result"` 44 | Error string `json:"error,omitempty"` 45 | } 46 | 47 | func main() { 48 | logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) 49 | configFile := "config.yaml" 50 | var config configuration 51 | 52 | // **Ensure Targets map is always initialized** 53 | config.Targets = make(map[string]targetConfig) 54 | 55 | // Set default exporter values 56 | config.Exporter.ListenPort = 8000 57 | config.Exporter.DefaultProbeInterval = 30 58 | config.Exporter.DefaultProbeTimeout = 5 59 | 60 | // Try reading the config file 61 | data, err := os.ReadFile(configFile) 62 | if err != nil { 63 | if os.IsNotExist(err) { 64 | logger.Error(fmt.Sprintf("Config file %s not found, proceeding with defaults", configFile)) 65 | } else { 66 | logger.Error(fmt.Sprintf("Failed to read config file %s: %v", configFile, err)) 67 | } 68 | } else { 69 | err = yaml.Unmarshal(data, &config) 70 | if err != nil { 71 | logger.Error(fmt.Sprintf("Failed to parse config file %s: %v", configFile, err)) 72 | } 73 | } 74 | 75 | // Ensure default values are applied if missing in the config file 76 | if config.Exporter.ListenPort == 0 { 77 | config.Exporter.ListenPort = 8000 78 | } 79 | if config.Exporter.DefaultProbeInterval == 0 { 80 | config.Exporter.DefaultProbeInterval = 30 81 | } 82 | if config.Exporter.DefaultProbeTimeout == 0 { 83 | config.Exporter.DefaultProbeTimeout = 5 84 | } 85 | 86 | // **Log message to indicate program continues execution** 87 | logger.Info("Starting server with final configuration", slog.Any("config", config)) 88 | 89 | // Prometheus metric setup 90 | var ( 91 | probeResult = prometheus.NewGaugeVec( 92 | prometheus.GaugeOpts{ 93 | Name: "probe_result", 94 | Help: "Current status of the probe (1 for success, 0 for failure)", 95 | }, 96 | []string{"target", "module", "address"}, 97 | ) 98 | ) 99 | 100 | promRegistry := prometheus.NewRegistry() 101 | prometheus.DefaultRegisterer = promRegistry 102 | prometheus.DefaultGatherer = promRegistry 103 | prometheus.MustRegister(probeResult) 104 | 105 | // HTTP handlers 106 | http.Handle("/metrics", promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})) 107 | http.HandleFunc("/probe", func(w http.ResponseWriter, r *http.Request) { 108 | if r.Method != http.MethodPost { 109 | http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) 110 | return 111 | } 112 | 113 | var request probeRequest 114 | err := json.NewDecoder(r.Body).Decode(&request) 115 | if err != nil { 116 | http.Error(w, "Bad request", http.StatusBadRequest) 117 | return 118 | } 119 | 120 | timeout := request.Timeout 121 | if timeout == 0 { 122 | timeout = config.Exporter.DefaultProbeTimeout 123 | } 124 | 125 | resultHandler := func(result bool, err error) { 126 | var response probeResponse 127 | response.Result = false 128 | if result { 129 | logger.Info("Probe successful") 130 | response.Result = true 131 | } else { 132 | if err != nil { 133 | logger.Error(fmt.Sprint(err.Error())) 134 | } 135 | response.Error = err.Error() 136 | } 137 | w.Header().Set("Content-Type", "application/json") 138 | json.NewEncoder(w).Encode(response) 139 | } 140 | 141 | switch request.Module { 142 | case "tcp": 143 | result, err := modules.ProbeTCP(request.Address, timeout) 144 | resultHandler(result, err) 145 | case "http": 146 | result, err := modules.ProbeHTTP(request.Address, timeout) 147 | resultHandler(result, err) 148 | case "icmp": 149 | result, err := modules.ProbeICMP(request.Address) 150 | resultHandler(result, err) 151 | default: 152 | logger.Error("Unknown module") 153 | http.Error(w, "Unknown module", http.StatusBadRequest) 154 | return 155 | } 156 | }) 157 | 158 | // Start HTTP server 159 | go func() { 160 | err := http.ListenAndServe(fmt.Sprintf(":%d", config.Exporter.ListenPort), nil) 161 | if err != nil { 162 | logger.Error(fmt.Sprintf("Failed to start HTTP server: %v", err)) 163 | os.Exit(1) 164 | } 165 | }() 166 | 167 | var wg sync.WaitGroup 168 | 169 | // **If no targets exist, ensure the program does not deadlock** 170 | if len(config.Targets) == 0 { 171 | logger.Info("No targets configured, service running with only HTTP API") 172 | select {} // Keeps the program running if no targets exist 173 | } 174 | 175 | // Start probes if any targets are defined 176 | for key, value := range config.Targets { 177 | wg.Add(1) 178 | go func(target string, module string, address string, interval int, timeout int) { 179 | defer wg.Done() 180 | if interval == 0 { 181 | interval = config.Exporter.DefaultProbeInterval 182 | } 183 | if timeout == 0 { 184 | timeout = config.Exporter.DefaultProbeTimeout 185 | } 186 | targetLogger := logger.With(slog.String("target", target)) 187 | resultHandler := func(result bool, err error, interval int) { 188 | if result { 189 | targetLogger.Info("Probe successful") 190 | probeResult.WithLabelValues(target, module, address).Set(1) 191 | } else { 192 | if err != nil { 193 | targetLogger.Error(fmt.Sprint(err.Error())) 194 | } 195 | probeResult.WithLabelValues(target, module, address).Set(0) 196 | } 197 | time.Sleep(time.Duration(interval) * time.Second) 198 | } 199 | switch module { 200 | case "tcp": 201 | for { 202 | result, err := modules.ProbeTCP(address, timeout) 203 | resultHandler(result, err, interval) 204 | } 205 | case "http": 206 | for { 207 | result, err := modules.ProbeHTTP(address, timeout) 208 | resultHandler(result, err, interval) 209 | } 210 | case "icmp": 211 | for { 212 | result, err := modules.ProbeICMP(address) 213 | resultHandler(result, err, interval) 214 | } 215 | default: 216 | targetLogger.Error("Unknown module") 217 | } 218 | }(key, value.Module, value.Address, value.Interval, value.Timeout) 219 | } 220 | 221 | wg.Wait() 222 | } 223 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /kubeping.drawio: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | --------------------------------------------------------------------------------