Admin Status
This commit is contained in:
parent
2233e08ca1
commit
12c8275326
|
@ -70,6 +70,26 @@ app.filter('hfcduration', function() {
|
|||
}
|
||||
});
|
||||
|
||||
app.controller('statusController', function ($scope, $http) {
|
||||
console.log("statusController");
|
||||
$scope.status_search = "";
|
||||
|
||||
var api = '/api/com.daplie.rvpn/status'
|
||||
|
||||
$scope.updateView = function() {
|
||||
$http.get(api).then(function(response) {
|
||||
console.log(response);
|
||||
data = response.data;
|
||||
if (data.error == 'ok' ){
|
||||
$scope.status = data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$scope.updateView()
|
||||
|
||||
});
|
||||
|
||||
app.controller('serverController', function ($scope, $http) {
|
||||
$scope.servers = [];
|
||||
$scope.servers_search = "";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div class="panel panel-default" data-ng-controller="serverController">
|
||||
<div class="panel panel-default" data-ng-controller="statusController">
|
||||
<div class="panel-heading">
|
||||
<div class="panel-title">
|
||||
<div class="row">
|
||||
|
@ -19,4 +19,28 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-4"> </div>
|
||||
<div class="col-md-8">Server Name: {{ status.name }} (Uptime: {{ status.uptime | hfcduration }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4"> </div>
|
||||
<div class="col-md-8">Administrative Domain: {{ status.admin_domain }} </div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4"> </div>
|
||||
<div class="col-md-8">Server Domain: {{ status.wss_domain }} </div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4"> </div>
|
||||
<div class="col-md-8">Default LB Method: {{ status.loadbalance_default_method }} </div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4"> </div>
|
||||
<div class="col-md-8">Deadtime: dwell:{{ status.dead_time.dwell}} idle:{{ status.dead_time.idle}} cancel:{{ status.dead_time.cancel_check}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package genericlistener
|
||||
|
||||
//ConnectionStatsAPI --
|
||||
type ConnectionStatsAPI struct {
|
||||
Connections int64 `json:"current_connections"`
|
||||
TotalConnections int64 `json:"total_connections"`
|
||||
}
|
||||
|
||||
//NewConnectionStatsAPI -- Consttuctor
|
||||
func NewConnectionStatsAPI(connections int64, totalConnections int64) (p *ConnectionStatsAPI) {
|
||||
p = new(ConnectionStatsAPI)
|
||||
p.Connections = connections
|
||||
p.TotalConnections = totalConnections
|
||||
return
|
||||
}
|
|
@ -6,16 +6,16 @@ import (
|
|||
|
||||
//StatusAPI -- Structure to support the server API
|
||||
type StatusAPI struct {
|
||||
Name string `json:"name"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
WssDomain string `json:"wss_domain"`
|
||||
AdminDomain string `json:"admin_domain"`
|
||||
LoadbalanceDefaultMethod string `json:"loadbalance_default_method"`
|
||||
DeadTime *StatusDeadTimeAPI `json:"dead_time"`
|
||||
AdminStats *TrafficAPI `json:"admin_traffic"`
|
||||
TrafficStats *TrafficAPI `json:"traffic"`
|
||||
ExtConnections *ConnectionStats
|
||||
WSSConnections *ConnectionStats
|
||||
Name string `json:"name"`
|
||||
Uptime float64 `json:"uptime"`
|
||||
WssDomain string `json:"wss_domain"`
|
||||
AdminDomain string `json:"admin_domain"`
|
||||
LoadbalanceDefaultMethod string `json:"loadbalance_default_method"`
|
||||
DeadTime *StatusDeadTimeAPI `json:"dead_time"`
|
||||
AdminStats *TrafficAPI `json:"admin_traffic"`
|
||||
TrafficStats *TrafficAPI `json:"traffic"`
|
||||
ExtConnections *ConnectionStatsAPI `json:"ext_connections"`
|
||||
WSSConnections *ConnectionStatsAPI `json:"wss_connections"`
|
||||
}
|
||||
|
||||
//NewStatusAPI - Constructor
|
||||
|
@ -29,6 +29,8 @@ func NewStatusAPI(c *Status) (s *StatusAPI) {
|
|||
s.DeadTime = NewStatusDeadTimeAPI(c.DeadTime.dwell, c.DeadTime.idle, c.DeadTime.cancelcheck)
|
||||
s.AdminStats = NewTrafficAPI(c.AdminStats.Requests, c.AdminStats.Responses, c.AdminStats.BytesIn, c.AdminStats.BytesOut)
|
||||
s.TrafficStats = NewTrafficAPI(c.TrafficStats.Requests, c.TrafficStats.Responses, c.TrafficStats.BytesIn, c.TrafficStats.BytesOut)
|
||||
s.ExtConnections = NewConnectionStatsAPI(c.ExtConnections.Connections, c.ExtConnections.TotalConnections)
|
||||
s.WSSConnections = NewConnectionStatsAPI(c.WSSConnections.Connections, c.ExtConnections.TotalConnections)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -17,13 +17,14 @@ const (
|
|||
)
|
||||
|
||||
var connectionTable *Table
|
||||
var serverStatus *Status
|
||||
var serverStatusAPI *Status
|
||||
|
||||
//handleAdminClient -
|
||||
// - expecting an existing oneConnListener with a qualified wss client connected.
|
||||
// - auth will happen again since we were just peeking at the token.
|
||||
func handleAdminClient(ctx context.Context, oneConn *oneConnListener) {
|
||||
serverStatus := ctx.Value(ctxServerStatus).(*Status)
|
||||
serverStatus = ctx.Value(ctxServerStatus).(*Status)
|
||||
|
||||
connectionTable = serverStatus.ConnectionTable
|
||||
serverStatusAPI = serverStatus
|
||||
|
@ -33,11 +34,16 @@ func handleAdminClient(ctx context.Context, oneConn *oneConnListener) {
|
|||
|
||||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
loginfo.Println("HandleFunc /")
|
||||
|
||||
serverStatus.AdminStats.IncRequests()
|
||||
|
||||
switch url := r.URL.Path; url {
|
||||
case "/":
|
||||
// check to see if we are using the administrative Host
|
||||
if strings.Contains(r.Host, "rvpn.daplie.invalid") {
|
||||
http.Redirect(w, r, "/admin", 301)
|
||||
serverStatus.AdminStats.IncResponses()
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -74,6 +80,8 @@ func getStatusEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
serverStatus.AdminStats.IncRequests()
|
||||
|
||||
statusContainer := NewStatusAPI(serverStatusAPI)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
|
@ -81,13 +89,15 @@ func getStatusEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
env := envelope.NewEnvelope("domains/GET")
|
||||
env.Result = statusContainer
|
||||
env.GenerateWriter(w)
|
||||
|
||||
serverStatus.AdminStats.IncResponses()
|
||||
}
|
||||
|
||||
func getDomainsEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
serverStatus.AdminStats.IncRequests()
|
||||
|
||||
domainsContainer := NewDomainsAPIContainer()
|
||||
|
||||
for domain := range connectionTable.domains {
|
||||
|
@ -102,13 +112,15 @@ func getDomainsEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
env := envelope.NewEnvelope("domains/GET")
|
||||
env.Result = domainsContainer
|
||||
env.GenerateWriter(w)
|
||||
|
||||
serverStatus.AdminStats.IncResponses()
|
||||
}
|
||||
|
||||
func getDomainEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
serverStatus.AdminStats.IncRequests()
|
||||
|
||||
env := envelope.NewEnvelope("domain/GET")
|
||||
|
||||
params := mux.Vars(r)
|
||||
|
@ -130,12 +142,15 @@ func getDomainEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
env.GenerateWriter(w)
|
||||
serverStatus.AdminStats.IncResponses()
|
||||
}
|
||||
|
||||
func getServersEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
serverStatus.AdminStats.IncRequests()
|
||||
|
||||
serverContainer := NewServerAPIContainer()
|
||||
|
||||
for c := range connectionTable.Connections() {
|
||||
|
@ -149,12 +164,15 @@ func getServersEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
env := envelope.NewEnvelope("servers/GET")
|
||||
env.Result = serverContainer
|
||||
env.GenerateWriter(w)
|
||||
serverStatus.AdminStats.IncResponses()
|
||||
}
|
||||
|
||||
func getServerEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
||||
|
||||
serverStatus.AdminStats.IncRequests()
|
||||
|
||||
env := envelope.NewEnvelope("server/GET")
|
||||
|
||||
params := mux.Vars(r)
|
||||
|
@ -185,4 +203,5 @@ func getServerEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
env.GenerateWriter(w)
|
||||
serverStatus.AdminStats.IncResponses()
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ type Status struct {
|
|||
GenericListeners *GenericListeners
|
||||
LoadbalanceDefaultMethod string
|
||||
AdminStats *TrafficStats
|
||||
AdminReqTyoe *AdminReqType
|
||||
TrafficStats *TrafficStats
|
||||
ExtConnections *ConnectionStats
|
||||
WSSConnections *ConnectionStats
|
||||
|
|
|
@ -2,22 +2,27 @@ package genericlistener
|
|||
|
||||
//ConnectionStats --
|
||||
type ConnectionStats struct {
|
||||
Connections int64
|
||||
Connections int64
|
||||
TotalConnections int64
|
||||
}
|
||||
|
||||
//NewConnectionStats -- Consttuctor
|
||||
func NewConnectionStats() (p *ConnectionStats) {
|
||||
p = new(ConnectionStats)
|
||||
p.Connections = 0
|
||||
p.TotalConnections = 0
|
||||
return
|
||||
}
|
||||
|
||||
//IncConnections --
|
||||
func (p *ConnectionStats) IncConnections() {
|
||||
p.Connections++
|
||||
p.TotalConnections++
|
||||
}
|
||||
|
||||
//DecConnections --
|
||||
func (p *ConnectionStats) DecConnections() {
|
||||
p.Connections--
|
||||
if p.Connections > 0 {
|
||||
p.Connections--
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue