Skip to content

Commit 4a5c74f

Browse files
committed
Add metric __src_disk_cache_size
1 parent bd865c8 commit 4a5c74f

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

cmd/statshouse/statshouse.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,18 @@ var argv struct {
9292
}
9393

9494
type mainAgent struct {
95-
agent *agent.Agent
96-
worker *worker
97-
mirrorUdpConn net.Conn
98-
receiverHTTP *receiver.HTTP
99-
receiverTCP *receiver.TCP
100-
receiversUDP []*receiver.UDP
101-
hijackHTTP *rpc.HijackListener
102-
hijackTCP *rpc.HijackListener
103-
receiversWG sync.WaitGroup
104-
logPackets func(format string, args ...interface{})
105-
hardwareMetrics *stats.CollectorManager
95+
agent *agent.Agent
96+
worker *worker
97+
mirrorUdpConn net.Conn
98+
receiverHTTP *receiver.HTTP
99+
receiverTCP *receiver.TCP
100+
receiversUDP []*receiver.UDP
101+
hijackHTTP *rpc.HijackListener
102+
hijackTCP *rpc.HijackListener
103+
receiversWG sync.WaitGroup
104+
logPackets func(format string, args ...interface{})
105+
hardwareMetrics *stats.CollectorManager
106+
mappingsCachePath string
106107
}
107108

108109
var (
@@ -165,7 +166,8 @@ func run() int {
165166
if argv.cacheDir != "" { // we support working without touching disk (on readonly filesystems, in stateless containers, etc)
166167
var err error
167168
// we do not want to confuse mappings from different clusters, this would be a disaster
168-
fpmc, err = os.OpenFile(filepath.Join(argv.cacheDir, fmt.Sprintf("mappings-%s.cache", argv.Cluster)), os.O_CREATE|os.O_RDWR, 0666)
169+
main.mappingsCachePath = filepath.Join(argv.cacheDir, fmt.Sprintf("mappings-%s.cache", argv.Cluster))
170+
fpmc, err = os.OpenFile(main.mappingsCachePath, os.O_CREATE|os.O_RDWR, 0666)
169171
if err != nil {
170172
logErr.Printf("failed to open agent mappings cache: %v", err)
171173
return 1
@@ -492,9 +494,13 @@ func (main *mainAgent) beforeFlushBucket(a *agent.Agent, unixNow uint32) {
492494
a.AddValueCounter(unixNow, format.BuiltinMetricMetaAgentUDPReceiveBufferSize,
493495
[]int32{}, v, 1)
494496
}
495-
// TODO: mappings cache size
496-
//a.AddValueCounter(unixNow, format.BuiltinMetricMetaAgentDiskCacheSize,
497-
// []int32{0, 0, 0, 0, a.ComponentTag()}, float64(s), 1)
497+
if main.mappingsCachePath != "" {
498+
fi, err := os.Stat(main.mappingsCachePath)
499+
if err == nil && fi != nil {
500+
a.AddValueCounter(unixNow, format.BuiltinMetricMetaAgentDiskCacheSize,
501+
[]int32{0, 0, 0, 0, a.ComponentTag()}, float64(fi.Size()), 1)
502+
}
503+
}
498504
}
499505

500506
func (main *mainAgent) startHardwareMetricsCollector() {

0 commit comments

Comments
 (0)