-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from davidnewhall/dn2_prometheus
Add prometheus exporter.
- Loading branch information
Showing
42 changed files
with
2,019 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# influx | ||
|
||
This package provides the methods to turn UniFi measurements into influx | ||
data-points with appropriate tags and fields. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package unifipoller | ||
package influxunifi | ||
|
||
import ( | ||
"time" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package unifipoller | ||
package influxunifi | ||
|
||
import ( | ||
influx "github.com/influxdata/influxdb1-client/v2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Package influx provides the methods to turn UniFi measurements into influx | ||
// data-points with appropriate tags and fields. | ||
package influxunifi | ||
|
||
import ( | ||
"github.com/davidnewhall/unifi-poller/metrics" | ||
client "github.com/influxdata/influxdb1-client/v2" | ||
) | ||
|
||
// Metrics contains all the data from the controller and an influx endpoint to send it to. | ||
type Metrics struct { | ||
*metrics.Metrics | ||
client.BatchPoints | ||
} | ||
|
||
// ProcessPoints batches all device and client data into influxdb data points. | ||
// Call this after you've collected all the data you care about. | ||
// This function is sorta weird and returns a slice of errors. The reasoning is | ||
// that some points may process while others fail, so we attempt to process them | ||
// all. This is (usually) run in a loop, so we can't really exit on error, | ||
// we just log the errors and tally them on a counter. In reality, this never | ||
// returns any errors because we control the data going in; cool right? But we | ||
// still check&log it in case the data going is skewed up and causes errors! | ||
func (m *Metrics) ProcessPoints() []error { | ||
errs := []error{} | ||
processPoints := func(m *Metrics, p []*client.Point, err error) { | ||
switch { | ||
case err != nil: | ||
errs = append(errs, err) | ||
case p == nil: | ||
default: | ||
m.AddPoints(p) | ||
} | ||
} | ||
|
||
for _, asset := range m.Sites { | ||
pts, err := SitePoints(asset, m.TS) | ||
processPoints(m, pts, err) | ||
} | ||
for _, asset := range m.Clients { | ||
pts, err := ClientPoints(asset, m.TS) | ||
processPoints(m, pts, err) | ||
} | ||
for _, asset := range m.IDSList { | ||
pts, err := IDSPoints(asset) // no m.TS. | ||
processPoints(m, pts, err) | ||
} | ||
|
||
if m.Devices == nil { | ||
return errs | ||
} | ||
for _, asset := range m.Devices.UAPs { | ||
pts, err := UAPPoints(asset, m.TS) | ||
processPoints(m, pts, err) | ||
} | ||
for _, asset := range m.Devices.USGs { | ||
pts, err := USGPoints(asset, m.TS) | ||
processPoints(m, pts, err) | ||
} | ||
for _, asset := range m.Devices.USWs { | ||
pts, err := USWPoints(asset, m.TS) | ||
processPoints(m, pts, err) | ||
} | ||
for _, asset := range m.Devices.UDMs { | ||
pts, err := UDMPoints(asset, m.TS) | ||
processPoints(m, pts, err) | ||
} | ||
return errs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package unifipoller | ||
package influxunifi | ||
|
||
import ( | ||
"strings" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package unifipoller | ||
package influxunifi | ||
|
||
import ( | ||
"time" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package unifipoller | ||
package influxunifi | ||
|
||
import ( | ||
"time" | ||
|
Oops, something went wrong.