From 93fe0fadb53c5ca1b1afa42a7a45c31e436dde9f Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Mon, 4 Jul 2016 14:39:48 +0200 Subject: [PATCH] airtime + no panic on lost of influxdb connection --- .gitignore | 2 +- data/breminale.go | 14 ++++++++++++++ data/statistics.go | 3 ++- stats_db.go | 25 +++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 3133390..94fec82 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,5 @@ _testmain.go *.test *.prof respond-collector -webroot/ +webroot config.yml diff --git a/data/breminale.go b/data/breminale.go index d45e62f..f1da47d 100644 --- a/data/breminale.go +++ b/data/breminale.go @@ -9,3 +9,17 @@ type Wireless struct { type SwitchPort struct { Speed uint32 `json:"speed"` } + +type WirelessStatistics struct { + Airtime24 *WirelessAirtime `json:"airtime24,omitempty"` + Airtime5 *WirelessAirtime `json:"airtime5,omitempty"` +} + +type WirelessAirtime struct { + Active uint64 `json:"active"` + Busy uint64 `json:"busy"` + Rx uint64 `json:"rx"` + Tx uint64 `json:"tx"` + Noise uint32 `json:"noise"` + Frequency uint32 `json:"frequency"` +} diff --git a/data/statistics.go b/data/statistics.go index b7cd57c..45c04c8 100644 --- a/data/statistics.go +++ b/data/statistics.go @@ -26,7 +26,8 @@ type Statistics struct { MgmtTx *Traffic `json:"mgmt_tx"` MgmtRx *Traffic `json:"mgmt_rx"` } `json:"traffic,omitempty"` - Switch map[string]*SwitchPort `json:"switch,omitempty"` + Switch map[string]*SwitchPort `json:"switch,omitempty"` + Wireless *WirelessStatistics `json:"wireless,omitempty"` } type MeshVPNPeerLink struct { diff --git a/stats_db.go b/stats_db.go index fee5372..5c4fcf0 100644 --- a/stats_db.go +++ b/stats_db.go @@ -2,6 +2,7 @@ package main import ( "log" + "strconv" "sync" "time" @@ -83,6 +84,26 @@ func (c *StatsDb) Add(stats *data.Statistics) { fields["traffic.mgmt_tx.bytes"] = int64(t.Bytes) fields["traffic.mgmt_tx.packets"] = t.Packets } + if w := stats.Wireless; w != nil { + if time := w.Airtime24; time != nil { + fields["airtime24.active"] = time.Active + fields["airtime24.busy"] = time.Busy + fields["airtime24.tx"] = time.Tx + fields["airtime24.rx"] = time.Rx + fields["airtime24.noise"] = time.Noise + fields["airtime24.frequency"] = time.Frequency + tags["frequency24"] = strconv.Itoa(int(time.Frequency)) + } + if time := w.Airtime5; time != nil { + fields["airtime5.active"] = time.Active + fields["airtime5.busy"] = time.Busy + fields["airtime5.tx"] = time.Tx + fields["airtime5.rx"] = time.Rx + fields["airtime5.noise"] = time.Noise + fields["airtime5.frequency"] = time.Frequency + tags["frequency5"] = strconv.Itoa(int(time.Frequency)) + } + } point, err := client.NewPoint("node", tags, fields, time.Now()) if err != nil { @@ -119,7 +140,7 @@ func (c *StatsDb) worker() { // create new batch timer.Reset(batchDuration) if bp, err = client.NewBatchPoints(bpConfig); err != nil { - panic(err) + log.Fatal(err) } } bp.AddPoint(point) @@ -139,7 +160,7 @@ func (c *StatsDb) worker() { log.Println("saving", len(bp.Points()), "points") if err = c.client.Write(bp); err != nil { - panic(err) + log.Fatal(err) } writeNow = false bp = nil