Skip to content

Commit

Permalink
Add Grafana yaml example
Browse files Browse the repository at this point in the history
Example to start Grafana and add the Jaeger/Prometheus as data sources
to Grafana.

We also provide an example dashboard that enables the user to visualize
the Service Weaver generated metrics. This can be used as a starting
point to create more advanced dashboards for Service Weaver
applications.
  • Loading branch information
rgrandl committed Nov 7, 2023
1 parent cb12206 commit ca6fab8
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 48 deletions.
31 changes: 30 additions & 1 deletion examples/telemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,40 @@

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.

```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
77 changes: 77 additions & 0 deletions examples/telemetry/grafana.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -85,6 +47,7 @@
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
Expand All @@ -98,6 +61,7 @@
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
Expand Down Expand Up @@ -134,7 +98,7 @@
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"x": 0,
"y": 1
},
"id": 3,
Expand Down Expand Up @@ -177,6 +141,7 @@
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
Expand All @@ -190,6 +155,7 @@
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
Expand Down Expand Up @@ -226,7 +192,7 @@
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"x": 0,
"y": 9
},
"id": 9,
Expand Down Expand Up @@ -298,7 +264,7 @@
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"x": 0,
"y": 17
},
"id": 10,
Expand Down Expand Up @@ -372,7 +338,7 @@
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"x": 0,
"y": 25
},
"id": 4,
Expand Down Expand Up @@ -446,7 +412,7 @@
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"x": 0,
"y": 33
},
"id": 8,
Expand Down Expand Up @@ -483,7 +449,6 @@
],
"refresh": "5s",
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": []
Expand All @@ -494,8 +459,8 @@
},
"timepicker": {},
"timezone": "",
"title": "Service Weaver",
"title": "Service Weaver Dashboard",
"uid": "c7fcf5e5-00e9-4af5-a246-0eaf3068ac29",
"version": 16,
"version": 2,
"weekStart": ""
}
}

0 comments on commit ca6fab8

Please sign in to comment.