Lock metrics on mutation
This commit is contained in:
parent
1df4c96963
commit
992e819f38
@ -1,6 +1,7 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/owncast/owncast/config"
|
"github.com/owncast/owncast/config"
|
||||||
@ -20,6 +21,8 @@ const (
|
|||||||
|
|
||||||
// CollectedMetrics stores different collected + timestamped values.
|
// CollectedMetrics stores different collected + timestamped values.
|
||||||
type CollectedMetrics struct {
|
type CollectedMetrics struct {
|
||||||
|
m sync.Mutex `json:"-"`
|
||||||
|
|
||||||
CPUUtilizations []TimestampedValue `json:"cpu"`
|
CPUUtilizations []TimestampedValue `json:"cpu"`
|
||||||
RAMUtilizations []TimestampedValue `json:"memory"`
|
RAMUtilizations []TimestampedValue `json:"memory"`
|
||||||
DiskUtilizations []TimestampedValue `json:"disk"`
|
DiskUtilizations []TimestampedValue `json:"disk"`
|
||||||
@ -65,6 +68,9 @@ func Start(getStatus func() models.Status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlePolling() {
|
func handlePolling() {
|
||||||
|
metrics.m.Lock()
|
||||||
|
defer metrics.m.Unlock()
|
||||||
|
|
||||||
// Collect hardware stats
|
// Collect hardware stats
|
||||||
collectCPUUtilization()
|
collectCPUUtilization()
|
||||||
collectRAMUtilization()
|
collectRAMUtilization()
|
||||||
|
@ -18,28 +18,38 @@ var (
|
|||||||
|
|
||||||
// RegisterPlaybackErrorCount will add to the windowed playback error count.
|
// RegisterPlaybackErrorCount will add to the windowed playback error count.
|
||||||
func RegisterPlaybackErrorCount(count float64) {
|
func RegisterPlaybackErrorCount(count float64) {
|
||||||
|
metrics.m.Lock()
|
||||||
|
defer metrics.m.Unlock()
|
||||||
windowedErrorCounts = append(windowedErrorCounts, count)
|
windowedErrorCounts = append(windowedErrorCounts, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterQualityVariantChangesCount will add to the windowed quality variant
|
// RegisterQualityVariantChangesCount will add to the windowed quality variant
|
||||||
// change count.
|
// change count.
|
||||||
func RegisterQualityVariantChangesCount(count float64) {
|
func RegisterQualityVariantChangesCount(count float64) {
|
||||||
|
metrics.m.Lock()
|
||||||
|
defer metrics.m.Unlock()
|
||||||
windowedQualityVariantChanges = append(windowedQualityVariantChanges, count)
|
windowedQualityVariantChanges = append(windowedQualityVariantChanges, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterPlayerBandwidth will add to the windowed playback bandwidth.
|
// RegisterPlayerBandwidth will add to the windowed playback bandwidth.
|
||||||
func RegisterPlayerBandwidth(kbps float64) {
|
func RegisterPlayerBandwidth(kbps float64) {
|
||||||
|
metrics.m.Lock()
|
||||||
|
defer metrics.m.Unlock()
|
||||||
windowedBandwidths = append(windowedBandwidths, kbps)
|
windowedBandwidths = append(windowedBandwidths, kbps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterPlayerLatency will add to the windowed player latency values.
|
// RegisterPlayerLatency will add to the windowed player latency values.
|
||||||
func RegisterPlayerLatency(seconds float64) {
|
func RegisterPlayerLatency(seconds float64) {
|
||||||
|
metrics.m.Lock()
|
||||||
|
defer metrics.m.Unlock()
|
||||||
windowedLatencies = append(windowedLatencies, seconds)
|
windowedLatencies = append(windowedLatencies, seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterPlayerSegmentDownloadDuration will add to the windowed player segment
|
// RegisterPlayerSegmentDownloadDuration will add to the windowed player segment
|
||||||
// download duration values.
|
// download duration values.
|
||||||
func RegisterPlayerSegmentDownloadDuration(seconds float64) {
|
func RegisterPlayerSegmentDownloadDuration(seconds float64) {
|
||||||
|
metrics.m.Lock()
|
||||||
|
defer metrics.m.Unlock()
|
||||||
windowedDownloadDurations = append(windowedDownloadDurations, seconds)
|
windowedDownloadDurations = append(windowedDownloadDurations, seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user