fix master ui

This commit is contained in:
Konstantin Lebedev 2022-04-07 19:37:40 +05:00
parent 35bc67f030
commit a2fdb3e277
4 changed files with 181 additions and 39 deletions

View file

@ -212,31 +212,38 @@ func (ms *MasterServer) proxyToLeader(f http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if ms.Topo.IsLeader() {
f(w, r)
} else if ms.Topo.RaftServer != nil && ms.Topo.RaftServer.Leader() != "" {
ms.boundedLeaderChan <- 1
defer func() { <-ms.boundedLeaderChan }()
targetUrl, err := url.Parse("http://" + ms.Topo.RaftServer.Leader())
if err != nil {
writeJsonError(w, r, http.StatusInternalServerError,
fmt.Errorf("Leader URL http://%s Parse Error: %v", ms.Topo.RaftServer.Leader(), err))
return
}
glog.V(4).Infoln("proxying to leader", ms.Topo.RaftServer.Leader())
proxy := httputil.NewSingleHostReverseProxy(targetUrl)
director := proxy.Director
proxy.Director = func(req *http.Request) {
actualHost, err := security.GetActualRemoteHost(req)
if err == nil {
req.Header.Set("HTTP_X_FORWARDED_FOR", actualHost)
}
director(req)
}
proxy.Transport = util.Transport
proxy.ServeHTTP(w, r)
} else {
// handle requests locally
f(w, r)
return
}
var raftServerLeader string
if ms.Topo.RaftServer != nil && ms.Topo.RaftServer.Leader() != "" {
raftServerLeader = ms.Topo.RaftServer.Leader()
} else if ms.Topo.HashicorpRaft != nil && ms.Topo.HashicorpRaft.Leader() != "" {
raftServerLeader = string(ms.Topo.HashicorpRaft.Leader())
}
if raftServerLeader == "" {
f(w, r)
return
}
ms.boundedLeaderChan <- 1
defer func() { <-ms.boundedLeaderChan }()
targetUrl, err := url.Parse("http://" + raftServerLeader)
if err != nil {
writeJsonError(w, r, http.StatusInternalServerError,
fmt.Errorf("Leader URL http://%s Parse Error: %v", raftServerLeader, err))
return
}
glog.V(4).Infoln("proxying to leader", raftServerLeader)
proxy := httputil.NewSingleHostReverseProxy(targetUrl)
director := proxy.Director
proxy.Director = func(req *http.Request) {
actualHost, err := security.GetActualRemoteHost(req)
if err == nil {
req.Header.Set("HTTP_X_FORWARDED_FOR", actualHost)
}
director(req)
}
proxy.Transport = util.Transport
proxy.ServeHTTP(w, r)
}
}

View file

@ -5,6 +5,8 @@ import (
"time"
"github.com/chrislusf/raft"
hashicorpRaft "github.com/hashicorp/raft"
ui "github.com/chrislusf/seaweedfs/weed/server/master_ui"
"github.com/chrislusf/seaweedfs/weed/stats"
"github.com/chrislusf/seaweedfs/weed/util"
@ -13,20 +15,39 @@ import (
func (ms *MasterServer) uiStatusHandler(w http.ResponseWriter, r *http.Request) {
infos := make(map[string]interface{})
infos["Up Time"] = time.Now().Sub(startTime).String()
args := struct {
Version string
Topology interface{}
RaftServer raft.Server
Stats map[string]interface{}
Counters *stats.ServerStats
VolumeSizeLimitMB uint32
}{
util.Version(),
ms.Topo.ToMap(),
ms.Topo.RaftServer,
infos,
serverStats,
ms.option.VolumeSizeLimitMB,
if ms.Topo.RaftServer != nil {
args := struct {
Version string
Topology interface{}
RaftServer raft.Server
Stats map[string]interface{}
Counters *stats.ServerStats
VolumeSizeLimitMB uint32
}{
util.Version(),
ms.Topo.ToMap(),
ms.Topo.RaftServer,
infos,
serverStats,
ms.option.VolumeSizeLimitMB,
}
ui.StatusTpl.Execute(w, args)
} else if ms.Topo.HashicorpRaft != nil {
args := struct {
Version string
Topology interface{}
RaftServer *hashicorpRaft.Raft
Stats map[string]interface{}
Counters *stats.ServerStats
VolumeSizeLimitMB uint32
}{
util.Version(),
ms.Topo.ToMap(),
ms.Topo.HashicorpRaft,
infos,
serverStats,
ms.option.VolumeSizeLimitMB,
}
ui.StatusNewRaftTpl.Execute(w, args)
}
ui.StatusTpl.Execute(w, args)
}

View file

@ -0,0 +1,110 @@
<!DOCTYPE html>
<html>
<head>
<title>SeaweedFS {{ .Version }}</title>
<link rel="stylesheet" href="/seaweedfsstatic/bootstrap/3.3.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>
<a href="https://github.com/chrislusf/seaweedfs"><img src="/seaweedfsstatic/seaweed50x50.png"></img></a>
SeaweedFS <small>{{ .Version }}</small>
</h1>
</div>
<div class="row">
<div class="col-sm-6">
<h2>Cluster status</h2>
<table class="table table-condensed table-striped">
<tbody>
<tr>
<th>Volume Size Limit</th>
<td>{{ .VolumeSizeLimitMB }}MB</td>
</tr>
<tr>
<th>Free</th>
<td>{{ .Topology.Free }}</td>
</tr>
<tr>
<th>Max</th>
<td>{{ .Topology.Max }}</td>
</tr>
{{ with .RaftServer }}
<tr>
<th>Leader</th>
<td><a href="http://{{ .Leader }}">{{ .Leader }}</a></td>
</tr>
<tr>
<th>Other Masters</th>
<td class="col-sm-5">
<ul class="list-unstyled">
{{ range $k, $p := .GetConfiguration.Configuration.Servers }}
<li><a href="http://{{ $p.ID }}/ui/index.html">{{ $p.ID }}</a></li>
{{ end }}
</ul>
</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
<div class="col-sm-6">
<h2>System Stats</h2>
<table class="table table-condensed table-striped">
<tr>
<th>Concurrent Connections</th>
<td>{{ .Counters.Connections.WeekCounter.Sum }}</td>
</tr>
{{ range $key, $val := .Stats }}
<tr>
<th>{{ $key }}</th>
<td>{{ $val }}</td>
</tr>
{{ end }}
</table>
</div>
</div>
<div class="row">
<h2>Topology</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Data Center</th>
<th>Rack</th>
<th>RemoteAddr</th>
<th>#Volumes</th>
<th>Volume Ids</th>
<th>#ErasureCodingShards</th>
<th>Max</th>
</tr>
</thead>
<tbody>
{{ range $dc_index, $dc := .Topology.DataCenters }}
{{ range $rack_index, $rack := $dc.Racks }}
{{ range $dn_index, $dn := $rack.DataNodes }}
<tr>
<td><code>{{ $dc.Id }}</code></td>
<td>{{ $rack.Id }}</td>
<td><a href="http://{{ $dn.Url }}/ui/index.html">{{ $dn.Url }}</a>
{{ if ne $dn.PublicUrl $dn.Url }}
/ <a href="http://{{ $dn.PublicUrl }}/ui/index.html">{{ $dn.PublicUrl }}</a>
{{ end }}
</td>
<td>{{ $dn.Volumes }}</td>
<td>{{ $dn.VolumeIds}}</td>
<td>{{ $dn.EcShards }}</td>
<td>{{ $dn.Max }}</td>
</tr>
{{ end }}
{{ end }}
{{ end }}
</tbody>
</table>
</div>
</div>
</body>
</html>

View file

@ -8,4 +8,8 @@ import (
//go:embed master.html
var masterHtml string
//go:embed masterNewRaft.html
var masterNewRaftHtml string
var StatusTpl = template.Must(template.New("status").Parse(masterHtml))
var StatusNewRaftTpl = template.Must(template.New("status").Parse(masterNewRaftHtml))