-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.go
69 lines (49 loc) · 1.2 KB
/
status.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
package main
import (
"bytes"
"fmt"
"net/http"
"time"
)
func statusPage(w http.ResponseWriter, r *http.Request) {
writeHttp(w, fmt.Sprintf("version: %s\n\n", version))
t := time.Now().Round(time.Second).Sub(timeStart)
writeHttp(w, fmt.Sprintf("uptime: %s\n", t))
connNum := len(sessionChan)
writeHttp(w, fmt.Sprintf("websocket connections: %d\n\n", connNum))
writeHttp(w, fmt.Sprintf("data traffic out: %s\n", NumberToString(transOut, ',')))
writeHttp(w, "\nfile list:\n")
for file, fid := range fileMap {
writeHttp(w, fmt.Sprintf("%5d. %s\n", fid, file))
sMap := sessionMap[fid]
for sid, _ := range *sMap {
writeHttp(w, fmt.Sprintf("\t\t%d\n", sid))
}
}
if connNum < 1 {
return
}
writeHttp(w, "\nsession list:\n")
for sid, _ := range sessionChan {
writeHttp(w, fmt.Sprintf("\t%d\n", sid))
}
}
func NumberToString(n uint64, sep rune) string {
s := fmt.Sprintf(`%d`, n)
startOffset := 0
var buff bytes.Buffer
l := len(s)
commaIndex := 3 - ((l - startOffset) % 3)
if commaIndex == 3 {
commaIndex = 0
}
for i := startOffset; i < l; i++ {
if commaIndex == 3 {
buff.WriteRune(sep)
commaIndex = 0
}
commaIndex++
buff.WriteByte(s[i])
}
return buff.String()
}