OutBytes uint64
// Prometheus metrics
- PromErrors prometheus.Counter
- PromInBytes prometheus.Counter
- PromOutBytes prometheus.Counter
- PromErrorCodes *prometheus.CounterVec
+ errors prometheus.Counter
+ inBytes prometheus.Counter
+ outBytes prometheus.Counter
+ errCounters *prometheus.CounterVec
ErrorCodes map[string]uint64 `json:",omitempty"`
lock sync.Mutex
}
+func (s *statsTicker) setup(m *volumeMetrics) {
+ s.errors = m.Errors
+ s.errCounters = m.ErrorCodes
+ s.inBytes = m.InBytes
+ s.outBytes = m.OutBytes
+}
+
// Tick increments each of the given counters by 1 using
// atomic.AddUint64.
func (s *statsTicker) Tick(counters ...*uint64) {
if err == nil {
return
}
- s.PromErrors.Inc()
+ s.errors.Inc()
s.Tick(&s.Errors)
s.lock.Lock()
}
s.ErrorCodes[errType]++
s.lock.Unlock()
- s.PromErrorCodes.WithLabelValues(errType).Inc()
+ s.errCounters.WithLabelValues(errType).Inc()
}
// TickInBytes increments the incoming byte counter by n.
func (s *statsTicker) TickInBytes(n uint64) {
- s.PromInBytes.Add(float64(n))
+ s.inBytes.Add(float64(n))
atomic.AddUint64(&s.InBytes, n)
}
// TickOutBytes increments the outgoing byte counter by n.
func (s *statsTicker) TickOutBytes(n uint64) {
- s.PromOutBytes.Add(float64(n))
+ s.outBytes.Add(float64(n))
atomic.AddUint64(&s.OutBytes, n)
}
}
// String implements flag.Value
-func (s *unixVolumeAdder) String() string {
+func (vs *unixVolumeAdder) String() string {
return "-"
}
if err == nil {
// Set up prometheus metrics
v.metrics = m
- v.os.stats.PromErrors = v.metrics.Errors
- v.os.stats.PromErrorCodes = v.metrics.ErrorCodes
- v.os.stats.PromInBytes = v.metrics.InBytes
- v.os.stats.PromOutBytes = v.metrics.OutBytes
+ v.os.stats.statsTicker.setup(m)
// Periodically update free/used volume space
go func() {
for {
return putWithPipe(ctx, loc, block, v)
}
-// ReadBlock implements BlockWriter.
+// WriteBlock implements BlockWriter.
func (v *UnixVolume) WriteBlock(ctx context.Context, loc string, rdr io.Reader) error {
if v.ReadOnly {
return MethodDisabledError