-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset reporter for gauges in tally (#3)
* fix: closer * fix: create new reporter with each tick
- Loading branch information
Showing
4 changed files
with
67 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
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,49 @@ | ||
package provider | ||
|
||
import ( | ||
"log/slog" | ||
"time" | ||
|
||
"github.com/tigrisdata/fly-exporter/reporter" | ||
) | ||
|
||
type MetricProvider struct { | ||
interval time.Duration | ||
reporter *reporter.Reporter | ||
} | ||
|
||
func NewMetricProvider() MetricProvider { | ||
mp := MetricProvider{ | ||
interval: 10 * time.Second, | ||
reporter: reporter.NewReporter(), | ||
} | ||
return mp | ||
} | ||
|
||
func (mp *MetricProvider) Collect() { | ||
ticker := time.NewTicker(mp.interval) | ||
|
||
if err := mp.reporter.CollectOnce(); err != nil { | ||
slog.Error("failed to collect metrics", "error", err) | ||
} | ||
|
||
for range ticker.C { | ||
reporter := reporter.NewReporter() | ||
if err := reporter.CollectOnce(); err != nil { | ||
slog.Error("failed to collect metric data:", "error", err) | ||
} | ||
time.Sleep(1 * time.Second) | ||
oldReporter := mp.reporter | ||
mp.reporter = reporter | ||
oldReporter.Close() | ||
} | ||
defer ticker.Stop() | ||
} | ||
|
||
func (mp *MetricProvider) ServeHttp() { | ||
mp.reporter.ServeHttp() | ||
} | ||
|
||
func (mp *MetricProvider) Close() { | ||
mp.reporter.Close() | ||
} |
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