The OpenFaaS dashboard

A good OpenFaaS dashboard is available on the Grafana platform. To make Grafana work with OpenFaaS, the Grafana server must be on the same network. We can use the following command to run a Grafana server via docker service create outside the OpenFaaS stack. It links to the OpenFaaS stack via the --network=func_functions argument:

$ docker service create --name=grafana 
--network=func_functions
-p 3000:3000 grafana/grafana

Alternatively, open the dashboard at http://localhost:3000. Log in using the username admin and password admin:

Figure 4.11: Grafana home dashboard 

A data source has to be created and pointed to the Prometheus server before using it as the source of a dashboard. Firstly, the data source name must be prometheus. Secondly, the URL needs to point to http://prometheus:9090. After that, we can click the Save and Test buttons. A green popup will be displayed if the data source setting is correct:

Figure 4.12: Defining a new Prometheus data source in Grafana

Next, an OpenFaaS dashboard can be imported using the dashboard's ID. We will use dashboard number 3434, then click on Load to prepare to import the dashboard:

Figure 4.13: The dashboard importing screen in Grafana

Next, the dialog will be changed to Importing Dashboard from Grafana.com. Here, it will ask us to include the dashboard name. We can leave it as the default name. It will also ask which data source we would like to use. Choose the Prometheus data source, which s already defined in the previous steps. After that, click the Import button to finish the importing process:

Figure 4.14: Setting the dashboard's name and selecting the Prometheus data source for it

Here's what the dashboard looks like. It displays the gateway's health status in a box and the number of gateway services as a gauge. The total function invocation stat is displayed as a line chart with numbers. The hello function written in Go is linearly invoked more than 20,000 times. During the test, the number of function replicas is scaled up, from five to 20. However, it is tested on a single machine, so the invocation rate does not change significantly:

Figure 4.15: The OpenFaaS dashboard in action

Here's the mechanism to allow OpenFaaS to auto-scale function replicas. First, when a client requests function invocation through the API gateway, the invocation will be stored in Prometheus. Inside Prometheus, there is an Alert Manager, which is responsible for firing events when a predefined rule is matched. OpenFaaS defines a rule for the Alert Manager to scale the number of replicas up by hooking the event with its Alert Handler URL, http://gateway:8080/system/alert. This Alert Handler will take care of calculating the number of replicas, checking the max replicas limit, and scaling the replicas of a certain function by sending the scale command to the cluster via the Swarm client API. The following diagram illustrates the steps behind this autoscaling mechanism:

Figure 4.16: The alerting mechanism of OpenFaaS to auto-scale the replicas of function services in the Docker Swarm
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset