diff --git a/grafana-dashboards/openfaas-dash.json b/grafana-dashboards/openfaas-dash.json new file mode 100644 index 0000000..da95325 --- /dev/null +++ b/grafana-dashboards/openfaas-dash.json @@ -0,0 +1,395 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 5, + "links": [], + "panels": [ + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "hiddenSeries": false, + "id": 2, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "rate ( gateway_function_invocation_total [20s])", + "legendFormat": "{{ function_name }} {{code}}", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Function rate", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "hiddenSeries": false, + "id": 4, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "gateway_service_count", + "legendFormat": "{{function_name}} ", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Replica scaling", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "hiddenSeries": false, + "id": 8, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "dataLinks": [] + }, + "percentage": false, + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "(rate(gateway_functions_seconds_sum[20s]) / rate(gateway_functions_seconds_count[20s]))", + "legendFormat": "{{function_name}} ", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Execution duration (s)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "cacheTimeout": null, + "colorBackground": false, + "colorValue": false, + "colors": [ + "#299c46", + "rgba(237, 129, 40, 0.89)", + "#d44a3a" + ], + "datasource": null, + "format": "none", + "gauge": { + "maxValue": 100, + "minValue": 0, + "show": false, + "thresholdLabels": false, + "thresholdMarkers": true + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 9 + }, + "id": 6, + "interval": null, + "links": [], + "mappingType": 1, + "mappingTypes": [ + { + "name": "value to text", + "value": 1 + }, + { + "name": "range to text", + "value": 2 + } + ], + "maxDataPoints": 100, + "nullPointMode": "connected", + "nullText": null, + "options": {}, + "postfix": "", + "postfixFontSize": "50%", + "prefix": "", + "prefixFontSize": "50%", + "rangeMaps": [ + { + "from": "null", + "text": "N/A", + "to": "null" + } + ], + "sparkline": { + "fillColor": "rgba(31, 118, 189, 0.18)", + "full": false, + "lineColor": "rgb(31, 120, 193)", + "show": false, + "ymax": null, + "ymin": null + }, + "tableColumn": "", + "targets": [ + { + "expr": "scalar( sum( gateway_function_invocation_total { code=\"200\"} ))", + "legendFormat": "", + "refId": "A" + } + ], + "thresholds": "", + "timeFrom": null, + "timeShift": null, + "title": "Total requests - 200 OK", + "type": "singlestat", + "valueFontSize": "80%", + "valueMaps": [ + { + "op": "=", + "text": "N/A", + "value": "null" + } + ], + "valueName": "avg" + } + ], + "schemaVersion": 22, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "", + "title": "OpenFaaS", + "uid": "MSmPanhnz", + "version": 3 +} diff --git a/lab1.md b/lab1.md index 3a92da2..0567cfe 100644 --- a/lab1.md +++ b/lab1.md @@ -16,7 +16,7 @@ For Mac * [Docker CE for Mac Edge Edition](https://store.docker.com/editions/community/docker-ce-desktop-mac) -For Windows +For Windows * Use Windows 10 Pro or Enterprise only * Install [Docker CE for Windows](https://store.docker.com/editions/community/docker-ce-desktop-windows) diff --git a/lab2.md b/lab2.md index e6e02c9..244ec1f 100644 --- a/lab2.md +++ b/lab2.md @@ -70,8 +70,8 @@ You'll see an ASCII logo generated like this: ```sh _ ___ ___ _ __ / |/ _ \ / _ (_)/ / -| | | | | | | |/ / -| | |_| | |_| / /_ +| | | | | | | |/ / +| | |_| | |_| / /_ |_|\___/ \___/_/(_) ``` @@ -134,18 +134,13 @@ OpenFaaS tracks metrics on your functions automatically using Prometheus. The me Run Grafana in OpenFaaS Kubernetes namespace: ```sh -kubectl -n openfaas run \ ---image=stefanprodan/faas-grafana:4.6.3 \ ---port=3000 \ -grafana +arkade install --namespace openfaas grafana ``` -Expose Grafana with a NodePort: +Get the `admin` password: ```sh -kubectl -n openfaas expose pod grafana \ ---type=NodePort \ ---name=grafana +kubectl get secret --namespace openfaas grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo ``` Find Grafana node port address: @@ -159,15 +154,60 @@ where `IP_ADDRESS` is your corresponding IP for Kubernetes. Or you may run this port-forwarding command in order to be able to access Grafana on `http://127.0.0.1:3000`: ```sh -$ kubectl port-forward pod/grafana 3000:3000 -n openfaas +kubectl port-forward svc/grafana 3000:80 -n openfaas ``` If you're using Kubernetes 1.17 or older, use `deploy/grafana` instead of `pod/` in the command above. -After the service has been created open Grafana in your browser, login with username `admin` password `admin` and navigate to the pre-made OpenFaaS dashboard at `$GRAFANA_URL`. +After the service has been created open Grafana in your browser, login with username `admin` password that you retrieved in the step above and navigate to the pre-made OpenFaaS dashboard at `$GRAFANA_URL` or if using the port forward `http://127.0.0.1:3000`. *Pictured: example of an OpenFaaS dashboard with Grafana* +### Configuring Grafana + +1. Setup `Datasource` + +After you login you will need to add the Datasource in order to Grafana knows where to collect the data to show. +To do that mouse over in the `Engine` icon and then click in the `Data Soruces` + +![Data Sources](./screenshot/grafana_data_sources.png) + +1.1. Click in `Add data source` + +![Add data source](./screenshot/grafana_add_data_source.png) + +1.2. Click in the `Select` button for the Prometheus Data Source + +![Prometheus data source](./screenshot/grafana_prometheus_data_source.png) + +1.3. Prometheus is installed with OpenFaaS and you can access that in the cluster using the service that is exposed `http://prometheus.openfaas:9090`` + +Add that information in the `URL` field and then click in the `Save & Test` button to save and validate the connection. + +![Prometheus](./screenshot/grafana_prometheus.png) + + +### Load initial Grafana Dashboard + +1.1 Click in the `Grafana` logo to return to the main page and mouse over the `plus` icon and then click in the `Import` + +![Import](./screenshot/grafana_import.png) + +1.2 Copy the contents of the file located in [grafana-dashboards/openfaas-dash.json](grafana-dashboards/openfaas-dash.json) and paste it +in the box under `Or paste JSON` and then click `Load` + +![Import JSON](./screenshot/grafana_import_json.png) + +1.3 Give a name for your Dashboard and click `Import` + +![Dashboard Name](./screenshot/grafana_dashboard_name.png) + +It will load and show the initial OpenFaaS Dashboards. +Now invoke some functions and you will see the graphs getting updated. + +![Dashboards](./screenshot/grafana_dashboard.png) + + Now move onto [Lab 3](./lab3.md) diff --git a/screenshot/grafana_add_data_source.png b/screenshot/grafana_add_data_source.png new file mode 100644 index 0000000..dbbc6c1 Binary files /dev/null and b/screenshot/grafana_add_data_source.png differ diff --git a/screenshot/grafana_dashboard.png b/screenshot/grafana_dashboard.png new file mode 100644 index 0000000..0bcda14 Binary files /dev/null and b/screenshot/grafana_dashboard.png differ diff --git a/screenshot/grafana_dashboard_name.png b/screenshot/grafana_dashboard_name.png new file mode 100644 index 0000000..9c2591a Binary files /dev/null and b/screenshot/grafana_dashboard_name.png differ diff --git a/screenshot/grafana_data_sources.png b/screenshot/grafana_data_sources.png new file mode 100644 index 0000000..1fe97f4 Binary files /dev/null and b/screenshot/grafana_data_sources.png differ diff --git a/screenshot/grafana_import.png b/screenshot/grafana_import.png new file mode 100644 index 0000000..fe4e711 Binary files /dev/null and b/screenshot/grafana_import.png differ diff --git a/screenshot/grafana_import_json.png b/screenshot/grafana_import_json.png new file mode 100644 index 0000000..1bab46d Binary files /dev/null and b/screenshot/grafana_import_json.png differ diff --git a/screenshot/grafana_prometheus.png b/screenshot/grafana_prometheus.png new file mode 100644 index 0000000..9dc3614 Binary files /dev/null and b/screenshot/grafana_prometheus.png differ diff --git a/screenshot/grafana_prometheus_data_source.png b/screenshot/grafana_prometheus_data_source.png new file mode 100644 index 0000000..24d2759 Binary files /dev/null and b/screenshot/grafana_prometheus_data_source.png differ