forked from newrelic/newrelic-pcf-nozzle-tile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.go
73 lines (60 loc) · 1.94 KB
/
value.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
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package value
import (
"context"
"code.cloudfoundry.org/go-loggregator/rpc/loggregator_v2"
"github.com/newrelic/newrelic-pcf-nozzle-tile/app"
"github.com/newrelic/newrelic-pcf-nozzle-tile/config"
"github.com/newrelic/newrelic-pcf-nozzle-tile/newrelic/accumulators"
"github.com/newrelic/newrelic-pcf-nozzle-tile/newrelic/entities"
"github.com/newrelic/newrelic-pcf-nozzle-tile/newrelic/metrics"
"github.com/newrelic/newrelic-pcf-nozzle-tile/newrelic/nrclients"
"github.com/newrelic/newrelic-pcf-nozzle-tile/newrelic/nrpcf"
)
// Metrics extends metric.Accumulator for
// Firehose ContainerMetric Envelope Event Types
type Metrics struct {
accumulators.Accumulator
}
// New satisfies metric.Accumulator
func (m Metrics) New() accumulators.Interface {
i := Metrics{
Accumulator: accumulators.NewAccumulator(
// Does not match a v2 envelope type, but router will send appropriate envelopes here.
"ValueMetric",
),
}
return i
}
// Update satisfies metric.Accumulator
func (m Metrics) Update(e *loggregator_v2.Envelope) {
ent := m.GetEntity(e, nrpcf.GetPCFAttributes(e))
g := e.GetGauge()
// A single v2 envelope can contain multiple metrics.
for key, met := range g.Metrics {
ent.
NewSample(
key,
metrics.Types.Gauge,
met.GetUnit(),
met.GetValue(),
).
Done()
}
}
// HarvestMetrics ...
func (m Metrics) HarvestMetrics(
entity *entities.Entity,
metric *metrics.Metric,
) {
metric.SetAttribute(
"eventType",
m.Config().GetString(config.NewRelicEventTypeValueMetric),
)
metric.SetAttribute("agent.subscription", m.Config().GetString("FIREHOSE_ID"))
metric.Attributes().AppendAll(entity.Attributes())
// Get a client with the insert key and RPM account ID from the config.
client := nrclients.New().GetEventClient(app.Get().Config.GetNewRelicConfig())
client.EnqueueEvent(context.Background(), metric.Marshal())
}