Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ethervoid committed Nov 11, 2024
2 parents 60233fd + 8e14bb0 commit 96c8a04
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 118 deletions.
46 changes: 19 additions & 27 deletions .github/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: 2
project_name: kvrocks-exporter
release:
github:
owner: KvrocksLabs
owner: RocksLabs
name: kvrocks_exporter

builds:
Expand All @@ -13,32 +14,23 @@ builds:
- "-X main.BuildCommitSha={{.Commit}}"
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
dockers:
- id: kvrocks-exporter-docker-amd64
goos: linux
goarch: amd64
ids:
- kvrocks-exporter
image_templates:
- "kvrocks/kvrocks-exporter:v{{ .Version }}-amd64"
build_flag_templates:
- "--platform=linux/amd64"
use: buildx
- id: kvrocks-exporter-docker-arm64
goos: linux
goarch: arm64
ids:
- kvrocks-exporter
image_templates:
- "kvrocks/kvrocks-exporter:v{{ .Version }}-arm64"
build_flag_templates:
- "--platform=linux/arm64"
use: buildx
docker_manifests:
- name_template: kvrocks/kvrocks-exporter:v{{ .Version }}
image_templates:
- kvrocks/kvrocks-exporter:v{{ .Version }}-amd64
- kvrocks/kvrocks-exporter:v{{ .Version }}-arm64
kos:
- repository: docker.io/kvrocks/kvrocks-exporter
tags:
- "{{.Version}}"
- latest
preserve_import_paths: false
base_image: alpine:3.20
bare: true
ldflags:
- "-X main.BuildVersion={{ .Version }}"
- "-X main.BuildDate={{.Date}}"
- "-X main.BuildCommitSha={{.Commit}}"
platforms:
- linux/amd64
- linux/arm64
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand All @@ -27,15 +27,15 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -49,4 +49,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
75 changes: 75 additions & 0 deletions .github/workflows/release-binaries-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: goreleaser

on:
pull_request:
push:
# run only against tags
tags:
- "*"

permissions:
contents: write
packages: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Run GoReleaser for build
uses: goreleaser/goreleaser-action@v6
if: success() && !startsWith(github.ref, 'refs/tags/')
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v2"
args: release --snapshot --clean -f ./.github/goreleaser.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
if: success() && startsWith(github.ref, 'refs/tags/')
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub if publishing tag
if: success() && startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: success() && startsWith(github.ref, 'refs/tags/')
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v2"
args: release --clean -f ./.github/goreleaser.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
if: success() && startsWith(github.ref, 'refs/tags/')
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: kvrocks/kvrocks-exporter
short-description: ${{ github.event.repository.description }}

- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: kvrocks_exporter_artifacts_${{ github.run_number }}
path: dist/
29 changes: 0 additions & 29 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ contrib/tls/ca.key
contrib/tls/ca.txt
contrib/tls/redis.crt
contrib/tls/redis.key

dist/
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

22 changes: 7 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,12 @@ upload-coverage:
go install github.com/mattn/[email protected]
/go/bin/goveralls -coverprofile=coverage.txt -service=drone.io

.PHONY: build
build:
go build .

.PHONY: release
release:
go install github.com/goreleaser/goreleaser/v2@latest

BUILD_DT:=$(shell date +%F-%T)
GO_LDFLAGS:="-s -w -extldflags \"-static\" -X main.BuildVersion=${DRONE_TAG} -X main.BuildCommitSha=${DRONE_COMMIT_SHA} -X main.BuildDate=$(BUILD_DT)"

.PHONE: build-binaries
build-binaries:
go get github.com/oliver006/gox@master

rm -rf .build | true

export CGO_ENABLED=0 ; \
gox -os="linux windows freebsd netbsd openbsd" -arch="amd64 386" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os="darwin solaris illumos" -arch="amd64" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os="linux freebsd netbsd" -arch="arm" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os="linux" -arch="arm64 mips64 mips64le ppc64 ppc64le s390x" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
echo "done"
goreleaser release --clean -f .github/goreleaser.yml
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,69 @@ This is a fork of oliver006/redis_exporter to export the kvrocks metrics.
### Build and run locally

```sh
git clone https://github.com/KvrocksLabs/kvrocks_exporter.git
git clone https://github.com/RocksLabs/kvrocks_exporter.git
cd kvrocks_exporter
go build .
./kvrocks_exporter --version
```

### Release

All releases are done via Github Actions. To create a new release, create a new Release + Tag from master.
Actions will automatically add the release artifacts and publish new docker images to Docker hub.

### Arguments

These mostly match the redis exporter but with "redis" replaced with "kvrocks". Please note this includes the protocol version.

```
Usage of ./kvrocks_exporter:
-config-command string
What to use for the CONFIG command (default "CONFIG")
-connection-timeout string
Timeout for connection to Kvrocks instance (default "15s")
-debug
Output verbose debug information
-export-client-port
Whether to include the client's port when exporting the client list. Warning: including the port increases the number of metrics generated and will make your Prometheus server take up more memory
-include-system-metrics
Whether to include system metrics like e.g. kvrocks_total_system_memory_bytes
-is-cluster
Whether this is a Kvrocks cluster (Enable this if you need to fetch key level data on a Kvrocks Cluster).
-kvrocks.addr string
Address of the Kvrocks instance to scrape (default "kvrocks://localhost:6666")
-kvrocks.password string
Password of the Kvrocks instance to scrape
-kvrocks.password-file string
Password file of the Kvrocks instance to scrape
-log-format string
Log format, valid options are txt and json (default "txt")
-namespace string
Namespace for metrics (default "kvrocks")
-ping-on-connect
Whether to ping the Kvrocks instance after connecting
-set-client-name
Whether to set client name to kvrocks_exporter (default true)
-skip-tls-verification
Whether to to skip TLS verification
-tls-ca-cert-file string
Name of the CA certificate file (including full path) if the server requires TLS client authentication
-tls-client-cert-file string
Name of the client certificate file (including full path) if the server requires TLS client authentication
-tls-client-key-file string
Name of the client key file (including full path) if the server requires TLS client authentication
-tls-server-cert-file string
Name of the server certificate file (including full path) if the web interface and telemetry should use TLS
-tls-server-key-file string
Name of the server key file (including full path) if the web interface and telemetry should use TLS
-version
Show version information and exit
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9121")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
```

### Basic Prometheus Configuration

Add a block to the `scrape_configs` of your prometheus.yml config file:
Expand Down
4 changes: 3 additions & 1 deletion exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func NewKvrocksExporter(kvrocksURI string, opts Options) (*Exporter, error) {
"monitor_clients": "monitor_clients",

// # Memory

"used_memory": "memory_used_bytes",
"used_memory_rss": "memory_used_rss_bytes",
"used_memory_lua": "memory_used_lua_bytes",
Expand All @@ -115,6 +114,8 @@ func NewKvrocksExporter(kvrocksURI string, opts Options) (*Exporter, error) {
// # Stats
"pubsub_channels": "pubsub_channels",
"pubsub_patterns": "pubsub_patterns",
"keyspace_hits": "keyspace_hits",
"keyspace_misses": "keyspace_misses",

// # Replication
"connected_slaves": "connected_slaves",
Expand Down Expand Up @@ -186,6 +187,7 @@ func NewKvrocksExporter(kvrocksURI string, opts Options) (*Exporter, error) {
"db_avg_ttl_seconds": {txt: "Avg TTL in seconds", lbls: []string{"db"}},
"db_keys": {txt: "Total number of keys by DB", lbls: []string{"db"}},
"db_keys_expiring": {txt: "Total number of expiring keys by DB", lbls: []string{"db"}},
"db_keys_expired": {txt: "Total number of expired keys by DB", lbls: []string{"db"}},
"exporter_last_scrape_error": {txt: "The last scrape error status.", lbls: []string{"err"}},
"instance_info": {txt: "Information about the kvrocks instance", lbls: []string{"role", "version", "git_sha1", "os", "tcp_port", "gcc_version", "process_id"}},
"last_slow_execution_duration_seconds": {txt: `The amount of time needed for last slow execution, in seconds`},
Expand Down
Loading

0 comments on commit 96c8a04

Please sign in to comment.