diff --git a/gateway/assets/icon.png b/gateway/assets/icon.png new file mode 100644 index 00000000..c68b3d13 Binary files /dev/null and b/gateway/assets/icon.png differ diff --git a/gateway/assets/index.html b/gateway/assets/index.html index 335fe944..4f9273b4 100644 --- a/gateway/assets/index.html +++ b/gateway/assets/index.html @@ -17,7 +17,7 @@ -

FaaS Gateway

+

OpenFaaS Icon  OpenFaaS Portal

@@ -55,8 +55,8 @@ - {{function.name}} - + {{function.name}} +
@@ -74,6 +74,12 @@
+
+ + + + +
diff --git a/gateway/handlers/functionshandler.go b/gateway/handlers/functionshandler.go index f41f9a2c..724eba7c 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 00000000..6af4cb54 --- /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 8f75342d..e437d6d1 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"` }