Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add grafana metric dashboard example #78

Merged
merged 6 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Check out on [go-dcp](https://github.com/Trendyol/go-dcp#configuration)
You can also use all DCP-related metrics explained [here](https://github.com/Trendyol/go-dcp#exposed-metrics).
All DCP-related metrics are automatically injected. It means you don't need to do anything.

## Grafana Metric Dashboard

[Grafana & Prometheus Example](example/grafana)

## Contributing

Go Dcp Elasticsearch is always open for direct contributions. For more information please check
Expand Down
22 changes: 22 additions & 0 deletions example/grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.21-alpine AS builder

WORKDIR /project

COPY go.mod go.sum ./
COPY main.go ./
COPY config.yml ./config.yml

RUN go mod download
RUN CGO_ENABLED=0 go build -a -o example main.go

FROM alpine:3.17.1

WORKDIR /app

RUN apk --no-cache add ca-certificates

USER nobody
COPY --from=builder --chown=nobody:nobody /project/example .
COPY --from=builder --chown=nobody:nobody /project/config.yml ./config.yml

ENTRYPOINT ["./example"]
21 changes: 21 additions & 0 deletions example/grafana/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
hosts:
- couchbase:8091
username: user
password: password
bucketName: dcp-test
dcp:
group:
name: groupName
membership:
type: static
metadata:
type: couchbase
config:
bucket: dcp-test
scope: _default
collection: _default
elasticsearch:
collectionIndexMapping:
_default: index-test
urls:
- "http://elasticsearch:9200"
6 changes: 6 additions & 0 deletions example/grafana/couchbase/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM couchbase:7.6.2

COPY configure.sh /opt/couchbase
RUN chmod +x /opt/couchbase/configure.sh

CMD ["/opt/couchbase/configure.sh"]
29 changes: 29 additions & 0 deletions example/grafana/couchbase/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Start Couchbase server in background
/entrypoint.sh couchbase-server &

# Wait for Couchbase to start
sleep 10

# Setup cluster
couchbase-cli cluster-init -c 127.0.0.1:8091 \
--cluster-username user \
--cluster-password password \
--services data,index,query,fts,eventing,analytics \
--cluster-ramsize 1024 \
--cluster-index-ramsize 256 \
--cluster-fts-ramsize 256 \
--cluster-eventing-ramsize 256 \
--cluster-analytics-ramsize 1024

# Create a bucket
couchbase-cli bucket-create -c 127.0.0.1:8091 \
--username user \
--password password \
--bucket dcp-test \
--bucket-type couchbase \
--bucket-ramsize 256

# Keep the container running
tail -f /dev/null
75 changes: 75 additions & 0 deletions example/grafana/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
version: '3.9'

volumes:
prometheus_data: { }
grafana_data: { }

services:
go-dcp-elastic:
build: .
ports:
- "8080:8080"
expose:
- 8080
depends_on:
- couchbase
- elasticsearch

elasticsearch:
image: elasticsearch:7.17.22
container_name: elasticsearch
environment:
- node.name=es01
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- xpack.security.enabled=false
- xpack.monitoring.collection.enabled=true
ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
- "9300:9300"
expose:
- 9200

couchbase:
build: ./couchbase
ports:
- "8091-8094:8091-8094"
- "11210:11210"
expose:
- 8091
environment:
- COUCHBASE_ADMINISTRATOR_USERNAME=user
- COUCHBASE_ADMINISTRATOR_PASSWORD=password

prometheus:
image: prom/prometheus:v2.53.1
container_name: prometheus
volumes:
- ./prometheus:/etc/prometheus
- prometheus_data:/prometheus
ports:
- "9090:9090"
expose:
- 9090

grafana:
image: grafana/grafana:10.0.0
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_ANONYMOUS_ENABLED=true
ports:
- "3000:3000"
expose:
- 3000
depends_on:
- prometheus
87 changes: 87 additions & 0 deletions example/grafana/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module grafana

go 1.21

require (
github.com/Trendyol/go-dcp-elasticsearch v1.1.63
github.com/couchbase/gocb/v2 v2.9.1
)

require (
github.com/Trendyol/go-dcp v1.1.50 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.6.1 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/couchbase/gocbcore/v10 v10.5.1 // indirect
github.com/couchbase/gocbcoreps v0.1.3 // indirect
github.com/couchbase/goprotostellar v1.0.2 // indirect
github.com/couchbaselabs/gocbconnstr/v2 v2.0.0-20240607131231-fb385523de28 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elastic/go-elasticsearch/v7 v7.17.10 // indirect
github.com/emicklei/go-restful/v3 v3.11.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/gofiber/adaptor/v2 v2.2.1 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mhmtszr/concurrent-swiss-map v1.0.8 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.4 // indirect
k8s.io/apimachinery v0.29.4 // indirect
k8s.io/client-go v0.29.4 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading
Loading