Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 1 | {{/* |
| 2 | # Copyright 2021-present Open Networking Foundation |
| 3 | |
| 4 | # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
| 5 | */}} |
| 6 | |
| 7 | apiVersion: v1 |
| 8 | kind: ConfigMap |
| 9 | metadata: |
| 10 | name: "tost-telegraf-config-script" |
| 11 | labels: |
| 12 | chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" |
| 13 | release: "{{ .Release.Name }}" |
| 14 | app: tost-telegraf |
| 15 | data: |
Yi Tseng | 0e78d9d | 2021-10-21 18:15:03 -0700 | [diff] [blame^] | 16 | sdfabric_telegraf.sh: | |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 17 | #!/bin/bash |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 18 | set -x |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 19 | #Locale setting for json_pp |
| 20 | export LC_CTYPE="POSIX" |
| 21 | export LC_NUMERIC="POSIX" |
| 22 | |
| 23 | #Install kubectl |
| 24 | curl -sLO https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl |
| 25 | install -m 755 kubectl /usr/local/bin/kubectl |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 26 | |
| 27 | while IFS= read -r LINE; do |
| 28 | ACTIVE_LINKS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \ |
| 29 | http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/links | json_pp | grep "\"state\" : \"ACTIVE\"" | wc -l) |
| 30 | |
| 31 | ENABLE_DEVICE_PORTS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \ |
| 32 | http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/devices/ports | json_pp | grep "\"isEnabled\" : true" | wc -l) |
| 33 | |
| 34 | DEVICES=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \ |
| 35 | http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/devices | json_pp | grep "\"type\" : \"SWITCH\"" | wc -l) |
| 36 | |
Yi Tseng | 0e78d9d | 2021-10-21 18:15:03 -0700 | [diff] [blame^] | 37 | ONOS_PODS=$(kubectl get po -l app=onos-classic -o name) |
| 38 | for POD in $ONOS_PODS; do |
| 39 | ONOS_READY=$(kubectl -n {{ .Values.onos.namespace }} get ${POD} --no-headers -o custom-columns=':.status.containerStatuses[*].ready' | grep true | wc -l) |
| 40 | echo "onos_telegraf,type=onos,onos_pod=${POD} ready=${ONOS_READY}" |
| 41 | done |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 42 | # Config Pod's ready status indicate the status of ONOS cluster |
| 43 | # Assumption: Config Pod has only one instance |
Yi Tseng | 3674e49 | 2021-10-19 15:35:27 -0700 | [diff] [blame] | 44 | ONOS_READY=$(kubectl -n {{ .Values.onos.namespace }} get pods -l {{ .Values.onos.component_label }} --no-headers -o custom-columns=':.status.containerStatuses[*].ready' | grep true | wc -l) |
Yi Tseng | 0e78d9d | 2021-10-21 18:15:03 -0700 | [diff] [blame^] | 45 | echo "onos_telegraf,type=cluster active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES},ready=${ONOS_READY}" |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 46 | done |