Add some configurable variables to stats page (#373)
* add switch to mask peer address in stats page * add setting to use custom httpAddr in stats page * make stats URI of peer configurable
This commit is contained in:
parent
41d287ecb4
commit
63684f143d
@ -26,7 +26,7 @@ Taken at {{ .Now }}
|
||||
|
||||
<h3 id="gossip-peers">Gossip Peers</h3>
|
||||
<table><tr><th>Name</th><th>HTTP</th><th>Recon</th><th>Recon Status</th><th>Recovery Status</th></tr>
|
||||
{{ range $peer := .Peers }}<tr><td>{{ $peer.Name }}</td><td><a href="http://{{ $peer.HTTPAddr }}/pks/lookup?op=stats">{{ $peer.HTTPAddr }}</a></td><td>{{ $peer.ReconAddr }}</td><td>{{ $peer.ReconStatus }}</td><td>{{ $peer.RecoveryStatus }}</td></tr>
|
||||
{{ range $peer := .Peers }}<tr><td>{{ $peer.Name }}</td><td><a href="http://{{ $peer.HTTPAddr }}{{ $peer.StatsPath }}">{{ $peer.HTTPAddr }}</a></td><td>{{ $peer.ReconAddr }}</td><td>{{ $peer.ReconStatus }}</td><td>{{ $peer.RecoveryStatus }}</td></tr>
|
||||
{{ end }}</table>
|
||||
|
||||
<h2 id="statistics">Statistics</h2>
|
||||
|
@ -77,6 +77,14 @@ type Partner struct {
|
||||
ReconAddr string `toml:"reconAddr"`
|
||||
ReconNet netType `toml:"reconNet" json:"-"`
|
||||
Weight int `toml:"weight"`
|
||||
// WebAddr overwrites HTTPAddr on stats page where the server is supposed
|
||||
// to be accessed via a different domain/port than hockeypuck process.
|
||||
// e.g., when there is a reverse proxy or load balancer
|
||||
WebAddr string `toml:"webAddr"`
|
||||
// StatsPath is the endpoint of stats page on this peer
|
||||
StatsPath string `toml:"statsPath"`
|
||||
// Mask the HTTPAddr and ReconAddr shown in stats page
|
||||
Mask bool `toml:"mask"`
|
||||
// Name is a copy of the key used in the Settings map
|
||||
Name string
|
||||
// Addr is the resolved address last used by outgoing recon
|
||||
|
@ -225,16 +225,32 @@ type loadStat struct {
|
||||
Time time.Time
|
||||
}
|
||||
|
||||
// maskString replace input string with * to hide sensitive information
|
||||
func maskString(orig string) string {
|
||||
if orig == "" {
|
||||
return orig
|
||||
}
|
||||
if len(orig) < 4 {
|
||||
return "******"
|
||||
}
|
||||
return string([]byte{orig[0]}) + "****" + string([]byte{orig[len(orig)-1]})
|
||||
}
|
||||
|
||||
type loadStats []loadStat
|
||||
|
||||
func (s loadStats) Len() int { return len(s) }
|
||||
func (s loadStats) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s loadStats) Less(i, j int) bool { return s[i].Time.Before(s[j].Time) }
|
||||
|
||||
// default value of stats endpoint path
|
||||
const defaultStatsPath = "/pks/lookup?op=stats"
|
||||
|
||||
type statsPeer struct {
|
||||
Name string
|
||||
HTTPAddr string `json:"httpAddr"`
|
||||
ReconAddr string `json:"reconAddr"`
|
||||
StatsPath string `json:"statsPath"`
|
||||
Masked bool `json:"masked,omitempty"`
|
||||
LastIncomingRecon time.Time
|
||||
LastIncomingError string
|
||||
LastOutgoingRecon time.Time
|
||||
@ -319,10 +335,11 @@ func (s *Server) stats(req *http.Request) (interface{}, error) {
|
||||
// If no recovery yet, then throw consistent error instead of implying that recovery is working.
|
||||
recoveryStatus = reconStatus
|
||||
}
|
||||
result.Peers = append(result.Peers, statsPeer{
|
||||
peerInfo := statsPeer{
|
||||
Name: v.Name,
|
||||
HTTPAddr: v.HTTPAddr,
|
||||
ReconAddr: v.ReconAddr,
|
||||
StatsPath: defaultStatsPath,
|
||||
LastIncomingRecon: v.LastIncomingRecon,
|
||||
LastIncomingError: fmt.Sprintf("%q", v.LastIncomingError),
|
||||
LastOutgoingRecon: v.LastOutgoingRecon,
|
||||
@ -331,7 +348,23 @@ func (s *Server) stats(req *http.Request) (interface{}, error) {
|
||||
LastRecovery: v.LastRecovery,
|
||||
LastRecoveryError: fmt.Sprintf("%q", v.LastRecoveryError),
|
||||
RecoveryStatus: recoveryStatus,
|
||||
})
|
||||
}
|
||||
if v.StatsPath != "" {
|
||||
if !strings.HasPrefix(v.StatsPath, "/") {
|
||||
peerInfo.StatsPath = "/" + v.StatsPath
|
||||
} else {
|
||||
peerInfo.StatsPath = v.StatsPath
|
||||
}
|
||||
}
|
||||
if v.WebAddr != "" {
|
||||
peerInfo.HTTPAddr = v.WebAddr
|
||||
}
|
||||
if v.Mask {
|
||||
peerInfo.HTTPAddr = maskString(peerInfo.HTTPAddr)
|
||||
peerInfo.ReconAddr = maskString(v.ReconAddr)
|
||||
peerInfo.Masked = true
|
||||
}
|
||||
result.Peers = append(result.Peers, peerInfo)
|
||||
}
|
||||
sort.Sort(statsPeers(result.Peers))
|
||||
return result, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user