github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/stats/api.go (about)

     1  // Copyright (c) 2015-2021, NVIDIA CORPORATION.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // Package stats provides a simple statsd client API.
     5  package stats
     6  
     7  type MultipleStat int
     8  
     9  const (
    10  	DirRead                 MultipleStat = iota // uses operations, entries and bytes stats
    11  	FileRead                                    // uses operations, op bucketed bytes, and bytes stats
    12  	FileReadplan                                // uses operations, op bucketed bytes, bytes, and bucketed steps stats
    13  	FileWrite                                   // uses operations, op bucketed bytes, bytes, appended and overwritten stats
    14  	FileWrote                                   // uses operations, op bucketed bytes, and bytes stats
    15  	JrpcfsIoWrite                               // uses operations, op bucketed bytes, and bytes stats
    16  	JrpcfsIoRead                                // uses operations, op bucketed bytes, and bytes stats
    17  	SwiftObjGet                                 // uses operations, op bucketed bytes, and bytes stats
    18  	SwiftObjLoad                                // uses operations, op bucketed bytes, and bytes stats
    19  	SwiftObjRead                                // uses operations, op bucketed bytes, and bytes stats
    20  	SwiftObjTail                                // uses operations and bytes stats
    21  	SwiftObjPutCtxRead                          // uses operations, op bucketed bytes, and bytes stats
    22  	SwiftObjPutCtxSendChunk                     // uses operations, op bucketed bytes, and bytes stats
    23  )
    24  
    25  // Dump returns a map of all accumulated stats since process start.
    26  //
    27  //   Key   is a string containing the name of the stat
    28  //   Value is the accumulation of all increments for the stat since process start
    29  func Dump() (statMap map[string]uint64) {
    30  	statMap = dump()
    31  	return
    32  }
    33  
    34  // IncrementOperations sends an increment of .operations to statsd.
    35  func IncrementOperations(statName *string) {
    36  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    37  	go incrementOperations(statName)
    38  }
    39  
    40  // IncrementOperationsBy sends an increment by <incBy> of .operations to statsd.
    41  func IncrementOperationsBy(statName *string, incBy uint64) {
    42  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    43  	go incrementOperationsBy(statName, incBy)
    44  }
    45  
    46  // IncrementOperationsAndBytes sends an increment of .operations and .bytes to statsd.
    47  func IncrementOperationsAndBytes(stat MultipleStat, bytes uint64) {
    48  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    49  	go incrementOperationsAndBytes(stat, bytes)
    50  }
    51  
    52  // IncrementOperationsEntriesAndBytes sends an increment of .operations, .entries, and .bytes to statsd.
    53  func IncrementOperationsEntriesAndBytes(stat MultipleStat, entries uint64, bytes uint64) {
    54  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    55  	go incrementOperationsEntriesAndBytes(stat, entries, bytes)
    56  }
    57  
    58  // IncrementOperationsAndBucketedBytes sends an increment of .operations, .bytes, and the appropriate .operations.size-* to statsd.
    59  func IncrementOperationsAndBucketedBytes(stat MultipleStat, bytes uint64) {
    60  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    61  	go incrementOperationsAndBucketedBytes(stat, bytes)
    62  }
    63  
    64  // IncrementOperationsBuckedtedBytesAndBucketedSteps sends an increment of .operations, .bytes, and the appropriate .operations.size-* to statsd.
    65  func IncrementOperationsBucketedEntriesAndBucketedBytes(stat MultipleStat, entries uint64, bytes uint64) {
    66  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    67  	go incrementOperationsBucketedEntriesAndBucketedBytes(stat, entries, bytes)
    68  }
    69  
    70  // IncrementOperationsBucketedBytesAndAppendedOverwritten sends an increment of .operations, .bytes, .appended, .overwritten, and the appropriate .operations.size-* to statsd.
    71  func IncrementOperationsBucketedBytesAndAppendedOverwritten(stat MultipleStat, bytes uint64, appended uint64, overwritten uint64) {
    72  	// Do this in a goroutine since channel operations are suprisingly expensive due to locking underneath
    73  	go incrementOperationsBucketedBytesAndAppendedOverwritten(stat, bytes, appended, overwritten)
    74  }