@@ -8,8 +8,11 @@ import (
8
8
"bytes"
9
9
"fmt"
10
10
"html/template"
11
+ "io"
11
12
"net/http"
13
+ "os"
12
14
"os/exec"
15
+ "runtime"
13
16
"sort"
14
17
"strings"
15
18
"time"
@@ -27,11 +30,13 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
27
30
28
31
statusMu .Lock ()
29
32
data := statusData {
30
- Total : len (status ),
31
- Uptime : round (time .Now ().Sub (processStartTime )),
32
- Recent : append ([]* buildStatus {}, statusDone ... ),
33
- DiskFree : df ,
34
- Version : Version ,
33
+ Total : len (status ),
34
+ Uptime : round (time .Now ().Sub (processStartTime )),
35
+ Recent : append ([]* buildStatus {}, statusDone ... ),
36
+ DiskFree : df ,
37
+ Version : Version ,
38
+ NumFD : fdCount (),
39
+ NumGoroutine : runtime .NumGoroutine (),
35
40
}
36
41
for _ , st := range status {
37
42
data .Active = append (data .Active , st )
@@ -85,14 +90,35 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
85
90
buf .WriteTo (w )
86
91
}
87
92
93
+ func fdCount () int {
94
+ f , err := os .Open ("/proc/self/fd" )
95
+ if err != nil {
96
+ return - 1
97
+ }
98
+ defer f .Close ()
99
+ n := 0
100
+ for {
101
+ names , err := f .Readdirnames (1000 )
102
+ n += len (names )
103
+ if err == io .EOF {
104
+ return n
105
+ }
106
+ if err != nil {
107
+ return - 1
108
+ }
109
+ }
110
+ }
111
+
88
112
func diskFree () string {
89
113
out , _ := exec .Command ("df" , "-h" ).Output ()
90
114
return string (out )
91
115
}
92
116
93
117
// statusData is the data that fills out statusTmpl.
94
118
type statusData struct {
95
- Total int
119
+ Total int // number of total builds active
120
+ NumFD int
121
+ NumGoroutine int
96
122
Uptime time.Duration
97
123
Active []* buildStatus
98
124
Recent []* buildStatus
@@ -157,6 +183,12 @@ var statusTmpl = template.Must(template.New("status").Parse(`
157
183
<h2 id=disk><a href='#disk'>🔗</a> Disk Space</h2>
158
184
<pre>{{.DiskFree}}</pre>
159
185
186
+ <h2 id=disk><a href='#fd'>🔗</a> File Descriptors</h2>
187
+ <p>{{.NumFD}}</p>
188
+
189
+ <h2 id=disk><a href='#goroutines'>🔗</a> Goroutines</h2>
190
+ <p>{{.NumGoroutine}} <a href='/debug/goroutines'>goroutines</a></p>
191
+
160
192
</body>
161
193
</html>
162
194
` ))
0 commit comments