github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/stats/api.go (about)

     1  // Package stats provides methods and functionality to register, track, log,
     2  // and StatsD-notify statistics that, for the most part, include "counter" and "latency" kinds.
     3  /*
     4   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package stats
     7  
     8  import (
     9  	"strings"
    10  
    11  	"github.com/NVIDIA/aistore/api/apc"
    12  	"github.com/NVIDIA/aistore/cmn/cifl"
    13  	"github.com/NVIDIA/aistore/cmn/cos"
    14  	"github.com/NVIDIA/aistore/core"
    15  	"github.com/NVIDIA/aistore/core/meta"
    16  	"github.com/NVIDIA/aistore/fs"
    17  )
    18  
    19  // enum: `statsValue` kinds
    20  const (
    21  	// lockless
    22  	KindCounter            = "counter"
    23  	KindSize               = "size"
    24  	KindGauge              = "gauge"
    25  	KindSpecial            = "special"
    26  	KindComputedThroughput = "compbw" // disk read/write throughput
    27  	// compound (+ semantics)
    28  	KindLatency    = "latency"
    29  	KindThroughput = "bw" // e.g. GetThroughput
    30  )
    31  
    32  const errPrefix = "err." // all error metric names (see `IsErrMetric` below)
    33  
    34  type (
    35  	Tracker interface {
    36  		cos.StatsUpdater
    37  
    38  		StartedUp() bool
    39  		IsPrometheus() bool
    40  
    41  		IncErr(metric string)
    42  
    43  		GetStats() *Node
    44  		GetStatsV322() *NodeV322 // [backward compatibility]
    45  
    46  		ResetStats(errorsOnly bool)
    47  		GetMetricNames() cos.StrKVs // (name, kind) pairs
    48  
    49  		RegMetrics(node *meta.Snode) // + init Prometheus, if configured
    50  	}
    51  
    52  	// REST API
    53  	Node struct {
    54  		Snode     *meta.Snode  `json:"snode"`
    55  		Tracker   copyTracker  `json:"tracker"`
    56  		TargetCDF fs.TargetCDF `json:"capacity"`
    57  	}
    58  	Cluster struct {
    59  		Proxy  *Node            `json:"proxy"`
    60  		Target map[string]*Node `json:"target"`
    61  	}
    62  	ClusterRaw struct {
    63  		Proxy  *Node           `json:"proxy"`
    64  		Target cos.JSONRawMsgs `json:"target"`
    65  	}
    66  
    67  	// (includes stats.Node and more; NOTE: direct API call w/ no proxying)
    68  	NodeStatus struct {
    69  		Node
    70  		Cluster cifl.Info
    71  		RebSnap *core.Snap `json:"rebalance_snap,omitempty"`
    72  		// assorted props
    73  		Status         string         `json:"status"`
    74  		DeploymentType string         `json:"deployment"`
    75  		Version        string         `json:"ais_version"`  // major.minor.build
    76  		BuildTime      string         `json:"build_time"`   // YYYY-MM-DD HH:MM:SS-TZ
    77  		K8sPodName     string         `json:"k8s_pod_name"` // (via ais-k8s/operator `MY_POD` env var)
    78  		Reserved1      string         `json:"reserved1,omitempty"`
    79  		Reserved2      string         `json:"reserved2,omitempty"`
    80  		MemCPUInfo     apc.MemCPUInfo `json:"sys_info"`
    81  		SmapVersion    int64          `json:"smap_version,string"`
    82  		Reserved3      int64          `json:"reserved3,omitempty"`
    83  		Reserved4      int64          `json:"reserved4,omitempty"`
    84  	}
    85  )
    86  
    87  // [backward compatibility]: includes v3.22 cdf* structures
    88  type (
    89  	NodeV322 struct {
    90  		Snode     *meta.Snode      `json:"snode"`
    91  		Tracker   copyTracker      `json:"tracker"`
    92  		TargetCDF fs.TargetCDFv322 `json:"capacity"`
    93  	}
    94  	NodeStatusV322 struct {
    95  		NodeV322
    96  		RebSnap *core.Snap `json:"rebalance_snap,omitempty"`
    97  		// assorted props
    98  		Status         string         `json:"status"`
    99  		DeploymentType string         `json:"deployment"`
   100  		Version        string         `json:"ais_version"`  // major.minor.build
   101  		BuildTime      string         `json:"build_time"`   // YYYY-MM-DD HH:MM:SS-TZ
   102  		K8sPodName     string         `json:"k8s_pod_name"` // (via ais-k8s/operator `MY_POD` env var)
   103  		MemCPUInfo     apc.MemCPUInfo `json:"sys_info"`
   104  		SmapVersion    int64          `json:"smap_version,string"`
   105  	}
   106  )
   107  
   108  func IsErrMetric(name string) bool {
   109  	return strings.HasPrefix(name, errPrefix) // e.g. name = ErrHTTPWriteCount
   110  }