You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
6.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
6 years ago
5 years ago
5 years ago
10 years ago
10 years ago
10 years ago
  1. package master_ui
  2. import (
  3. "fmt"
  4. "html/template"
  5. "strconv"
  6. "strings"
  7. )
  8. func bytesToHumanReadble(b uint64) string {
  9. const unit = 1024
  10. if b < unit {
  11. return fmt.Sprintf("%d B", b)
  12. }
  13. div, exp := uint64(unit), 0
  14. for n := b / unit; n >= unit; n /= unit {
  15. div *= unit
  16. exp++
  17. }
  18. return fmt.Sprintf("%.2f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
  19. }
  20. func percentFrom(total uint64, part_of uint64) string {
  21. return fmt.Sprintf("%.2f", (float64(part_of)/float64(total))*100)
  22. }
  23. func join(data []int64) string {
  24. var ret []string
  25. for _, d := range data {
  26. ret = append(ret, strconv.Itoa(int(d)))
  27. }
  28. return strings.Join(ret, ",")
  29. }
  30. var funcMap = template.FuncMap{
  31. "join": join,
  32. "bytesToHumanReadble": bytesToHumanReadble,
  33. "percentFrom": percentFrom,
  34. }
  35. var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOCTYPE html>
  36. <html>
  37. <head>
  38. <title>SeaweedFS {{ .Version }}</title>
  39. <link rel="stylesheet" href="/seaweedfsstatic/bootstrap/3.3.1/css/bootstrap.min.css">
  40. <script type="text/javascript" src="/seaweedfsstatic/javascript/jquery-2.1.3.min.js"></script>
  41. <script type="text/javascript" src="/seaweedfsstatic/javascript/jquery-sparklines/2.1.2/jquery.sparkline.min.js"></script>
  42. <script type="text/javascript">
  43. $(function() {
  44. var periods = ['second', 'minute', 'hour', 'day'];
  45. for (i = 0; i < periods.length; i++) {
  46. var period = periods[i];
  47. $('.inlinesparkline-'+period).sparkline('html', {
  48. type: 'line',
  49. barColor: 'red',
  50. tooltipSuffix:' request per '+period,
  51. });
  52. }
  53. });
  54. </script>
  55. <style>
  56. #jqstooltip{
  57. height: 28px !important;
  58. width: 150px !important;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="container">
  64. <div class="page-header">
  65. <h1>
  66. <a href="https://github.com/chrislusf/seaweedfs"><img src="/seaweedfsstatic/seaweed50x50.png"></img></a>
  67. SeaweedFS <small>{{ .Version }}</small>
  68. </h1>
  69. </div>
  70. <div class="row">
  71. <div class="col-sm-6">
  72. <h2>Disk Stats</h2>
  73. <table class="table table-striped">
  74. <thead>
  75. <tr>
  76. <th>Path</th>
  77. <th>Total</th>
  78. <th>Free</th>
  79. <th>Usage</th>
  80. </tr>
  81. </thead>
  82. <tbody>
  83. {{ range .DiskStatuses }}
  84. <tr>
  85. <td>{{ .Dir }}</td>
  86. <td>{{ bytesToHumanReadble .All }}</td>
  87. <td>{{ bytesToHumanReadble .Free }}</td>
  88. <td>{{ percentFrom .All .Used}}%</td>
  89. </tr>
  90. {{ end }}
  91. </tbody>
  92. </table>
  93. </div>
  94. <div class="col-sm-6">
  95. <h2>System Stats</h2>
  96. <table class="table table-condensed table-striped">
  97. <tr>
  98. <th>Masters</th>
  99. <td>{{.Masters}}</td>
  100. </tr>
  101. <tr>
  102. <th>Weekly # ReadRequests</th>
  103. <td><span class="inlinesparkline-day">{{ .Counters.ReadRequests.WeekCounter.ToList | join }}</span></td>
  104. </tr>
  105. <tr>
  106. <th>Daily # ReadRequests</th>
  107. <td><span class="inlinesparkline-hour">{{ .Counters.ReadRequests.DayCounter.ToList | join }}</span></td>
  108. </tr>
  109. <tr>
  110. <th>Hourly # ReadRequests</th>
  111. <td><span class="inlinesparkline-minute">{{ .Counters.ReadRequests.HourCounter.ToList | join }}</span></td>
  112. </tr>
  113. <tr>
  114. <th>Last Minute # ReadRequests</th>
  115. <td><span class="inlinesparkline-second">{{ .Counters.ReadRequests.MinuteCounter.ToList | join }}</span></td>
  116. </tr>
  117. {{ range $key, $val := .Stats }}
  118. <tr>
  119. <th>{{ $key }}</th>
  120. <td>{{ $val }}</td>
  121. </tr>
  122. {{ end }}
  123. </table>
  124. </div>
  125. </div>
  126. <div class="row">
  127. <h2>Volumes</h2>
  128. <table class="table table-striped">
  129. <thead>
  130. <tr>
  131. <th>Id</th>
  132. <th>Collection</th>
  133. <th>Data Size</th>
  134. <th>Files</th>
  135. <th>Trash</th>
  136. <th>TTL</th>
  137. <th>ReadOnly</th>
  138. </tr>
  139. </thead>
  140. <tbody>
  141. {{ range .Volumes }}
  142. <tr>
  143. <td><code>{{ .Id }}</code></td>
  144. <td>{{ .Collection }}</td>
  145. <td>{{ bytesToHumanReadble .Size }}</td>
  146. <td>{{ .FileCount }}</td>
  147. <td>{{ .DeleteCount }} / {{bytesToHumanReadble .DeletedByteCount}}</td>
  148. <td>{{ .Ttl }}</td>
  149. <td>{{ .ReadOnly }}</td>
  150. </tr>
  151. {{ end }}
  152. </tbody>
  153. </table>
  154. </div>
  155. <div class="row">
  156. <h2>Remote Volumes</h2>
  157. <table class="table table-striped">
  158. <thead>
  159. <tr>
  160. <th>Id</th>
  161. <th>Collection</th>
  162. <th>Size</th>
  163. <th>Files</th>
  164. <th>Trash</th>
  165. <th>Remote</th>
  166. <th>Key</th>
  167. </tr>
  168. </thead>
  169. <tbody>
  170. {{ range .RemoteVolumes }}
  171. <tr>
  172. <td><code>{{ .Id }}</code></td>
  173. <td>{{ .Collection }}</td>
  174. <td>{{ bytesToHumanReadble .Size }}</td>
  175. <td>{{ .FileCount }}</td>
  176. <td>{{ .DeleteCount }} / {{bytesToHumanReadble .DeletedByteCount}}</td>
  177. <td>{{ .RemoteStorageName }}</td>
  178. <td>{{ .RemoteStorageKey }}</td>
  179. </tr>
  180. {{ end }}
  181. </tbody>
  182. </table>
  183. </div>
  184. <div class="row">
  185. <h2>Erasure Coding Shards</h2>
  186. <table class="table table-striped">
  187. <thead>
  188. <tr>
  189. <th>Id</th>
  190. <th>Collection</th>
  191. <th>Shard Size</th>
  192. <th>Shards</th>
  193. <th>CreatedAt</th>
  194. </tr>
  195. </thead>
  196. <tbody>
  197. {{ range .EcVolumes }}
  198. <tr>
  199. <td><code>{{ .VolumeId }}</code></td>
  200. <td>{{ .Collection }}</td>
  201. <td>{{ bytesToHumanReadble .ShardSize }}</td>
  202. <td>{{ .ShardIdList }}</td>
  203. <td>{{ .CreatedAt.Format "02 Jan 06 15:04 -0700" }}</td>
  204. </tr>
  205. {{ end }}
  206. </tbody>
  207. </table>
  208. </div>
  209. </div>
  210. </body>
  211. </html>
  212. `))