[Aether-1482] - Add the new helm chart to install the telegraf external daemon of ONOS controller

- Use the servicemonitor to work with Prometheus instead of Rancher's annotation

Change-Id: Icabfb43b1dbf5f86bfdbd4117cf550770d3418a7
diff --git a/apps/tost-telegraf/.helmignore b/apps/tost-telegraf/.helmignore
new file mode 100644
index 0000000..c687fff
--- /dev/null
+++ b/apps/tost-telegraf/.helmignore
@@ -0,0 +1,26 @@
+# Copyright 2021-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/apps/tost-telegraf/Chart.yaml b/apps/tost-telegraf/Chart.yaml
new file mode 100644
index 0000000..4569bec
--- /dev/null
+++ b/apps/tost-telegraf/Chart.yaml
@@ -0,0 +1,31 @@
+# Copyright 2021-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+apiVersion: v2
+name: tost-telegraf
+description: Telegraf plugin for TOST stack
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+# Versions are expected to follow Semantic Versioning (https://semver.org/)
+version: 0.1.0
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application. Versions are not expected to
+# follow Semantic Versioning. They should reflect the version the application is using.
+appVersion: 0.1.0
+
+dependencies:
+  - name: telegraf
+    version: 1.7.38
+    repository: https://influxdata.github.io/helm-charts
diff --git a/apps/tost-telegraf/templates/configmap-config.yaml b/apps/tost-telegraf/templates/configmap-config.yaml
new file mode 100644
index 0000000..13c1548
--- /dev/null
+++ b/apps/tost-telegraf/templates/configmap-config.yaml
@@ -0,0 +1,31 @@
+{{/*
+# Copyright 2021-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: "tost-telegraf-config-script"
+  labels:
+    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
+    release: "{{ .Release.Name }}"
+    app: tost-telegraf
+data:
+  tost_telegraf.sh: |
+    #!/bin/sh
+    set -x
+
+    while IFS= read -r LINE; do
+        ACTIVE_LINKS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \
+        http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/links | json_pp | grep "\"state\" : \"ACTIVE\"" | wc -l)
+
+        ENABLE_DEVICE_PORTS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \
+        http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/devices/ports | json_pp | grep "\"isEnabled\" : true" | wc -l)
+
+        DEVICES=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \
+        http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/devices | json_pp | grep "\"type\" : \"SWITCH\"" | wc -l)
+
+        echo "onos_telegraf active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES}"
+    done
diff --git a/apps/tost-telegraf/templates/servicemonitor.yaml b/apps/tost-telegraf/templates/servicemonitor.yaml
new file mode 100644
index 0000000..5959341
--- /dev/null
+++ b/apps/tost-telegraf/templates/servicemonitor.yaml
@@ -0,0 +1,18 @@
+{{/*
+# Copyright 2021-present Open Networking Foundation
+
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+*/}}
+
+apiVersion: monitoring.coreos.com/v1
+kind: ServiceMonitor
+metadata:
+  name: tost-telegraf
+spec:
+  selector:
+    matchLabels:
+      app.kubernetes.io/name: telegraf
+  endpoints:
+  - port: prometheus-client
+    path: /metrics
+    scheme: HTTP
diff --git a/apps/tost-telegraf/values.yaml b/apps/tost-telegraf/values.yaml
new file mode 100644
index 0000000..1ac2abe
--- /dev/null
+++ b/apps/tost-telegraf/values.yaml
@@ -0,0 +1,40 @@
+# Copyright 2021-present Open Networking Foundation
+# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
+
+telegraf:
+  image:
+    tag: "1.17"
+  volumes:
+    - name: "telegraf-external-daemon"
+      configMap:
+        name: tost-telegraf-config-script
+        defaultMode: 0755
+  mountPoints:
+    - name: "telegraf-external-daemon"
+      mountPath: /tmp/onos_telegraf.sh
+      subPath: tost_telegraf.sh
+  config:
+    inputs:
+      - execd:
+          command: ["/tmp/onos_telegraf.sh"]
+          signal: "STDIN"
+      - cisco_telemetry_gnmi:
+          addresses:
+            - 10.128.100.34:9339
+          redial: 10s
+      - cisco_telemetry_gnmi.subscription:
+          name: stratum_counters
+          origin: openconfig-interfaces
+          path: /interfaces/interface[name=*]/state/counters
+          sample_interval: 5000ns
+          subscription_mode: sample
+
+    outputs:
+      - prometheus_client:
+          metric_version: 2
+          listen: ":9273"
+onos:
+  username: onos
+  password: rocks
+  server: localhost
+  port: 8181