github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/bulk/bulk_metrics.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package bulk
    12  
    13  import (
    14  	"time"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/util/metric"
    17  )
    18  
    19  // Metrics contains pointers to the metrics for
    20  // monitoring bulk operations.
    21  type Metrics struct {
    22  	MaxBytesHist  *metric.Histogram
    23  	CurBytesCount *metric.Gauge
    24  }
    25  
    26  // MetricStruct implements the metrics.Struct interface.
    27  func (Metrics) MetricStruct() {}
    28  
    29  var _ metric.Struct = Metrics{}
    30  
    31  var (
    32  	metaMemMaxBytes = metric.Metadata{
    33  		Name:        "sql.mem.bulk.max",
    34  		Help:        "Memory usage per sql statement for bulk operations",
    35  		Measurement: "Memory",
    36  		Unit:        metric.Unit_BYTES,
    37  	}
    38  	metaMemCurBytes = metric.Metadata{
    39  		Name:        "sql.mem.bulk.current",
    40  		Help:        "Current sql statement memory usage for bulk operations",
    41  		Measurement: "Memory",
    42  		Unit:        metric.Unit_BYTES,
    43  	}
    44  )
    45  
    46  // See pkg/sql/mem_metrics.go
    47  // log10int64times1000 = log10(math.MaxInt64) * 1000, rounded up somewhat
    48  const log10int64times1000 = 19 * 1000
    49  
    50  // MakeBulkMetrics instantiates the metrics holder for bulk operation monitoring.
    51  func MakeBulkMetrics(histogramWindow time.Duration) Metrics {
    52  	return Metrics{
    53  		MaxBytesHist:  metric.NewHistogram(metaMemMaxBytes, histogramWindow, log10int64times1000, 3),
    54  		CurBytesCount: metric.NewGauge(metaMemCurBytes),
    55  	}
    56  }