Skip to content

Commit

Permalink
store/tikv: add rawkv metrics. (pingcap#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored Dec 13, 2016
1 parent 2c7ca81 commit c7e255e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions store/tikv/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
Subsystem: "tikvclient",
Name: "txn_cmd_seconds",
Help: "Bucketed histogram of processing time of txn cmds.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 18),
}, []string{"type"})

backoffCounter = prometheus.NewCounterVec(
Expand All @@ -65,6 +66,7 @@ var (
Subsystem: "tikvclient",
Name: "backoff_seconds",
Help: "Bucketed histogram of sleep seconds of backoff.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 18),
}, []string{"type"})

sendReqHistogram = prometheus.NewHistogramVec(
Expand All @@ -73,6 +75,7 @@ var (
Subsystem: "tikvclient",
Name: "request_seconds",
Help: "Bucketed histogram of sending request duration.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 18),
}, []string{"type"})

copBuildTaskHistogram = prometheus.NewHistogram(
Expand Down Expand Up @@ -159,6 +162,24 @@ var (
Help: "Size of kv pairs to write in a transaction. (KB)",
Buckets: prometheus.ExponentialBuckets(1, 2, 21),
})

rawkvCmdHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "tikvclient",
Name: "rawkv_cmd_seconds",
Help: "Bucketed histogram of processing time of rawkv cmds.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 18),
}, []string{"type"})

rawkvSizeHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "tikvclient",
Name: "rawkv_kv_size",
Help: "Size of key/value to put, in bytes.",
Buckets: prometheus.ExponentialBuckets(1, 2, 21),
}, []string{"type"})
)

func reportRegionError(e *errorpb.Error) {
Expand Down Expand Up @@ -195,4 +216,6 @@ func init() {
prometheus.MustRegister(regionErrorCounter)
prometheus.MustRegister(txnWriteKVCountHistogram)
prometheus.MustRegister(txnWriteSizeHistogram)
prometheus.MustRegister(rawkvCmdHistogram)
prometheus.MustRegister(rawkvSizeHistogram)
}
13 changes: 13 additions & 0 deletions store/tikv/rawkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package tikv

import (
"time"

"github.com/juju/errors"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/pd/pd-client"
Expand Down Expand Up @@ -49,6 +51,9 @@ func (c *RawKVClient) ClusterID() uint64 {
// Get queries value with the key. When the key does not exist, it returns
// `nil, nil`, while `[]byte{}, nil` means an empty value.
func (c *RawKVClient) Get(key []byte) ([]byte, error) {
start := time.Now()
defer func() { rawkvCmdHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds()) }()

req := &kvrpcpb.Request{
Type: kvrpcpb.MessageType_CmdRawGet,
CmdRawGetReq: &kvrpcpb.CmdRawGetRequest{
Expand All @@ -71,6 +76,11 @@ func (c *RawKVClient) Get(key []byte) ([]byte, error) {

// Put stores a key-value pair to TiKV.
func (c *RawKVClient) Put(key, value []byte) error {
start := time.Now()
defer func() { rawkvCmdHistogram.WithLabelValues("put").Observe(time.Since(start).Seconds()) }()
rawkvSizeHistogram.WithLabelValues("key").Observe(float64(len(key)))
rawkvSizeHistogram.WithLabelValues("value").Observe(float64(len(value)))

req := &kvrpcpb.Request{
Type: kvrpcpb.MessageType_CmdRawPut,
CmdRawPutReq: &kvrpcpb.CmdRawPutRequest{
Expand All @@ -94,6 +104,9 @@ func (c *RawKVClient) Put(key, value []byte) error {

// Delete deletes a key-value pair from TiKV.
func (c *RawKVClient) Delete(key []byte) error {
start := time.Now()
defer func() { rawkvCmdHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds()) }()

req := &kvrpcpb.Request{
Type: kvrpcpb.MessageType_CmdRawDelete,
CmdRawDeleteReq: &kvrpcpb.CmdRawDeleteRequest{
Expand Down

0 comments on commit c7e255e

Please sign in to comment.