@@ -18,6 +18,20 @@ type int64Gauge interface {
1818 Record (ctx context.Context , value int64 , options ... metric.RecordOption )
1919}
2020
21+ type float64Gauge interface {
22+ Set (float64 )
23+ }
24+
25+ // Option configures a [DiskMonitor].
26+ type Option func (* DiskMonitor )
27+
28+ // WithPrometheusGauge mirrors OTel gauge samples to a Prometheus gauge (e.g. node /metrics).
29+ func WithPrometheusGauge (g float64Gauge ) Option {
30+ return func (dm * DiskMonitor ) {
31+ dm .promGauge = g
32+ }
33+ }
34+
2135// totalRegularFileSizeBytes sums on-disk file sizes for every non-directory under dirPath (recursive), using filepath.WalkDir.
2236func totalRegularFileSizeBytes (dirPath string ) (int64 , error ) {
2337 var totalSize int64
@@ -44,10 +58,11 @@ type DiskMonitor struct {
4458 lggr logger.Logger
4559 sizeOfDir func () (int64 , error )
4660 gauge int64Gauge
61+ promGauge float64Gauge
4762}
4863
4964// NewDiskMonitor returns a [DiskMonitor] for dirPath using gaugeName at tickInterval.
50- func NewDiskMonitor (lggr logger.Logger , dirPath string , gaugeName string , tickInterval time.Duration ) (* DiskMonitor , error ) {
65+ func NewDiskMonitor (lggr logger.Logger , dirPath string , gaugeName string , tickInterval time.Duration , opts ... Option ) (* DiskMonitor , error ) {
5166 g , err := beholder .GetMeter ().Int64Gauge (gaugeName )
5267 if err != nil {
5368 return nil , fmt .Errorf ("int64 gauge %q: %w" , gaugeName , err )
@@ -70,6 +85,10 @@ func NewDiskMonitor(lggr logger.Logger, dirPath string, gaugeName string, tickIn
7085 "gaugeName" , gaugeName ,
7186 ))
7287 dm .lggr = dm .eng .SugaredLogger
88+
89+ for _ , opt := range opts {
90+ opt (dm )
91+ }
7392 return dm , nil
7493}
7594
@@ -88,4 +107,7 @@ func (dm *DiskMonitor) emitDirSizeMetric(ctx context.Context) {
88107
89108 dm .lggr .Debugw ("Emitting directory size metric" , "sizeBytes" , totalSize )
90109 dm .gauge .Record (ctx , totalSize )
110+ if dm .promGauge != nil {
111+ dm .promGauge .Set (float64 (totalSize ))
112+ }
91113}
0 commit comments