Admin Status

This commit is contained in:
Henry Camacho 2017-03-23 18:10:49 -05:00
parent 2233e08ca1
commit 12c8275326
7 changed files with 103 additions and 17 deletions

View File

@ -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 = "";

View File

@ -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 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>

View File

@ -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
}

View File

@ -14,8 +14,8 @@ type StatusAPI struct {
DeadTime *StatusDeadTimeAPI `json:"dead_time"`
AdminStats *TrafficAPI `json:"admin_traffic"`
TrafficStats *TrafficAPI `json:"traffic"`
ExtConnections *ConnectionStats
WSSConnections *ConnectionStats
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
}

View File

@ -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()
}

View File

@ -18,6 +18,7 @@ type Status struct {
GenericListeners *GenericListeners
LoadbalanceDefaultMethod string
AdminStats *TrafficStats
AdminReqTyoe *AdminReqType
TrafficStats *TrafficStats
ExtConnections *ConnectionStats
WSSConnections *ConnectionStats

View File

@ -3,21 +3,26 @@ package genericlistener
//ConnectionStats --
type ConnectionStats struct {
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() {
if p.Connections > 0 {
p.Connections--
}
}