diff --git a/html/admin/js/app.js b/html/admin/js/app.js index 77ec008..595f99c 100644 --- a/html/admin/js/app.js +++ b/html/admin/js/app.js @@ -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 = ""; diff --git a/html/admin/partials/status.html b/html/admin/partials/status.html index 5ccff84..05f4569 100644 --- a/html/admin/partials/status.html +++ b/html/admin/partials/status.html @@ -1,4 +1,4 @@ -
+
@@ -19,4 +19,28 @@
-
\ No newline at end of file +
+
+
+
Server Name: {{ status.name }} (Uptime: {{ status.uptime | hfcduration }}
+
+
+
+
Administrative Domain: {{ status.admin_domain }}
+
+
+
+
Server Domain: {{ status.wss_domain }}
+
+
+
+
Default LB Method: {{ status.loadbalance_default_method }}
+
+
+
+
Deadtime: dwell:{{ status.dead_time.dwell}} idle:{{ status.dead_time.idle}} cancel:{{ status.dead_time.cancel_check}}
+
+
+
+ + diff --git a/rvpn/genericlistener/api_collect_connections.go b/rvpn/genericlistener/api_collect_connections.go new file mode 100644 index 0000000..4b113f1 --- /dev/null +++ b/rvpn/genericlistener/api_collect_connections.go @@ -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 +} diff --git a/rvpn/genericlistener/api_collect_status.go b/rvpn/genericlistener/api_collect_status.go index 88a2c5f..2104b22 100644 --- a/rvpn/genericlistener/api_collect_status.go +++ b/rvpn/genericlistener/api_collect_status.go @@ -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 } diff --git a/rvpn/genericlistener/api_interface.go b/rvpn/genericlistener/api_interface.go index e24a364..5f3ec96 100644 --- a/rvpn/genericlistener/api_interface.go +++ b/rvpn/genericlistener/api_interface.go @@ -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() } diff --git a/rvpn/genericlistener/status.go b/rvpn/genericlistener/status.go index 631b85e..1cd3369 100644 --- a/rvpn/genericlistener/status.go +++ b/rvpn/genericlistener/status.go @@ -18,6 +18,7 @@ type Status struct { GenericListeners *GenericListeners LoadbalanceDefaultMethod string AdminStats *TrafficStats + AdminReqTyoe *AdminReqType TrafficStats *TrafficStats ExtConnections *ConnectionStats WSSConnections *ConnectionStats diff --git a/rvpn/genericlistener/status_traffic_connections.go b/rvpn/genericlistener/status_traffic_connections.go index d19db3e..f412725 100644 --- a/rvpn/genericlistener/status_traffic_connections.go +++ b/rvpn/genericlistener/status_traffic_connections.go @@ -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-- + } }