diff --git a/examples/telemetry/README.md b/examples/telemetry/README.md index 8769549..caf380b 100644 --- a/examples/telemetry/README.md +++ b/examples/telemetry/README.md @@ -2,7 +2,7 @@ This directory contains an example of how to use the `weaver kube` plugin API to configure how metrics and traces are exported. In `main.go`, we register a -plugin to export traces to Jaeger and a plugin to export metrics to Prometheus. +plugin to export traces to [Jaeger][jaeger] and a plugin to export metrics to [Prometheus][prometheus]. Compile the `telemetry` binary and use it as you would `weaver kube`. Use `prometheus.yaml` and `jaeger.yaml` to deploy Prometheus and Jaeger to a Kubernetes cluster. @@ -10,3 +10,32 @@ Kubernetes cluster. ```console $ kubectl apply -f jaeger.yaml -f prometheus.yaml -f $(telemetry deploy kube_deploy.yaml) ``` + +If you want to visualize your traces and metrics collected by Jaeger and Prometheus +with [Grafana][grafana], you can deploy Grafana using `grafana.yaml`. Note that +Jaeger and Prometheus are automatically added as data sources in Grafana. +`grafana_dashboard.json` is an example of a Service Weaver dashboard that helps +you visualize the metrics generated by Service Weaver. + +```console +$ kubectl apply -f grafana.yaml +``` + +To open Grafana: +```console +$ kubectl port-forward service/grafana 8081:80 +``` + +In your browser open `localhost:8081`. The default username and password is +`admin`, `admin`. + +To open Grafana dashboard, follow the instructions [here][grafana_dashboard]. + +**Note**: `prometheus.yaml`, `jaeger.yaml`, `grafana.yaml` are examples on how +to quickly start Prometheus, Jaeger and Grafana. For production usage, you may +want to customize them further. + +[prometheus]: https://prometheus.io/ +[jaeger]: https://www.jaegertracing.io/ +[grafana]: https://grafana.com/ +[grafana_dashboard]: https://grafana.com/docs/grafana/latest/dashboards/manage-dashboards/#import-a-dashboard \ No newline at end of file diff --git a/examples/telemetry/grafana.yaml b/examples/telemetry/grafana.yaml new file mode 100644 index 0000000..fe716e8 --- /dev/null +++ b/examples/telemetry/grafana.yaml @@ -0,0 +1,77 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Grafana Deployment +apiVersion: apps/v1 +kind: Deployment +metadata: + name: grafana +spec: + replicas: 1 + selector: + matchLabels: + app: grafana + template: + metadata: + labels: + app: grafana + spec: + containers: + - name: grafana + image: grafana/grafana:latest + ports: + - containerPort: 3000 + volumeMounts: + - mountPath: /etc/grafana/provisioning/datasources/grafana.yaml + name: grafana-config + subPath: grafana.yaml + volumes: + - name: grafana-config + configMap: + name: grafana-config + +--- + +# Grafana Service +apiVersion: v1 +kind: Service +metadata: + name: grafana +spec: + ports: + - name: ui-port + port: 80 + targetPort: 3000 + protocol: TCP + selector: + app: grafana + +--- + +# Store grafana.yaml in a ConfigMap. +apiVersion: v1 +kind: ConfigMap +metadata: + name: grafana-config +data: + grafana.yaml: | + apiVersion: 1 + datasources: + - name: Jaeger + type: jaeger + url: http://jaeger:16686 + + - name: Prometheus + type: prometheus + url: http://prometheus:80 diff --git a/internal/impl/dashboard.txt b/examples/telemetry/grafana_dashboard.json similarity index 91% rename from internal/impl/dashboard.txt rename to examples/telemetry/grafana_dashboard.json index 02b7bc5..5098598 100644 --- a/internal/impl/dashboard.txt +++ b/examples/telemetry/grafana_dashboard.json @@ -36,44 +36,6 @@ "title": "Metrics", "type": "row" }, - { - "datasource": { - "type": "loki", - "uid": "P8E80F9AEF21F6940" - }, - "gridPos": { - "h": 40, - "w": 12, - "x": 0, - "y": 1 - }, - "id": 2, - "options": { - "dedupStrategy": "none", - "enableLogDetails": true, - "prettifyLogMessage": false, - "showCommonLabels": false, - "showLabels": false, - "showTime": false, - "sortOrder": "Descending", - "wrapLogMessage": false - }, - "targets": [ - { - "datasource": { - "type": "loki", - "uid": "P8E80F9AEF21F6940" - }, - "editorMode": "builder", - "expr": "{app=\"%s\"}", - "key": "Q-f5ed4dd4-34d6-449d-b547-a020c1407c9d-0", - "queryType": "range", - "refId": "A" - } - ], - "title": "New Panel", - "type": "logs" - }, { "datasource": { "type": "prometheus", @@ -85,6 +47,7 @@ "mode": "palette-classic" }, "custom": { + "axisBorderShow": false, "axisCenteredZero": false, "axisColorMode": "text", "axisLabel": "", @@ -98,6 +61,7 @@ "tooltip": false, "viz": false }, + "insertNulls": false, "lineInterpolation": "linear", "lineWidth": 1, "pointSize": 5, @@ -134,7 +98,7 @@ "gridPos": { "h": 8, "w": 12, - "x": 12, + "x": 0, "y": 1 }, "id": 3, @@ -177,6 +141,7 @@ "mode": "palette-classic" }, "custom": { + "axisBorderShow": false, "axisCenteredZero": false, "axisColorMode": "text", "axisLabel": "", @@ -190,6 +155,7 @@ "tooltip": false, "viz": false }, + "insertNulls": false, "lineInterpolation": "linear", "lineWidth": 1, "pointSize": 5, @@ -226,7 +192,7 @@ "gridPos": { "h": 8, "w": 12, - "x": 12, + "x": 0, "y": 9 }, "id": 9, @@ -298,7 +264,7 @@ "gridPos": { "h": 8, "w": 12, - "x": 12, + "x": 0, "y": 17 }, "id": 10, @@ -372,7 +338,7 @@ "gridPos": { "h": 8, "w": 12, - "x": 12, + "x": 0, "y": 25 }, "id": 4, @@ -446,7 +412,7 @@ "gridPos": { "h": 8, "w": 12, - "x": 12, + "x": 0, "y": 33 }, "id": 8, @@ -483,7 +449,6 @@ ], "refresh": "5s", "schemaVersion": 38, - "style": "dark", "tags": [], "templating": { "list": [] @@ -494,8 +459,8 @@ }, "timepicker": {}, "timezone": "", - "title": "Service Weaver", + "title": "Service Weaver Dashboard", "uid": "c7fcf5e5-00e9-4af5-a246-0eaf3068ac29", - "version": 16, + "version": 2, "weekStart": "" -} +} \ No newline at end of file