metric_names.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package internal
  2. const (
  3. apdexRollup = "Apdex"
  4. apdexPrefix = "Apdex/"
  5. webRollup = "WebTransaction"
  6. backgroundRollup = "OtherTransaction/all"
  7. errorsPrefix = "Errors/"
  8. // "HttpDispatcher" metric is used for the overview graph, and
  9. // therefore should only be made for web transactions.
  10. dispatcherMetric = "HttpDispatcher"
  11. queueMetric = "WebFrontend/QueueTime"
  12. webMetricPrefix = "WebTransaction/Go"
  13. backgroundMetricPrefix = "OtherTransaction/Go"
  14. instanceReporting = "Instance/Reporting"
  15. // https://newrelic.atlassian.net/wiki/display/eng/Custom+Events+in+New+Relic+Agents
  16. customEventsSeen = "Supportability/Events/Customer/Seen"
  17. customEventsSent = "Supportability/Events/Customer/Sent"
  18. // https://source.datanerd.us/agents/agent-specs/blob/master/Transaction-Events-PORTED.md
  19. txnEventsSeen = "Supportability/AnalyticsEvents/TotalEventsSeen"
  20. txnEventsSent = "Supportability/AnalyticsEvents/TotalEventsSent"
  21. // https://source.datanerd.us/agents/agent-specs/blob/master/Error-Events.md
  22. errorEventsSeen = "Supportability/Events/TransactionError/Seen"
  23. errorEventsSent = "Supportability/Events/TransactionError/Sent"
  24. // https://source.datanerd.us/agents/agent-specs/blob/master/Span-Events.md
  25. spanEventsSeen = "Supportability/SpanEvent/TotalEventsSeen"
  26. spanEventsSent = "Supportability/SpanEvent/TotalEventsSent"
  27. supportabilityDropped = "Supportability/MetricsDropped"
  28. // Runtime/System Metrics
  29. memoryPhysical = "Memory/Physical"
  30. heapObjectsAllocated = "Memory/Heap/AllocatedObjects"
  31. cpuUserUtilization = "CPU/User/Utilization"
  32. cpuSystemUtilization = "CPU/System/Utilization"
  33. cpuUserTime = "CPU/User Time"
  34. cpuSystemTime = "CPU/System Time"
  35. runGoroutine = "Go/Runtime/Goroutines"
  36. gcPauseFraction = "GC/System/Pause Fraction"
  37. gcPauses = "GC/System/Pauses"
  38. // Distributed Tracing Supportability Metrics
  39. supportTracingAcceptSuccess = "Supportability/DistributedTrace/AcceptPayload/Success"
  40. supportTracingAcceptException = "Supportability/DistributedTrace/AcceptPayload/Exception"
  41. supportTracingAcceptParseException = "Supportability/DistributedTrace/AcceptPayload/ParseException"
  42. supportTracingCreateBeforeAccept = "Supportability/DistributedTrace/AcceptPayload/Ignored/CreateBeforeAccept"
  43. supportTracingIgnoredMultiple = "Supportability/DistributedTrace/AcceptPayload/Ignored/Multiple"
  44. supportTracingIgnoredVersion = "Supportability/DistributedTrace/AcceptPayload/Ignored/MajorVersion"
  45. supportTracingAcceptUntrustedAccount = "Supportability/DistributedTrace/AcceptPayload/Ignored/UntrustedAccount"
  46. supportTracingAcceptNull = "Supportability/DistributedTrace/AcceptPayload/Ignored/Null"
  47. supportTracingCreatePayloadSuccess = "Supportability/DistributedTrace/CreatePayload/Success"
  48. supportTracingCreatePayloadException = "Supportability/DistributedTrace/CreatePayload/Exception"
  49. )
  50. // DistributedTracingSupport is used to track distributed tracing activity for
  51. // supportability.
  52. type DistributedTracingSupport struct {
  53. AcceptPayloadSuccess bool // AcceptPayload was called successfully
  54. AcceptPayloadException bool // AcceptPayload had a generic exception
  55. AcceptPayloadParseException bool // AcceptPayload had a parsing exception
  56. AcceptPayloadCreateBeforeAccept bool // AcceptPayload was ignored because CreatePayload had already been called
  57. AcceptPayloadIgnoredMultiple bool // AcceptPayload was ignored because AcceptPayload had already been called
  58. AcceptPayloadIgnoredVersion bool // AcceptPayload was ignored because the payload's major version was greater than the agent's
  59. AcceptPayloadUntrustedAccount bool // AcceptPayload was ignored because the payload was untrusted
  60. AcceptPayloadNullPayload bool // AcceptPayload was ignored because the payload was nil
  61. CreatePayloadSuccess bool // CreatePayload was called successfully
  62. CreatePayloadException bool // CreatePayload had a generic exception
  63. }
  64. type rollupMetric struct {
  65. all string
  66. allWeb string
  67. allOther string
  68. }
  69. func newRollupMetric(s string) rollupMetric {
  70. return rollupMetric{
  71. all: s + "all",
  72. allWeb: s + "allWeb",
  73. allOther: s + "allOther",
  74. }
  75. }
  76. func (r rollupMetric) webOrOther(isWeb bool) string {
  77. if isWeb {
  78. return r.allWeb
  79. }
  80. return r.allOther
  81. }
  82. var (
  83. errorsRollupMetric = newRollupMetric("Errors/")
  84. // source.datanerd.us/agents/agent-specs/blob/master/APIs/external_segment.md
  85. // source.datanerd.us/agents/agent-specs/blob/master/APIs/external_cat.md
  86. // source.datanerd.us/agents/agent-specs/blob/master/Cross-Application-Tracing-PORTED.md
  87. externalRollupMetric = newRollupMetric("External/")
  88. // source.datanerd.us/agents/agent-specs/blob/master/Datastore-Metrics-PORTED.md
  89. datastoreRollupMetric = newRollupMetric("Datastore/")
  90. datastoreProductMetricsCache = map[string]rollupMetric{
  91. "Cassandra": newRollupMetric("Datastore/Cassandra/"),
  92. "Derby": newRollupMetric("Datastore/Derby/"),
  93. "Elasticsearch": newRollupMetric("Datastore/Elasticsearch/"),
  94. "Firebird": newRollupMetric("Datastore/Firebird/"),
  95. "IBMDB2": newRollupMetric("Datastore/IBMDB2/"),
  96. "Informix": newRollupMetric("Datastore/Informix/"),
  97. "Memcached": newRollupMetric("Datastore/Memcached/"),
  98. "MongoDB": newRollupMetric("Datastore/MongoDB/"),
  99. "MySQL": newRollupMetric("Datastore/MySQL/"),
  100. "MSSQL": newRollupMetric("Datastore/MSSQL/"),
  101. "Oracle": newRollupMetric("Datastore/Oracle/"),
  102. "Postgres": newRollupMetric("Datastore/Postgres/"),
  103. "Redis": newRollupMetric("Datastore/Redis/"),
  104. "Solr": newRollupMetric("Datastore/Solr/"),
  105. "SQLite": newRollupMetric("Datastore/SQLite/"),
  106. "CouchDB": newRollupMetric("Datastore/CouchDB/"),
  107. "Riak": newRollupMetric("Datastore/Riak/"),
  108. "VoltDB": newRollupMetric("Datastore/VoltDB/"),
  109. }
  110. )
  111. func customSegmentMetric(s string) string {
  112. return "Custom/" + s
  113. }
  114. // customMetric is used to construct custom metrics from the input given to
  115. // Application.RecordCustomMetric. Note that the "Custom/" prefix helps prevent
  116. // collision with other agent metrics, but does not eliminate the possibility
  117. // since "Custom/" is also used for segments.
  118. func customMetric(customerInput string) string {
  119. return "Custom/" + customerInput
  120. }
  121. // DatastoreMetricKey contains the fields by which datastore metrics are
  122. // aggregated.
  123. type DatastoreMetricKey struct {
  124. Product string
  125. Collection string
  126. Operation string
  127. Host string
  128. PortPathOrID string
  129. }
  130. type externalMetricKey struct {
  131. Host string
  132. ExternalCrossProcessID string
  133. ExternalTransactionName string
  134. }
  135. func datastoreScopedMetric(key DatastoreMetricKey) string {
  136. if "" != key.Collection {
  137. return datastoreStatementMetric(key)
  138. }
  139. return datastoreOperationMetric(key)
  140. }
  141. // Datastore/{datastore}/*
  142. func datastoreProductMetric(key DatastoreMetricKey) rollupMetric {
  143. d, ok := datastoreProductMetricsCache[key.Product]
  144. if ok {
  145. return d
  146. }
  147. return newRollupMetric("Datastore/" + key.Product + "/")
  148. }
  149. // Datastore/operation/{datastore}/{operation}
  150. func datastoreOperationMetric(key DatastoreMetricKey) string {
  151. return "Datastore/operation/" + key.Product +
  152. "/" + key.Operation
  153. }
  154. // Datastore/statement/{datastore}/{table}/{operation}
  155. func datastoreStatementMetric(key DatastoreMetricKey) string {
  156. return "Datastore/statement/" + key.Product +
  157. "/" + key.Collection +
  158. "/" + key.Operation
  159. }
  160. // Datastore/instance/{datastore}/{host}/{port_path_or_id}
  161. func datastoreInstanceMetric(key DatastoreMetricKey) string {
  162. return "Datastore/instance/" + key.Product +
  163. "/" + key.Host +
  164. "/" + key.PortPathOrID
  165. }
  166. // External/{host}/all
  167. func externalHostMetric(key externalMetricKey) string {
  168. return "External/" + key.Host + "/all"
  169. }
  170. // ExternalApp/{host}/{external_id}/all
  171. func externalAppMetric(key externalMetricKey) string {
  172. return "ExternalApp/" + key.Host +
  173. "/" + key.ExternalCrossProcessID + "/all"
  174. }
  175. // ExternalTransaction/{host}/{external_id}/{external_txnname}
  176. func externalTransactionMetric(key externalMetricKey) string {
  177. return "ExternalTransaction/" + key.Host +
  178. "/" + key.ExternalCrossProcessID +
  179. "/" + key.ExternalTransactionName
  180. }
  181. func callerFields(c payloadCaller) string {
  182. return "/" + c.Type +
  183. "/" + c.Account +
  184. "/" + c.App +
  185. "/" + c.TransportType +
  186. "/"
  187. }
  188. // DurationByCaller/{type}/{account}/{app}/{transport}/*
  189. func durationByCallerMetric(c payloadCaller) rollupMetric {
  190. return newRollupMetric("DurationByCaller" + callerFields(c))
  191. }
  192. // ErrorsByCaller/{type}/{account}/{app}/{transport}/*
  193. func errorsByCallerMetric(c payloadCaller) rollupMetric {
  194. return newRollupMetric("ErrorsByCaller" + callerFields(c))
  195. }
  196. // TransportDuration/{type}/{account}/{app}/{transport}/*
  197. func transportDurationMetric(c payloadCaller) rollupMetric {
  198. return newRollupMetric("TransportDuration" + callerFields(c))
  199. }