blob: 2ddd5ea1a42965fce117e7657fbf3553d165c566 [file] [log] [blame]
// Copyright 2017 The Goma Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package rpc
import (
func init() {
http.HandleFunc("/debug/backends", func(w http.ResponseWriter, req *http.Request) {
// TODO: auth request as net/trace
w.Header().Set("Content-Type", "text/html; charset=utf=8")
Render(w, req)
// Render renders backend information.
// It is handled on /debug/backends on default http mux.
func Render(w http.ResponseWriter, req *http.Request) {
type backendInfo struct {
Addr string
Conn bool
NReq int64
NErr int64
Load int
Err error
type clientInfo struct {
Target string
Timestamp time.Time
Backends []backendInfo
data := struct {
Clients []clientInfo
for _, client := range clients {
ci := clientInfo{
Timestamp: client.timestamp,
var addrs []string
for addr := range client.backends {
addrs = append(addrs, addr)
for _, addr := range addrs {
b := client.backends[addr]
bi := backendInfo{
Addr: b.addr,
Conn: != nil,
NReq: b.nreq,
NErr: b.nerr,
Load: b.load,
Err: b.err,
ci.Backends = append(ci.Backends, bi)
data.Clients = append(data.Clients, ci)
err := pageTmpl.ExecuteTemplate(w, "Page", data)
if err != nil {
logger := log.FromContext(context.Background())
logger.Errorf("rpc: Failed executing template: %v", err)
var pageTmpl = template.Must(template.New("Page").Parse(pageHTML))
const pageHTML = `
{{template "Prolog" .}}
{{template "StatusTable" .}}
{{template "Epilog" .}}
{{define "Prolog"}}
{{define "StatusTable"}}
<table border="1">
<td># of reqs
<td># of err
{{range $c := .Clients}}
{{range $b := $c.Backends}}
<td colspan="2">
{{define "Epilog"}}