github.com/newrelic/go-agent@v3.26.0+incompatible/internal/metric_names.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package internal
     5  
     6  const (
     7  	apdexRollup = "Apdex"
     8  	apdexPrefix = "Apdex/"
     9  
    10  	webRollup        = "WebTransaction"
    11  	backgroundRollup = "OtherTransaction/all"
    12  
    13  	// https://source.datanerd.us/agents/agent-specs/blob/master/Total-Time-Async.md
    14  	totalTimeWeb        = "WebTransactionTotalTime"
    15  	totalTimeBackground = "OtherTransactionTotalTime"
    16  
    17  	errorsPrefix = "Errors/"
    18  
    19  	// "HttpDispatcher" metric is used for the overview graph, and
    20  	// therefore should only be made for web transactions.
    21  	dispatcherMetric = "HttpDispatcher"
    22  
    23  	queueMetric = "WebFrontend/QueueTime"
    24  
    25  	webMetricPrefix        = "WebTransaction/Go"
    26  	backgroundMetricPrefix = "OtherTransaction/Go"
    27  
    28  	instanceReporting = "Instance/Reporting"
    29  
    30  	// https://newrelic.atlassian.net/wiki/display/eng/Custom+Events+in+New+Relic+Agents
    31  	customEventsSeen = "Supportability/Events/Customer/Seen"
    32  	customEventsSent = "Supportability/Events/Customer/Sent"
    33  
    34  	// https://source.datanerd.us/agents/agent-specs/blob/master/Transaction-Events-PORTED.md
    35  	txnEventsSeen = "Supportability/AnalyticsEvents/TotalEventsSeen"
    36  	txnEventsSent = "Supportability/AnalyticsEvents/TotalEventsSent"
    37  
    38  	// https://source.datanerd.us/agents/agent-specs/blob/master/Error-Events.md
    39  	errorEventsSeen = "Supportability/Events/TransactionError/Seen"
    40  	errorEventsSent = "Supportability/Events/TransactionError/Sent"
    41  
    42  	// https://source.datanerd.us/agents/agent-specs/blob/master/Span-Events.md
    43  	spanEventsSeen = "Supportability/SpanEvent/TotalEventsSeen"
    44  	spanEventsSent = "Supportability/SpanEvent/TotalEventsSent"
    45  
    46  	supportabilityDropped = "Supportability/MetricsDropped"
    47  
    48  	// Runtime/System Metrics
    49  	memoryPhysical       = "Memory/Physical"
    50  	heapObjectsAllocated = "Memory/Heap/AllocatedObjects"
    51  	cpuUserUtilization   = "CPU/User/Utilization"
    52  	cpuSystemUtilization = "CPU/System/Utilization"
    53  	cpuUserTime          = "CPU/User Time"
    54  	cpuSystemTime        = "CPU/System Time"
    55  	runGoroutine         = "Go/Runtime/Goroutines"
    56  	gcPauseFraction      = "GC/System/Pause Fraction"
    57  	gcPauses             = "GC/System/Pauses"
    58  
    59  	// Distributed Tracing Supportability Metrics
    60  	supportTracingAcceptSuccess          = "Supportability/DistributedTrace/AcceptPayload/Success"
    61  	supportTracingAcceptException        = "Supportability/DistributedTrace/AcceptPayload/Exception"
    62  	supportTracingAcceptParseException   = "Supportability/DistributedTrace/AcceptPayload/ParseException"
    63  	supportTracingCreateBeforeAccept     = "Supportability/DistributedTrace/AcceptPayload/Ignored/CreateBeforeAccept"
    64  	supportTracingIgnoredMultiple        = "Supportability/DistributedTrace/AcceptPayload/Ignored/Multiple"
    65  	supportTracingIgnoredVersion         = "Supportability/DistributedTrace/AcceptPayload/Ignored/MajorVersion"
    66  	supportTracingAcceptUntrustedAccount = "Supportability/DistributedTrace/AcceptPayload/Ignored/UntrustedAccount"
    67  	supportTracingAcceptNull             = "Supportability/DistributedTrace/AcceptPayload/Ignored/Null"
    68  	supportTracingCreatePayloadSuccess   = "Supportability/DistributedTrace/CreatePayload/Success"
    69  	supportTracingCreatePayloadException = "Supportability/DistributedTrace/CreatePayload/Exception"
    70  
    71  	// Configurable event harvest supportability metrics
    72  	supportReportPeriod     = "Supportability/EventHarvest/ReportPeriod"
    73  	supportTxnEventLimit    = "Supportability/EventHarvest/AnalyticEventData/HarvestLimit"
    74  	supportCustomEventLimit = "Supportability/EventHarvest/CustomEventData/HarvestLimit"
    75  	supportErrorEventLimit  = "Supportability/EventHarvest/ErrorEventData/HarvestLimit"
    76  	supportSpanEventLimit   = "Supportability/EventHarvest/SpanEventData/HarvestLimit"
    77  )
    78  
    79  // DistributedTracingSupport is used to track distributed tracing activity for
    80  // supportability.
    81  type DistributedTracingSupport struct {
    82  	AcceptPayloadSuccess            bool // AcceptPayload was called successfully
    83  	AcceptPayloadException          bool // AcceptPayload had a generic exception
    84  	AcceptPayloadParseException     bool // AcceptPayload had a parsing exception
    85  	AcceptPayloadCreateBeforeAccept bool // AcceptPayload was ignored because CreatePayload had already been called
    86  	AcceptPayloadIgnoredMultiple    bool // AcceptPayload was ignored because AcceptPayload had already been called
    87  	AcceptPayloadIgnoredVersion     bool // AcceptPayload was ignored because the payload's major version was greater than the agent's
    88  	AcceptPayloadUntrustedAccount   bool // AcceptPayload was ignored because the payload was untrusted
    89  	AcceptPayloadNullPayload        bool // AcceptPayload was ignored because the payload was nil
    90  	CreatePayloadSuccess            bool // CreatePayload was called successfully
    91  	CreatePayloadException          bool // CreatePayload had a generic exception
    92  }
    93  
    94  type rollupMetric struct {
    95  	all      string
    96  	allWeb   string
    97  	allOther string
    98  }
    99  
   100  func newRollupMetric(s string) rollupMetric {
   101  	return rollupMetric{
   102  		all:      s + "all",
   103  		allWeb:   s + "allWeb",
   104  		allOther: s + "allOther",
   105  	}
   106  }
   107  
   108  func (r rollupMetric) webOrOther(isWeb bool) string {
   109  	if isWeb {
   110  		return r.allWeb
   111  	}
   112  	return r.allOther
   113  }
   114  
   115  var (
   116  	errorsRollupMetric = newRollupMetric("Errors/")
   117  
   118  	// source.datanerd.us/agents/agent-specs/blob/master/APIs/external_segment.md
   119  	// source.datanerd.us/agents/agent-specs/blob/master/APIs/external_cat.md
   120  	// source.datanerd.us/agents/agent-specs/blob/master/Cross-Application-Tracing-PORTED.md
   121  	externalRollupMetric = newRollupMetric("External/")
   122  
   123  	// source.datanerd.us/agents/agent-specs/blob/master/Datastore-Metrics-PORTED.md
   124  	datastoreRollupMetric = newRollupMetric("Datastore/")
   125  
   126  	datastoreProductMetricsCache = map[string]rollupMetric{
   127  		"Cassandra":     newRollupMetric("Datastore/Cassandra/"),
   128  		"Derby":         newRollupMetric("Datastore/Derby/"),
   129  		"Elasticsearch": newRollupMetric("Datastore/Elasticsearch/"),
   130  		"Firebird":      newRollupMetric("Datastore/Firebird/"),
   131  		"IBMDB2":        newRollupMetric("Datastore/IBMDB2/"),
   132  		"Informix":      newRollupMetric("Datastore/Informix/"),
   133  		"Memcached":     newRollupMetric("Datastore/Memcached/"),
   134  		"MongoDB":       newRollupMetric("Datastore/MongoDB/"),
   135  		"MySQL":         newRollupMetric("Datastore/MySQL/"),
   136  		"MSSQL":         newRollupMetric("Datastore/MSSQL/"),
   137  		"Oracle":        newRollupMetric("Datastore/Oracle/"),
   138  		"Postgres":      newRollupMetric("Datastore/Postgres/"),
   139  		"Redis":         newRollupMetric("Datastore/Redis/"),
   140  		"Solr":          newRollupMetric("Datastore/Solr/"),
   141  		"SQLite":        newRollupMetric("Datastore/SQLite/"),
   142  		"CouchDB":       newRollupMetric("Datastore/CouchDB/"),
   143  		"Riak":          newRollupMetric("Datastore/Riak/"),
   144  		"VoltDB":        newRollupMetric("Datastore/VoltDB/"),
   145  	}
   146  )
   147  
   148  func customSegmentMetric(s string) string {
   149  	return "Custom/" + s
   150  }
   151  
   152  // customMetric is used to construct custom metrics from the input given to
   153  // Application.RecordCustomMetric.  Note that the "Custom/" prefix helps prevent
   154  // collision with other agent metrics, but does not eliminate the possibility
   155  // since "Custom/" is also used for segments.
   156  func customMetric(customerInput string) string {
   157  	return "Custom/" + customerInput
   158  }
   159  
   160  // DatastoreMetricKey contains the fields by which datastore metrics are
   161  // aggregated.
   162  type DatastoreMetricKey struct {
   163  	Product      string
   164  	Collection   string
   165  	Operation    string
   166  	Host         string
   167  	PortPathOrID string
   168  }
   169  
   170  type externalMetricKey struct {
   171  	Host                    string
   172  	Library                 string
   173  	Method                  string
   174  	ExternalCrossProcessID  string
   175  	ExternalTransactionName string
   176  }
   177  
   178  // MessageMetricKey is the key to use for message segments.
   179  type MessageMetricKey struct {
   180  	Library         string
   181  	DestinationType string
   182  	Consumer        bool
   183  	DestinationName string
   184  	DestinationTemp bool
   185  }
   186  
   187  // Name returns the metric name value for this MessageMetricKey to be used for
   188  // scoped and unscoped metrics.
   189  //
   190  // Producers
   191  // MessageBroker/{Library}/{Destination Type}/{Action}/Named/{Destination Name}
   192  // MessageBroker/{Library}/{Destination Type}/{Action}/Temp
   193  //
   194  // Consumers
   195  // OtherTransaction/Message/{Library}/{DestinationType}/Named/{Destination Name}
   196  // OtherTransaction/Message/{Library}/{DestinationType}/Temp
   197  func (key MessageMetricKey) Name() string {
   198  	var destination string
   199  	if key.DestinationTemp {
   200  		destination = "Temp"
   201  	} else if key.DestinationName == "" {
   202  		destination = "Named/Unknown"
   203  	} else {
   204  		destination = "Named/" + key.DestinationName
   205  	}
   206  
   207  	if key.Consumer {
   208  		return "Message/" + key.Library +
   209  			"/" + key.DestinationType +
   210  			"/" + destination
   211  	}
   212  	return "MessageBroker/" + key.Library +
   213  		"/" + key.DestinationType +
   214  		"/Produce/" + destination
   215  }
   216  
   217  func datastoreScopedMetric(key DatastoreMetricKey) string {
   218  	if "" != key.Collection {
   219  		return datastoreStatementMetric(key)
   220  	}
   221  	return datastoreOperationMetric(key)
   222  }
   223  
   224  // Datastore/{datastore}/*
   225  func datastoreProductMetric(key DatastoreMetricKey) rollupMetric {
   226  	d, ok := datastoreProductMetricsCache[key.Product]
   227  	if ok {
   228  		return d
   229  	}
   230  	return newRollupMetric("Datastore/" + key.Product + "/")
   231  }
   232  
   233  // Datastore/operation/{datastore}/{operation}
   234  func datastoreOperationMetric(key DatastoreMetricKey) string {
   235  	return "Datastore/operation/" + key.Product +
   236  		"/" + key.Operation
   237  }
   238  
   239  // Datastore/statement/{datastore}/{table}/{operation}
   240  func datastoreStatementMetric(key DatastoreMetricKey) string {
   241  	return "Datastore/statement/" + key.Product +
   242  		"/" + key.Collection +
   243  		"/" + key.Operation
   244  }
   245  
   246  // Datastore/instance/{datastore}/{host}/{port_path_or_id}
   247  func datastoreInstanceMetric(key DatastoreMetricKey) string {
   248  	return "Datastore/instance/" + key.Product +
   249  		"/" + key.Host +
   250  		"/" + key.PortPathOrID
   251  }
   252  
   253  func (key externalMetricKey) scopedMetric() string {
   254  	if "" != key.ExternalCrossProcessID && "" != key.ExternalTransactionName {
   255  		return externalTransactionMetric(key)
   256  	}
   257  
   258  	if key.Method == "" {
   259  		// External/{host}/{library}
   260  		return "External/" + key.Host + "/" + key.Library
   261  	}
   262  	// External/{host}/{library}/{method}
   263  	return "External/" + key.Host + "/" + key.Library + "/" + key.Method
   264  }
   265  
   266  // External/{host}/all
   267  func externalHostMetric(key externalMetricKey) string {
   268  	return "External/" + key.Host + "/all"
   269  }
   270  
   271  // ExternalApp/{host}/{external_id}/all
   272  func externalAppMetric(key externalMetricKey) string {
   273  	return "ExternalApp/" + key.Host +
   274  		"/" + key.ExternalCrossProcessID + "/all"
   275  }
   276  
   277  // ExternalTransaction/{host}/{external_id}/{external_txnname}
   278  func externalTransactionMetric(key externalMetricKey) string {
   279  	return "ExternalTransaction/" + key.Host +
   280  		"/" + key.ExternalCrossProcessID +
   281  		"/" + key.ExternalTransactionName
   282  }
   283  
   284  func callerFields(c payloadCaller) string {
   285  	return "/" + c.Type +
   286  		"/" + c.Account +
   287  		"/" + c.App +
   288  		"/" + c.TransportType +
   289  		"/"
   290  }
   291  
   292  // DurationByCaller/{type}/{account}/{app}/{transport}/*
   293  func durationByCallerMetric(c payloadCaller) rollupMetric {
   294  	return newRollupMetric("DurationByCaller" + callerFields(c))
   295  }
   296  
   297  // ErrorsByCaller/{type}/{account}/{app}/{transport}/*
   298  func errorsByCallerMetric(c payloadCaller) rollupMetric {
   299  	return newRollupMetric("ErrorsByCaller" + callerFields(c))
   300  }
   301  
   302  // TransportDuration/{type}/{account}/{app}/{transport}/*
   303  func transportDurationMetric(c payloadCaller) rollupMetric {
   304  	return newRollupMetric("TransportDuration" + callerFields(c))
   305  }