diff --git a/gateway/assets/icon.png b/gateway/assets/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c68b3d132f4aa2327c0c3337efca4b472b4fe38d Binary files /dev/null and b/gateway/assets/icon.png differ diff --git a/gateway/assets/index.html b/gateway/assets/index.html index 335fe944ee851512a159d9df2c1400eae538d2d0..4f9273b4ebd3742d5c8fa244583510ea81d55f01 100644 --- a/gateway/assets/index.html +++ b/gateway/assets/index.html @@ -17,7 +17,7 @@ <md-sidenav class="md-sidenav-left" md-component-id="left" md-is-locked-open="$mdMedia('gt-sm')" md-whiteframe="4" layout="column"> <md-toolbar class="md-theme-indigo"> - <h1 class="md-toolbar-tools">FaaS Gateway</h1> + <h1 class="md-toolbar-tools"><img src="icon.png" alt="OpenFaaS Icon" width="60px" height="60px" class="md-avatar"/> OpenFaaS Portal</h1> </md-toolbar> <md-content layout-padding> @@ -55,8 +55,8 @@ <md-card-title-text> <span class="md-headline"> - {{function.name}} - </span> + {{function.name}} + </span> <div layout-gt-sm="row"> <md-input-container class="md-icon-float md-block"> <label>Replicas</label> @@ -74,6 +74,12 @@ <input ng-model="function.image" type="text" readonly="readonly"> </md-input-container> </div> + <div layout-gt-sm="row" ng-show="function.envProcess"> + <md-input-container class="md-block" flex-gt-sm> + <label>Watchdog process</label> + <input ng-model="function.envProcess" type="text" readonly="readonly"> + </md-input-container> + </div> <md-card-title-text> </md-card-title> </md-card> diff --git a/gateway/handlers/functionshandler.go b/gateway/handlers/functionshandler.go index f41f9a2c2cd292f181f159992a88159aaf573b97..724eba7c2d64644cd380a608e44c702ca8314751 100644 --- a/gateway/handlers/functionshandler.go +++ b/gateway/handlers/functionshandler.go @@ -44,47 +44,6 @@ func getCounterValue(service string, code string, metricsOptions *metrics.Metric return invocations } -// MakeFunctionReader gives a summary of Function structs with Docker service stats overlaid with Prometheus counters. -func MakeFunctionReader(metricsOptions metrics.MetricOptions, c *client.Client) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - serviceFilter := filters.NewArgs() - - options := types.ServiceListOptions{ - Filters: serviceFilter, - } - - services, err := c.ServiceList(context.Background(), options) - if err != nil { - fmt.Println(err) - } - - // TODO: Filter only "faas" functions (via metadata?) - var functions []requests.Function - - for _, service := range services { - - if len(service.Spec.TaskTemplate.ContainerSpec.Labels["function"]) > 0 { - invocations := getCounterValue(service.Spec.Name, "200", &metricsOptions) + - getCounterValue(service.Spec.Name, "500", &metricsOptions) - - f := requests.Function{ - Name: service.Spec.Name, - Image: service.Spec.TaskTemplate.ContainerSpec.Image, - InvocationCount: invocations, - Replicas: *service.Spec.Mode.Replicated.Replicas, - } - functions = append(functions, f) - } - } - - functionBytes, _ := json.Marshal(functions) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(200) - w.Write(functionBytes) - } -} - func MakeDeleteFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Client) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/gateway/handlers/reader.go b/gateway/handlers/reader.go new file mode 100644 index 0000000000000000000000000000000000000000..6af4cb54e0a2efd092f3ca679c5c6a7eaa1339ca --- /dev/null +++ b/gateway/handlers/reader.go @@ -0,0 +1,67 @@ +package handlers + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "strings" + + "github.com/alexellis/faas/gateway/metrics" + "github.com/alexellis/faas/gateway/requests" + "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/client" +) + +// MakeFunctionReader gives a summary of Function structs with Docker service stats overlaid with Prometheus counters. +func MakeFunctionReader(metricsOptions metrics.MetricOptions, c *client.Client) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + serviceFilter := filters.NewArgs() + + options := types.ServiceListOptions{ + Filters: serviceFilter, + } + + services, err := c.ServiceList(context.Background(), options) + if err != nil { + fmt.Println(err) + } + + // TODO: Filter only "faas" functions (via metadata?) + var functions []requests.Function + + for _, service := range services { + + if len(service.Spec.TaskTemplate.ContainerSpec.Labels["function"]) > 0 { + invocations := getCounterValue(service.Spec.Name, "200", &metricsOptions) + + getCounterValue(service.Spec.Name, "500", &metricsOptions) + + var envProcess string + + for _, env := range service.Spec.TaskTemplate.ContainerSpec.Env { + if strings.Index(env, "fprocess=") > -1 { + envProcess = env[len("fprocess="):] + } + } + + f := requests.Function{ + Name: service.Spec.Name, + Image: service.Spec.TaskTemplate.ContainerSpec.Image, + InvocationCount: invocations, + Replicas: *service.Spec.Mode.Replicated.Replicas, + EnvProcess: envProcess, + } + + functions = append(functions, f) + } + } + + functionBytes, _ := json.Marshal(functions) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + w.Write(functionBytes) + } +} diff --git a/gateway/requests/requests.go b/gateway/requests/requests.go index 8f75342daceea59f12a8ba52a54ca5e7c242722f..e437d6d1d45d9d3666515a167e6f3e8087f5caa4 100644 --- a/gateway/requests/requests.go +++ b/gateway/requests/requests.go @@ -75,4 +75,5 @@ type Function struct { Image string `json:"image"` InvocationCount float64 `json:"invocationCount"` // TODO: shouldn't this be int64? Replicas uint64 `json:"replicas"` + EnvProcess string `json:"envProcess"` }