This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- merges random subprojects into this repo - move config handling into it's own module - remove most placeholders - interface based aggregators (easier to add more) - interface based and context aware scheduling, needs more work - update deps - go 1.21
- Loading branch information
1 parent
d758d42
commit 367c888
Showing
43 changed files
with
2,706 additions
and
1,973 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[default.extend-words] | ||
templeos = "templeos" | ||
WRONLY = "WRONLY" | ||
|
||
[files] | ||
extend-exclude = ["scripts"] |
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,50 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/influxdata/influxdb-client-go/v2/api" | ||
) | ||
|
||
// Aggregator is an interface for aggregating a metric `T` | ||
type Aggregator[T any] interface { | ||
// Initialize the aggregator with a starting value from influxdb | ||
Init(reader api.QueryAPI) (lastUpdated time.Time, err error) | ||
|
||
// Aggregate adds metric T into the aggregator | ||
Aggregate(entry T) | ||
|
||
// Send the aggregated statistics to influxdb | ||
Send(writer api.WriteAPI) | ||
} | ||
|
||
// StartAggregator starts the aggregator with the given Aggregator implementation, channel of type T, influxdb QueryAPI and WriteAPI. | ||
// It returns the lastUpdated time and an error if any occurred during initialization. | ||
func StartAggregator[T any](aggregator Aggregator[T], c <-chan T, reader api.QueryAPI, writer api.WriteAPI) (lastUpdated time.Time, err error) { | ||
lastUpdated, err = aggregator.Init(reader) | ||
if err != nil { | ||
return lastUpdated, err | ||
} | ||
|
||
go func() { | ||
ticker := time.NewTicker(time.Minute) | ||
|
||
for { | ||
select { | ||
case <-ticker.C: | ||
aggregator.Send(writer) | ||
case entry := <-c: | ||
aggregator.Aggregate(entry) | ||
} | ||
} | ||
}() | ||
|
||
return lastUpdated, nil | ||
} | ||
|
||
// NetStat is a commonly used struct for aggregating network statistics | ||
type NetStat struct { | ||
BytesSent int64 | ||
BytesRecv int64 | ||
Requests int64 | ||
} |
Oops, something went wrong.