airtime + no panic on lost of influxdb connection
This commit is contained in:
		
							parent
							
								
									5011719fdf
								
							
						
					
					
						commit
						93fe0fadb5
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -23,5 +23,5 @@ _testmain.go
 | 
			
		||||
*.test
 | 
			
		||||
*.prof
 | 
			
		||||
respond-collector
 | 
			
		||||
webroot/
 | 
			
		||||
webroot
 | 
			
		||||
config.yml
 | 
			
		||||
 | 
			
		||||
@ -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"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										25
									
								
								stats_db.go
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user