Allow multiple points per device.
This commit is contained in:
		
							parent
							
								
									f752a5076a
								
							
						
					
					
						commit
						f638cdab10
					
				|  | @ -3,3 +3,5 @@ | ||||||
| /*.1.gz | /*.1.gz | ||||||
| /*.1 | /*.1 | ||||||
| /vendor | /vendor | ||||||
|  | .DS_Store | ||||||
|  | *~ | ||||||
|  |  | ||||||
|  | @ -102,10 +102,10 @@ func (c *Config) PollUnifiController(infdb influx.Client, unifi *unidev.AuthedRe | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		for _, asset := range append(clients, devices...) { | 		for _, asset := range append(clients, devices...) { | ||||||
| 			if pt, errr := asset.Point(); errr != nil { | 			if pt, errr := asset.Points(); errr != nil { | ||||||
| 				log.Println("asset.Point():", errr) | 				log.Println("asset.Points():", errr) | ||||||
| 			} else { | 			} else { | ||||||
| 				bp.AddPoint(pt) | 				bp.AddPoints(pt) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,8 +7,8 @@ import ( | ||||||
| 	influx "github.com/influxdata/influxdb/client/v2" | 	influx "github.com/influxdata/influxdb/client/v2" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Point generates a client's datapoint for InfluxDB.
 | // Points generates a client's datapoints for InfluxDB.
 | ||||||
| func (u UCL) Point() (*influx.Point, error) { | func (u UCL) Points() (points []*influx.Point, err error) { | ||||||
| 	if u.Name == "" && u.Hostname != "" { | 	if u.Name == "" && u.Hostname != "" { | ||||||
| 		u.Name = u.Hostname | 		u.Name = u.Hostname | ||||||
| 	} else if u.Hostname == "" && u.Name != "" { | 	} else if u.Hostname == "" && u.Name != "" { | ||||||
|  | @ -95,6 +95,6 @@ func (u UCL) Point() (*influx.Point, error) { | ||||||
| 		"wired-tx_bytes-r":       u.WiredTxBytesR, | 		"wired-tx_bytes-r":       u.WiredTxBytesR, | ||||||
| 		"wired-tx_packets":       u.WiredTxPackets, | 		"wired-tx_packets":       u.WiredTxPackets, | ||||||
| 	} | 	} | ||||||
| 
 | 	points[0], err = influx.NewPoint("clients", tags, fields, time.Now()) | ||||||
| 	return influx.NewPoint("clients", tags, fields, time.Now()) | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,8 +7,8 @@ import ( | ||||||
| 	influx "github.com/influxdata/influxdb/client/v2" | 	influx "github.com/influxdata/influxdb/client/v2" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Point generates a device's datapoint for InfluxDB.
 | // Points generates a device's datapoints for InfluxDB.
 | ||||||
| func (u UAP) Point() (*influx.Point, error) { | func (u UAP) Points() (points []*influx.Point, err error) { | ||||||
| 	tags := map[string]string{ | 	tags := map[string]string{ | ||||||
| 		"id":                      u.ID, | 		"id":                      u.ID, | ||||||
| 		"mac":                     u.Mac, | 		"mac":                     u.Mac, | ||||||
|  | @ -165,5 +165,6 @@ func (u UAP) Point() (*influx.Point, error) { | ||||||
| 		"stat_wifi1-tx_packets":      u.Stat.Wifi1TxPackets, | 		"stat_wifi1-tx_packets":      u.Stat.Wifi1TxPackets, | ||||||
| 		"stat_wifi1-tx_retries":      u.Stat.Wifi1TxRetries, | 		"stat_wifi1-tx_retries":      u.Stat.Wifi1TxRetries, | ||||||
| 	} | 	} | ||||||
| 	return influx.NewPoint("uap", tags, fields, time.Now()) | 	points[0], err = influx.NewPoint("uap", tags, fields, time.Now()) | ||||||
|  | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ const LoginPath = "/api/login" | ||||||
| // Asset provides a common interface to retreive metrics from a device or client.
 | // Asset provides a common interface to retreive metrics from a device or client.
 | ||||||
| type Asset interface { | type Asset interface { | ||||||
| 	// Point() means this is useful to influxdb..
 | 	// Point() means this is useful to influxdb..
 | ||||||
| 	Point() (*influx.Point, error) | 	Points() ([]*influx.Point, error) | ||||||
| 	// Add more methods to achieve more usefulness from this library.
 | 	// Add more methods to achieve more usefulness from this library.
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,8 +7,8 @@ import ( | ||||||
| 	influx "github.com/influxdata/influxdb/client/v2" | 	influx "github.com/influxdata/influxdb/client/v2" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Point generates a device's datapoint for InfluxDB.
 | // Points generates a device's datapoints for InfluxDB.
 | ||||||
| func (u USG) Point() (*influx.Point, error) { | func (u USG) Points() (points []*influx.Point, err error) { | ||||||
| 	tags := map[string]string{ | 	tags := map[string]string{ | ||||||
| 		"id":                      u.ID, | 		"id":                      u.ID, | ||||||
| 		"mac":                     u.Mac, | 		"mac":                     u.Mac, | ||||||
|  | @ -117,5 +117,6 @@ func (u USG) Point() (*influx.Point, error) { | ||||||
| 		"wan-tx_bytes":      u.Stat.WanTxBytes, | 		"wan-tx_bytes":      u.Stat.WanTxBytes, | ||||||
| 		"wan-tx_packets":    u.Stat.WanTxPackets, | 		"wan-tx_packets":    u.Stat.WanTxPackets, | ||||||
| 	} | 	} | ||||||
| 	return influx.NewPoint("usg", tags, fields, time.Now()) | 	points[0], err = influx.NewPoint("usg", tags, fields, time.Now()) | ||||||
|  | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,8 +7,8 @@ import ( | ||||||
| 	influx "github.com/influxdata/influxdb/client/v2" | 	influx "github.com/influxdata/influxdb/client/v2" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Point generates a device's datapoint for InfluxDB.
 | // Points generates a device's datapoints for InfluxDB.
 | ||||||
| func (u USW) Point() (*influx.Point, error) { | func (u USW) Points() (points []*influx.Point, err error) { | ||||||
| 	tags := map[string]string{ | 	tags := map[string]string{ | ||||||
| 		"id":                     u.ID, | 		"id":                     u.ID, | ||||||
| 		"mac":                    u.Mac, | 		"mac":                    u.Mac, | ||||||
|  | @ -109,5 +109,6 @@ func (u USW) Point() (*influx.Point, error) { | ||||||
| 		"stat_tx_retries":          u.Stat.TxRetries, | 		"stat_tx_retries":          u.Stat.TxRetries, | ||||||
| 		// Add the port stats too.
 | 		// Add the port stats too.
 | ||||||
| 	} | 	} | ||||||
| 	return influx.NewPoint("usw", tags, fields, time.Now()) | 	points[0], err = influx.NewPoint("usw", tags, fields, time.Now()) | ||||||
|  | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue