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