3
3
package watch
4
4
5
5
import (
6
+ "expvar"
6
7
"fmt"
7
8
"os"
8
9
"path/filepath"
@@ -34,6 +35,10 @@ type naiveNotify struct {
34
35
notifyList map [string ]bool
35
36
}
36
37
38
+ var (
39
+ numberOfWatches = expvar .NewInt ("watch.naive.numberOfWatches" )
40
+ )
41
+
37
42
func (d * naiveNotify ) Add (name string ) error {
38
43
fi , err := os .Stat (name )
39
44
if err != nil && ! os .IsNotExist (err ) {
@@ -52,7 +57,7 @@ func (d *naiveNotify) Add(name string) error {
52
57
return errors .Wrapf (err , "notify.Add(%q)" , name )
53
58
}
54
59
} else {
55
- err = d .watcher . Add (filepath .Dir (name ))
60
+ err = d .add (filepath .Dir (name ))
56
61
if err != nil {
57
62
return errors .Wrapf (err , "notify.Add(%q)" , filepath .Dir (name ))
58
63
}
@@ -74,7 +79,7 @@ func (d *naiveNotify) watchRecursively(dir string) error {
74
79
if ! mode .IsDir () {
75
80
return nil
76
81
}
77
- err = d .watcher . Add (path )
82
+ err = d .add (path )
78
83
if err != nil {
79
84
if os .IsNotExist (err ) {
80
85
return nil
@@ -100,7 +105,7 @@ func (d *naiveNotify) watchAncestorOfMissingPath(path string) error {
100
105
return d .watchAncestorOfMissingPath (parent )
101
106
}
102
107
103
- return d .watcher . Add (path )
108
+ return d .add (path )
104
109
}
105
110
106
111
func (d * naiveNotify ) Close () error {
@@ -151,7 +156,7 @@ func (d *naiveNotify) loop() {
151
156
}
152
157
}
153
158
if shouldWatch {
154
- err := d .watcher . Add (path )
159
+ err := d .add (path )
155
160
if err != nil && ! os .IsNotExist (err ) {
156
161
d .log .Infof ("Error watching path %s: %s" , e .Name , err )
157
162
}
@@ -179,6 +184,15 @@ func (d *naiveNotify) shouldNotify(path string) bool {
179
184
return false
180
185
}
181
186
187
+ func (d * naiveNotify ) add (path string ) error {
188
+ err := d .watcher .Add (path )
189
+ if err != nil {
190
+ return err
191
+ }
192
+ numberOfWatches .Add (1 )
193
+ return nil
194
+ }
195
+
182
196
func NewWatcher (l logger.Logger ) (* naiveNotify , error ) {
183
197
fsw , err := fsnotify .NewWatcher ()
184
198
if err != nil {
0 commit comments