-
Notifications
You must be signed in to change notification settings - Fork 394
/
stats.go
99 lines (87 loc) · 4.35 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package repairer
import (
"fmt"
"sync"
"github.com/spacemonkeygo/monkit/v3"
"storj.io/common/storj"
)
// statsCollector holds a *stats for each redundancy scheme
// seen by the repairer. These are chained into the monkit scope for
// monitoring as they are initialized.
type statsCollector struct {
lock sync.Mutex
stats map[string]*stats
}
func newStatsCollector() *statsCollector {
return &statsCollector{
stats: make(map[string]*stats),
}
}
func (collector *statsCollector) getStatsByRS(rs string) *stats {
collector.lock.Lock()
defer collector.lock.Unlock()
stats, ok := collector.stats[rs]
if !ok {
stats = newStats(rs)
mon.Chain(stats)
collector.stats[rs] = stats
}
return stats
}
// stats is used for collecting and reporting repairer metrics.
//
// add any new metrics tagged with rs_scheme to this struct and set them
// in newStats.
type stats struct {
repairAttempts *monkit.Meter
repairSegmentSize *monkit.IntVal
repairerSegmentsBelowMinReq *monkit.Counter
repairerNodesUnavailable *monkit.Meter
repairUnnecessary *monkit.Meter
healthyRatioBeforeRepair *monkit.FloatVal
repairTooManyNodesFailed *monkit.Meter
repairFailed *monkit.Meter
repairPartial *monkit.Meter
repairSuccess *monkit.Meter
healthyRatioAfterRepair *monkit.FloatVal
segmentTimeUntilRepair *monkit.IntVal
segmentRepairCount *monkit.IntVal
}
func newStats(rs string) *stats {
return &stats{
repairAttempts: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_attempts").WithTag("rs_scheme", rs)),
repairSegmentSize: monkit.NewIntVal(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_segment_size").WithTag("rs_scheme", rs)),
repairerSegmentsBelowMinReq: monkit.NewCounter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repairer_segments_below_min_req").WithTag("rs_scheme", rs)),
repairerNodesUnavailable: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repairer_nodes_unavailable").WithTag("rs_scheme", rs)),
repairUnnecessary: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_unnecessary").WithTag("rs_scheme", rs)),
healthyRatioBeforeRepair: monkit.NewFloatVal(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "healthy_ratio_before_repair").WithTag("rs_scheme", rs)),
repairTooManyNodesFailed: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_too_many_nodes_failed").WithTag("rs_scheme", rs)),
repairFailed: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_failed").WithTag("rs_scheme", rs)),
repairPartial: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_partial").WithTag("rs_scheme", rs)),
repairSuccess: monkit.NewMeter(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "repair_success").WithTag("rs_scheme", rs)),
healthyRatioAfterRepair: monkit.NewFloatVal(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "healthy_ratio_after_repair").WithTag("rs_scheme", rs)),
segmentTimeUntilRepair: monkit.NewIntVal(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "segment_time_until_repair").WithTag("rs_scheme", rs)),
segmentRepairCount: monkit.NewIntVal(monkit.NewSeriesKey("tagged_repair_stats").WithTag("name", "segment_repair_count").WithTag("rs_scheme", rs)),
}
}
// Stats implements the monkit.StatSource interface.
func (stats *stats) Stats(cb func(key monkit.SeriesKey, field string, val float64)) {
stats.repairAttempts.Stats(cb)
stats.repairSegmentSize.Stats(cb)
stats.repairerSegmentsBelowMinReq.Stats(cb)
stats.repairerNodesUnavailable.Stats(cb)
stats.repairUnnecessary.Stats(cb)
stats.healthyRatioBeforeRepair.Stats(cb)
stats.repairTooManyNodesFailed.Stats(cb)
stats.repairFailed.Stats(cb)
stats.repairPartial.Stats(cb)
stats.repairSuccess.Stats(cb)
stats.healthyRatioAfterRepair.Stats(cb)
stats.segmentTimeUntilRepair.Stats(cb)
stats.segmentRepairCount.Stats(cb)
}
func getRSString(rs storj.RedundancyScheme) string {
return fmt.Sprintf("%d/%d/%d/%d", rs.RequiredShares, rs.RepairShares, rs.OptimalShares, rs.TotalShares)
}