Skip to content

Commit

Permalink
fix top lists: reset host counters in each export cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
cha87de committed Sep 6, 2018
1 parent ed068e1 commit 7e75f2b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tophost/exporter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tophost

import (
"fmt"
"time"

"omi-gitlab.e-technik.uni-ulm.de/bwnetflow/kafka/consumer_dashboard/prometheus"
Expand All @@ -12,13 +11,13 @@ type Exporter struct {
promExporter prometheus.Exporter
hostlistBytes topHosts
hostlistConnections topHosts
maxHosts int
}

// Initialize the top host exporter
func (exporter *Exporter) Initialize(promExporter prometheus.Exporter, maxHosts int, exportInterval time.Duration) {
exporter.promExporter = promExporter
exporter.hostlistBytes = make(topHosts, maxHosts)
exporter.hostlistConnections = make(topHosts, maxHosts)
exporter.maxHosts = maxHosts
ticker := time.NewTicker(exportInterval)
quit := make(chan struct{})
go func() {
Expand Down Expand Up @@ -46,6 +45,10 @@ func (exporter *Exporter) Consider(ipSrc string, ipDst string, bytes uint64) {

// runs one export cycle of current snapshot
func (exporter *Exporter) exportTraffic() {
// create empty top host list
exporter.hostlistBytes = make(topHosts, exporter.maxHosts)

// walk through rawHost list
length := 0
rawHostsBytes.Range(func(key, value interface{}) bool {
length++
Expand All @@ -55,9 +58,11 @@ func (exporter *Exporter) exportTraffic() {
currentValue := value.(uint64)
exporter.hostlistBytes.addHost(currentIP, currentValue)

// remove from rawHosts list
rawHostsBytes.Delete(currentIP)

return true
})
fmt.Printf("byHostBytes length: %d\n", length)

// push hostlist to promExporter
for _, host := range exporter.hostlistBytes {
Expand All @@ -67,6 +72,10 @@ func (exporter *Exporter) exportTraffic() {

// runs one export cycle of current snapshot
func (exporter *Exporter) exportConnections() {
// create empty top host list
exporter.hostlistConnections = make(topHosts, exporter.maxHosts)

// walk through rawHost list
length := 0
rawHostsConnections.Range(func(key, value interface{}) bool {
length++
Expand All @@ -76,9 +85,11 @@ func (exporter *Exporter) exportConnections() {
currentValue := value.(uint64)
exporter.hostlistConnections.addHost(currentIP, currentValue)

// remove from rawHosts list
rawHostsConnections.Delete(currentIP)

return true
})
fmt.Printf("byHostConnections length: %d\n", length)

// push hostlist to promExporter
for _, host := range exporter.hostlistConnections {
Expand Down

0 comments on commit 7e75f2b

Please sign in to comment.