mirror of https://github.com/perkeep/perkeep.git
pkg/server/status: link to GCL logs on GCE
Fixes issue #592 Change-Id: Ife405816ee42902258c93eac917a6ff5bada4138
This commit is contained in:
parent
64a8d7d26b
commit
8a10bb52e0
|
@ -237,8 +237,8 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque
|
|||
f("<h2>Logs</h2><ul>")
|
||||
f(" <li><a href='/debug/config'>/debug/config</a> - server config</li>\n")
|
||||
if env.OnGCE() {
|
||||
f(" <li><a href='/debug/logs'>/debug/logs</a> - server logs</li>\n")
|
||||
f(" <li><a href='/debug/logs?TODO'>/debug/logs?XXX</a> - camlistored logs</li>\n")
|
||||
f(" <li><a href='/debug/logs/camlistored'>camlistored logs on Google Cloud Logging</a></li>\n")
|
||||
f(" <li><a href='/debug/logs/system'>system logs from Google Compute Engine</a></li>\n")
|
||||
}
|
||||
f("</ul>")
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ import (
|
|||
"camlistore.org/pkg/server"
|
||||
"camlistore.org/pkg/server/app"
|
||||
"camlistore.org/pkg/types/serverconfig"
|
||||
|
||||
"google.golang.org/cloud/compute/metadata"
|
||||
)
|
||||
|
||||
const camliPrefix = "/camli/"
|
||||
|
@ -597,7 +599,7 @@ func (config *Config) InstallHandlers(hi HandlerInstaller, baseURL string, reind
|
|||
hi.Handle("/debug/pprof/", profileHandler{})
|
||||
}
|
||||
hi.Handle("/debug/config", auth.RequireAuth(configHandler{config}, auth.OpAll))
|
||||
hi.Handle("/debug/logs", auth.RequireAuth(http.HandlerFunc(logsHandler), auth.OpAll))
|
||||
hi.Handle("/debug/logs/", auth.RequireAuth(http.HandlerFunc(logsHandler), auth.OpAll))
|
||||
return multiCloser(hl.closers), nil
|
||||
}
|
||||
|
||||
|
@ -697,18 +699,33 @@ func (profileHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
func logsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
c := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Dial: func(network, addr string) (net.Conn, error) {
|
||||
return net.Dial("unix", "/run/camjournald.sock")
|
||||
suffix := strings.TrimPrefix(r.URL.Path, "/debug/logs/")
|
||||
switch suffix {
|
||||
case "camlistored":
|
||||
projID, err := metadata.ProjectID()
|
||||
if err != nil {
|
||||
httputil.ServeError(w, r, fmt.Errorf("Error getting project ID: %v", err))
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r,
|
||||
"https://console.developers.google.com/logs?project="+projID+"&service=custom.googleapis.com&logName=camlistored-stderr",
|
||||
http.StatusFound)
|
||||
case "system":
|
||||
c := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Dial: func(network, addr string) (net.Conn, error) {
|
||||
return net.Dial("unix", "/run/camjournald.sock")
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := c.Get("http://journal/entries")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
io.Copy(w, res.Body)
|
||||
default:
|
||||
http.Error(w, "no such logs", 404)
|
||||
}
|
||||
res, err := c.Get("http://journal/entries")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
io.Copy(w, res.Body)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue