LoginSignup
2
0

More than 1 year has passed since last update.

Dragonfly(dragonflydb)とGrafana,PrometheusでRedis Exporter不要の監視

Last updated at Posted at 2022-10-22

1.はじめに

  • 2022年に発表されたインメモリキャッシュ製品のDragonflyを立ち上げてみます。
    • 箱から出してすぐに動作するGrafana+Prometheusで監視環境も構築します。
    • redisクライアント(golang)から呼び出して動作確認します。

2.Dragonflyとは

2022年に発表されたインメモリキャッシュ製品です。Redisのドロップイン代替品を目指しています。

3.環境構築

grafana,prometheus設定

  • 公式リポジトリからgrafana,prometheus設定を取得する

image.png

compose.yml作成

compose.yml
services:
  dragonfly:
    image: 'docker.dragonflydb.io/dragonflydb/dragonfly'
    container_name: dragonfly
    restart: unless-stopped
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - "6579:6379"
    volumes:
      - dragonfly_data:/data

  prometheus:
    image: prom/prometheus:v2.39.1
    container_name: prometheus_df
    restart: unless-stopped
    command:
      - '--config.file=/etc/prometheus/prometheus.yaml'
    expose:
      - 9090
    configs:
      - source: prometheus
        target: /etc/prometheus/prometheus.yaml
        mode: 440
    volumes:
      - prometheus_data:/prometheus

  grafana:
    image: grafana/grafana:9.2.1
    container_name: grafana_df
    restart: unless-stopped
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=Grafana
      - GF_USERS_DEFAULT_THEME=light
    ports:
      - 9000:3000
    configs:
      - source: grafana-datasource
        target: /etc/grafana/provisioning/datasources/datasource.yaml
        mode: 440
      - source: grafana-dashboard-json
        target: /etc/grafana/provisioning/dashboards/dashboard.json
        mode: 440
      - source: grafana-dashboard-yaml
        target: /etc/grafana/provisioning/dashboards/dashboard.yaml
        mode: 440
    volumes:
      - grafana_data:/var/lib/grafana

configs:
  prometheus:
    # https://github.com/dragonflydb/dragonfly/blob/main/tools/local/monitoring/prometheus/prometheus.yml
    file: ./prometheus/prometheus.yml
  grafana-datasource:
    # https://github.com/dragonflydb/dragonfly/blob/main/tools/local/monitoring/grafana/provisioning/datasources/datasource.yml
    file: ./grafana/datasource.yml
  grafana-dashboard-json:
    # https://github.com/dragonflydb/dragonfly/blob/main/tools/local/monitoring/grafana/provisioning/dashboards/dashboard.json
    file: ./grafana/dashboard.json
  grafana-dashboard-yaml:
    # https://github.com/dragonflydb/dragonfly/blob/main/tools/local/monitoring/grafana/provisioning/dashboards/dashboard.yml
    file: ./grafana/dashboard.yml

volumes:
  dragonfly_data:
  prometheus_data:
  grafana_data:

実行

docker compose up -d

4.テスト実施

main_test.go
package main

import (
	"context"
	"testing"

	"github.com/go-redis/redis/v9"
	"github.com/stretchr/testify/assert"
)

func TestExampleClient(t *testing.T) {

	ctx := context.Background()

	tests := []struct {
		name         string
		key          string
		expected     string
		expected_err error
	}{
		{
			name:         "test",
			key:          "key",
			expected:     "value",
			expected_err: redis.Nil,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(ti *testing.T) {

			rdb := redis.NewClient(&redis.Options{
				Addr:     "localhost:6379",
				Password: "", // no password set
				DB:       0,  // use default DB
			})

			for i := 0; i < 10_000; i++ {
				errB := rdb.Set(ctx, "key", "value", 0).Err()
				assert.NoError(ti, errB, "they should NoError")

				val, err := rdb.Get(ctx, tt.key).Result()
				assert.Equal(ti, val, tt.expected, "they should be equal")
				assert.NoError(ti, err, "they should be ok")

				val, err = rdb.Get(ctx, "will-empty").Result()
				assert.Empty(ti, val, "they should be equal")
				assert.Equal(ti, err, tt.expected_err, "they should be redis.Nil")
				assert.EqualError(ti, err, tt.expected_err.Error(), "they should be redis.Nil")
			}
		})
	}
}

結果

  • テストを通過できた。
  • 性能監視できた。
>go test -timeout 30s -run ^TestExampleClient$ github.com/my/repo
ok  	github.com/my/repo	16.905s

localhost_9009_d_xDLNRKUWz_dragonfly-dashboard_orgId=1&from=now-5m&to=now(pcdisplay).png

参考情報

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0