|
| 1 | +package mozzle |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + |
| 6 | + cfevent "github.com/cloudfoundry/sonde-go/events" |
| 7 | +) |
| 8 | + |
| 9 | +type containerMetrics struct { |
| 10 | + *cfevent.ContainerMetric |
| 11 | + App application |
| 12 | +} |
| 13 | + |
| 14 | +func (m containerMetrics) EmitTo(e Emitter) { |
| 15 | + attributes := attributes(m.App) |
| 16 | + attributes["instance"] = strconv.Itoa(int(m.GetInstanceIndex())) |
| 17 | + |
| 18 | + e.Emit(forApp(m.App, Metric{ |
| 19 | + Service: "memory used_bytes", |
| 20 | + Metric: int(m.GetMemoryBytes()), |
| 21 | + State: "ok", |
| 22 | + Attributes: attributes, |
| 23 | + })) |
| 24 | + e.Emit(forApp(m.App, Metric{ |
| 25 | + Service: "memory total_bytes", |
| 26 | + Metric: int(m.GetMemoryBytesQuota()), |
| 27 | + State: "ok", |
| 28 | + Attributes: attributes, |
| 29 | + })) |
| 30 | + e.Emit(forApp(m.App, Metric{ |
| 31 | + Service: "memory used_ratio", |
| 32 | + Metric: ratio(m.GetMemoryBytes(), m.GetMemoryBytesQuota()), |
| 33 | + State: "ok", |
| 34 | + Attributes: attributes, |
| 35 | + })) |
| 36 | + |
| 37 | + e.Emit(forApp(m.App, Metric{ |
| 38 | + Service: "disk used_bytes", |
| 39 | + Metric: int(m.GetDiskBytes()), |
| 40 | + State: "ok", |
| 41 | + Attributes: attributes, |
| 42 | + })) |
| 43 | + e.Emit(forApp(m.App, Metric{ |
| 44 | + Service: "disk total_bytes", |
| 45 | + Metric: int(m.GetDiskBytesQuota()), |
| 46 | + State: "ok", |
| 47 | + Attributes: attributes, |
| 48 | + })) |
| 49 | + e.Emit(forApp(m.App, Metric{ |
| 50 | + Service: "disk used_ratio", |
| 51 | + Metric: ratio(m.GetDiskBytes(), m.GetDiskBytesQuota()), |
| 52 | + State: "ok", |
| 53 | + Attributes: attributes, |
| 54 | + })) |
| 55 | + |
| 56 | + e.Emit(forApp(m.App, Metric{ |
| 57 | + Service: "cpu_percent", |
| 58 | + Metric: m.GetCpuPercentage(), |
| 59 | + State: "ok", |
| 60 | + Attributes: attributes, |
| 61 | + })) |
| 62 | +} |
0 commit comments