SEBA-267 Add ONU Performance Metrics to Kafka Exporter

Change-Id: I18902935a4654c3a241284093b8a456a226f707f
diff --git a/Dockerfile b/Dockerfile
index ef68715..29e46da 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -15,15 +15,15 @@
 # docker build -t opencord/kafka-topic-exporter:latest .
 # docker build -t 10.90.0.101:30500/opencord/kafka-topic-exporter:latest .
 
-FROM golang:latest as builder
-RUN mkdir /app 
-ADD . /app/ 
-WORKDIR /app 
+FROM golang:1.10-stretch as builder
+RUN mkdir /app
+ADD . /app/
+WORKDIR /app
 RUN go get github.com/prometheus/client_golang/prometheus
 RUN go get github.com/Shopify/sarama
-RUN CGO_ENABLED=0 GOOS=linux go build -o main . 
+RUN CGO_ENABLED=0 GOOS=linux go build -o main .
 
-FROM alpine:latest  
+FROM alpine:3.8
 WORKDIR /app/
 COPY --from=builder /app/main .
 ENTRYPOINT ["./main"]
\ No newline at end of file
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..9084fa2
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+1.1.0
diff --git a/prometheus.go b/prometheus.go
index 15ce599..a1bc327 100644
--- a/prometheus.go
+++ b/prometheus.go
@@ -14,7 +14,9 @@
 
 package main
 
-import "github.com/prometheus/client_golang/prometheus"
+import (
+       "github.com/prometheus/client_golang/prometheus"
+)
 
 var (
 	txBytesTotal = prometheus.NewGaugeVec(
@@ -66,72 +68,128 @@
 func export(kpi KPI) {
 
 	for _, data := range kpi.SliceDatas {
-		txBytesTotal.WithLabelValues(
-			data.Metadata.LogicalDeviceID,
-			data.Metadata.SerialNumber,
-			data.Metadata.DeviceID,
-			data.Metadata.Context.InterfaceID,
-			data.Metadata.Context.PonID,
-			data.Metadata.Context.PortNumber,
-			data.Metadata.Title,
-		).Set(data.Metrics.TxBytes)
+	        switch title := data.Metadata.Title; title {
+                        case "Ethernet", "PON":
+                                txBytesTotal.WithLabelValues(
+                                        data.Metadata.LogicalDeviceID,
+                                        data.Metadata.SerialNumber,
+                                        data.Metadata.DeviceID,
+                                        data.Metadata.Context.InterfaceID,
+                                        data.Metadata.Context.PonID,
+                                        data.Metadata.Context.PortNumber,
+                                        data.Metadata.Title,
+                                ).Set(data.Metrics.TxBytes)
 
-		rxBytesTotal.WithLabelValues(
-			data.Metadata.LogicalDeviceID,
-			data.Metadata.SerialNumber,
-			data.Metadata.DeviceID,
-			data.Metadata.Context.InterfaceID,
-			data.Metadata.Context.PonID,
-			data.Metadata.Context.PortNumber,
-			data.Metadata.Title,
-		).Set(data.Metrics.RxBytes)
+                                rxBytesTotal.WithLabelValues(
+                                        data.Metadata.LogicalDeviceID,
+                                        data.Metadata.SerialNumber,
+                                        data.Metadata.DeviceID,
+                                        data.Metadata.Context.InterfaceID,
+                                        data.Metadata.Context.PonID,
+                                        data.Metadata.Context.PortNumber,
+                                        data.Metadata.Title,
+                                ).Set(data.Metrics.RxBytes)
 
-		txPacketsTotal.WithLabelValues(
-			data.Metadata.LogicalDeviceID,
-			data.Metadata.SerialNumber,
-			data.Metadata.DeviceID,
-			data.Metadata.Context.InterfaceID,
-			data.Metadata.Context.PonID,
-			data.Metadata.Context.PortNumber,
-			data.Metadata.Title,
-		).Set(data.Metrics.TxPackets)
+                                txPacketsTotal.WithLabelValues(
+                                        data.Metadata.LogicalDeviceID,
+                                        data.Metadata.SerialNumber,
+                                        data.Metadata.DeviceID,
+                                        data.Metadata.Context.InterfaceID,
+                                        data.Metadata.Context.PonID,
+                                        data.Metadata.Context.PortNumber,
+                                        data.Metadata.Title,
+                                ).Set(data.Metrics.TxPackets)
 
-		rxPacketsTotal.WithLabelValues(
-			data.Metadata.LogicalDeviceID,
-			data.Metadata.SerialNumber,
-			data.Metadata.DeviceID,
-			data.Metadata.Context.InterfaceID,
-			data.Metadata.Context.PonID,
-			data.Metadata.Context.PortNumber,
-			data.Metadata.Title,
-		).Set(data.Metrics.RxPackets)
+                                rxPacketsTotal.WithLabelValues(
+                                        data.Metadata.LogicalDeviceID,
+                                        data.Metadata.SerialNumber,
+                                        data.Metadata.DeviceID,
+                                        data.Metadata.Context.InterfaceID,
+                                        data.Metadata.Context.PonID,
+                                        data.Metadata.Context.PortNumber,
+                                        data.Metadata.Title,
+                                ).Set(data.Metrics.RxPackets)
 
-		txErrorPacketsTotal.WithLabelValues(
-			data.Metadata.LogicalDeviceID,
-			data.Metadata.SerialNumber,
-			data.Metadata.DeviceID,
-			data.Metadata.Context.InterfaceID,
-			data.Metadata.Context.PonID,
-			data.Metadata.Context.PortNumber,
-			data.Metadata.Title,
-		).Set(data.Metrics.TxErrorPackets)
+                                txErrorPacketsTotal.WithLabelValues(
+                                        data.Metadata.LogicalDeviceID,
+                                        data.Metadata.SerialNumber,
+                                        data.Metadata.DeviceID,
+                                        data.Metadata.Context.InterfaceID,
+                                        data.Metadata.Context.PonID,
+                                        data.Metadata.Context.PortNumber,
+                                        data.Metadata.Title,
+                                ).Set(data.Metrics.TxErrorPackets)
 
-		rxErrorPacketsTotal.WithLabelValues(
-			data.Metadata.LogicalDeviceID,
-			data.Metadata.SerialNumber,
-			data.Metadata.DeviceID,
-			data.Metadata.Context.InterfaceID,
-			data.Metadata.Context.PonID,
-			data.Metadata.Context.PortNumber,
-			data.Metadata.Title,
-		).Set(data.Metrics.RxErrorPackets)
+                                rxErrorPacketsTotal.WithLabelValues(
+                                        data.Metadata.LogicalDeviceID,
+                                        data.Metadata.SerialNumber,
+                                        data.Metadata.DeviceID,
+                                        data.Metadata.Context.InterfaceID,
+                                        data.Metadata.Context.PonID,
+                                        data.Metadata.Context.PortNumber,
+                                        data.Metadata.Title,
+                                ).Set(data.Metrics.RxErrorPackets)
 
-		// TODO add metrics for:
-		// TxBcastPackets
-		// TxUnicastPackets
-		// TxMulticastPackets
-		// RxBcastPackets
-		// RxMulticastPackets
+                                // TODO add metrics for:
+                                // TxBcastPackets
+                                // TxUnicastPackets
+                                // TxMulticastPackets
+                                // RxBcastPackets
+                                // RxMulticastPackets
 
+                        case "Ethernet_Bridge_Port_History":
+                                if data.Metadata.Context.Upstream == "True" {
+                                        // ONU. Extended Ethernet statistics.
+                                        txPacketsTotal.WithLabelValues(
+                                                data.Metadata.LogicalDeviceID,
+                                                data.Metadata.SerialNumber,
+                                                data.Metadata.DeviceID,
+                                                "NA", // InterfaceID
+                                                "NA", // PonID
+                                                "NA", // PortNumber
+                                                data.Metadata.Title,
+                                        ).Add(data.Metrics.Packets)
+
+                                        txBytesTotal.WithLabelValues(
+                                                data.Metadata.LogicalDeviceID,
+                                                data.Metadata.SerialNumber,
+                                                data.Metadata.DeviceID,
+                                                "NA", // InterfaceID
+                                                "NA", // PonID
+                                                "NA", // PortNumber
+                                                data.Metadata.Title,
+                                        ).Add(data.Metrics.Octets)
+                                } else {
+                                         // ONU. Extended Ethernet statistics.
+                                        rxPacketsTotal.WithLabelValues(
+                                                data.Metadata.LogicalDeviceID,
+                                                data.Metadata.SerialNumber,
+                                                data.Metadata.DeviceID,
+                                                "NA", // InterfaceID
+                                                "NA", // PonID
+                                                "NA", // PortNumber
+                                                data.Metadata.Title,
+                                        ).Add(data.Metrics.Packets)
+
+                                        rxBytesTotal.WithLabelValues(
+                                                data.Metadata.LogicalDeviceID,
+                                                data.Metadata.SerialNumber,
+                                                data.Metadata.DeviceID,
+                                                "NA", // InterfaceID
+                                                "NA", // PonID
+                                                "NA", // PortNumber
+                                                data.Metadata.Title,
+                                        ).Add(data.Metrics.Octets)
+                                }
+
+                        case "Ethernet_UNI_History":
+                                // ONU. Do nothing.
+
+                        case "FEC_History":
+                                // ONU. Do Nothing.
+
+                        case "voltha.internal":
+                                // Voltha Internal. Do nothing.
+                }
 	}
 }
diff --git a/types.go b/types.go
index 25ed429..1e29fbe 100644
--- a/types.go
+++ b/types.go
@@ -28,12 +28,21 @@
 	RxErrorPackets     float64 `json:"rx_error_packets"`
 	RxBcastPackets     float64 `json:"rx_bcast_packets"`
 	RxMulticastPackets float64 `json:"rx_mcast_packets"`
+
+	// ONU Ethernet_Bridge_Port_history
+	Packets            float64 `json:"packets"`
+	Octets             float64 `json:"octets"`
 }
 
 type Context struct {
 	InterfaceID string `json:"intf_id"`
 	PonID       string `json:"pon_id"`
 	PortNumber  string `json:"port_no"`
+
+	// ONU Performance Metrics
+	ParentClassId string `json:"parent_class_id"`
+	ParentEntityId string `json:"parent_entity_id"`
+	Upstream    string `json:"upstream"`
 }
 
 type Metadata struct {