Ejemplo n.º 1
0
func serveStatus(worker *Worker, w http.ResponseWriter, r *http.Request) {
	statusReq := WorkerStatusRequest{}
	status := WorkerStatusResponse{}

	err := worker.Status(&statusReq, &status)
	if err != nil {
		// TODO - escaping.
		fmt.Fprintf(w, "<p>Status error: %v", err)
	}

	addr := fmt.Sprintf("%s:%d", cname, worker.listener.Addr().(*net.TCPAddr).Port)
	fmt.Fprintf(w, "<p>Worker %s (<a href=\"http://%s:%d\">status</a>)<p>Version %s<p>Jobs %d\n",
		addr, cname, worker.httpStatusPort, status.Version, status.MaxJobCount)
	fmt.Fprintf(w, "<p><a href=\"/log?host=%s\">Worker log %s</a>\n", addr, addr)

	if !status.Accepting {
		fmt.Fprintf(w, "<b>shutting down</b>")
	}
	stats.CpuStatsWriteHttp(w, status.CpuStats, status.DiskStats)

	fmt.Fprintf(w, "<p>Total CPU: %s", status.TotalCpu.Percent())

	m := status.MemStat
	fmt.Fprintf(w, "<p>HeapIdle: %v, HeapInUse: %v",
		m.HeapIdle, m.HeapInuse)

	stats.CountStatsWriteHttp(w, status.PhaseNames, status.PhaseCounts)

	for _, mirrorStatus := range status.MirrorStatus {
		mirrorStatusHtml(w, mirrorStatus)
	}
}
Ejemplo n.º 2
0
func (me *Coordinator) workerHandler(w http.ResponseWriter, req *http.Request) {
	addr, conn, err := me.getHost(req)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintf(w, "<html><head><title>Termite worker status</title></head>")
		fmt.Fprintf(w, "<body>Error: %s</body></html>", err.Error())
		return
	}

	statusReq := WorkerStatusRequest{}
	status := WorkerStatusResponse{}

	client := rpc.NewClient(conn)
	err = client.Call("Worker.Status", &statusReq, &status)
	client.Close()
	if err != nil {
		fmt.Fprintf(w, "<p><tt>RPC error: %v<tt>\n", err)
		return
	}

	fmt.Fprintf(w, "<p>Worker %s<p>Version %s<p>Jobs %d\n",
		addr, status.Version, status.MaxJobCount)
	fmt.Fprintf(w, "<p><a href=\"/log?host=%s\">Worker log %s</a>\n", addr, addr)

	if !status.Accepting {
		fmt.Fprintf(w, "<b>shutting down</b>")
	}
	stats.CpuStatsWriteHttp(w, status.CpuStats, status.DiskStats)

	fmt.Fprintf(w, "<p>Total CPU: %s", status.TotalCpu.Percent())
	fmt.Fprintf(w, "<p>Content cache hit rate: %.0f %%, Age %d",
		100.0*status.ContentCacheHitRate,
		status.ContentCacheHitAge)

	m := status.MemStat
	fmt.Fprintf(w, "<p>HeapIdle: %v, HeapInUse: %v",
		m.HeapIdle, m.HeapInuse)

	stats.CountStatsWriteHttp(w, status.PhaseNames, status.PhaseCounts)

	for _, mirrorStatus := range status.MirrorStatus {
		me.mirrorStatusHtml(w, mirrorStatus)
	}
	fmt.Fprintf(w, "<p><a href=\"/workerkill?host=%s\">Kill worker %s</a>\n", addr, addr)
	fmt.Fprintf(w, "<p><a href=\"/restart?host=%s\">Restart worker %s</a>\n", addr, addr)
	conn.Close()
}