MCPcopy
hub / github.com/perkeep/perkeep / serveStatusHTML

Method serveStatusHTML

pkg/server/status.go:230–298  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

228var quotedPrefix = regexp.MustCompile(`[;"]/(\S+?/)[&"]`)
229
230func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Request) {
231 st := sh.currentStatus()
232 f := func(p string, a ...interface{}) {
233 if len(a) == 0 {
234 io.WriteString(rw, p)
235 } else {
236 fmt.Fprintf(rw, p, a...)
237 }
238 }
239 f("<html><head><title>perkeepd status</title></head>")
240 f("<body>")
241
242 f("<h1>perkeepd status</h1>")
243
244 f("<h2>Versions</h2><ul>")
245 var envStr string
246 if env.OnGCE() {
247 envStr = " (on GCE)"
248 }
249 f("<li><b>Perkeep</b>: %s%s</li>", html.EscapeString(buildinfo.Summary()), envStr)
250 f("<li><b>Go</b>: %s/%s %s, cgo=%v</li>", runtime.GOOS, runtime.GOARCH, runtime.Version(), cgoEnabled)
251 f("<li><b>djpeg</b>: %s", html.EscapeString(buildinfo.DjpegStatus()))
252 f("</ul>")
253
254 f("<h2>Logs</h2><ul>")
255 f(" <li><a href='/debug/config'>/debug/config</a> - server config</li>\n")
256 if env.OnGCE() {
257 f(" <li><a href='/debug/logs/perkeepd'>perkeepd logs on Google Cloud Logging</a></li>\n")
258 f(" <li><a href='/debug/logs/system'>system logs from Google Compute Engine</a></li>\n")
259 }
260 f("</ul>")
261
262 f("<h2>Admin</h2>")
263 f("<ul>")
264 f(" <li><form method='post' action='restart' onsubmit='return confirm(\"Really restart now?\")'><button>restart server</button> ")
265 f("<input type='checkbox' name='reindex' id='reindex'><label for='reindex'> reindex </label>")
266 f("<select name='recovery'><option selected='true' disabled='disabled'>select recovery mode</option>")
267 f("<option value='0'>no recovery</option>")
268 f("<option value='1'>fast recovery</option>")
269 f("<option value='2'>full recovery</option>")
270 f("</select>")
271 f("</form></li>")
272 if env.OnGCE() {
273 console, err := sh.googleCloudConsole()
274 if err != nil {
275 log.Printf("error getting Google Cloud Console URL: %v", err)
276 } else {
277 f(" <li><b>Updating:</b> When a new image for Perkeep on GCE is available, you can update by hitting \"Reset\" (or \"Stop\", then \"Start\") for your instance on your <a href='%s'>Google Cloud Console</a>.<br>Alternatively, you can ssh to your instance and restart the Perkeep service with: <b>sudo systemctl restart perkeepd</b>.</li>", console)
278 }
279 }
280 f("</ul>")
281
282 f("<h2>Handlers</h2>")
283 f("<p>As JSON: <a href='status.json'>status.json</a>; and the <a href='%s?camli.mode=config'>discovery JSON</a>.</p>", st.rootPrefix)
284 f("<p>Not yet pretty HTML UI:</p>")
285 js, err := json.MarshalIndent(st, "", " ")
286 if err != nil {
287 log.Printf("JSON marshal error: %v", err)

Callers 1

ServeHTTPMethod · 0.95

Calls 8

currentStatusMethod · 0.95
googleCloudConsoleMethod · 0.95
OnGCEFunction · 0.92
SummaryFunction · 0.92
DjpegStatusFunction · 0.92
PrintfMethod · 0.80
isHandlerMethod · 0.80
fFunction · 0.50

Tested by

no test coverage detected