Skip to content

Commit c9bbb33

Browse files
authored
Finish out each Reporter impl (#69)
* finish impl of space report, remove spaceRefs from org reporter for time being * finish out org report interface impl * name of summary report can be a big ol bytebuffer of orgs aggregated together. Maybe can be fixed later * finish out impl of summary report * README example should remove percentage memory used
1 parent 3858fea commit c9bbb33

File tree

4 files changed

+111
-50
lines changed

4 files changed

+111
-50
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ cf usage-report -o voyager -o tenzing --format table
3737

3838
```txt
3939
org voyager is consuming 60416 MB of 83968 MB
40-
space dev is consuming 25600 MB memory (30%) of org quota
40+
space dev is consuming 25600 MB memory of org quota
4141
AIs billable: 20
4242
AIs canonical: 18 (13 running, 5 stopped)
4343
SCS instances: 2
44-
space test is consuming 34816 MB memory (41%) of org quota
44+
space test is consuming 34816 MB memory of org quota
4545
AIs billable: 20
4646
AIs canonical: 19 (17 running, 2 stopped)
4747
SCS instances: 1
4848
org tenzing is consuming 0 MB of 83968 MB
49-
space dev is consuming 0 MB memory (0%) of org quota
49+
space dev is consuming 0 MB memory of org quota
5050
AIs billable: 2
5151
AIs canonical: 0 (0 running, 0 stopped)
5252
SCS instances: 2
53-
space test is consuming 0 MB memory (0%) of org quota
53+
space test is consuming 0 MB memory of org quota
5454
AIs billable: 2
5555
AIs canonical: 0 (0 running, 0 stopped)
5656
SCS instances: 2
57-
space integration is consuming 0 MB memory (0%) of org quota
57+
space integration is consuming 0 MB memory of org quota
5858
AIs billable: 1
5959
AIs canonical: 0 (0 running, 0 stopped)
6060
SCS instances: 1

models/org_report.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type OrgReporter interface {
1010
type OrgReport struct {
1111
orgRef Org
1212
spaceReportsRef []SpaceReporter
13-
// spacesRef []Space
1413
}
1514

1615
// NewOrgReport -
@@ -23,10 +22,10 @@ func NewOrgReport(org Org) *OrgReport {
2322
return &OrgReport{
2423
orgRef: org,
2524
spaceReportsRef: spaceReports,
26-
// spacesRef: org.Spaces,
2725
}
2826
}
2927

28+
// SpaceReports -
3029
func (o *OrgReport) SpaceReports() []SpaceReporter {
3130
return o.spaceReportsRef
3231
}
@@ -52,7 +51,6 @@ func (o *OrgReport) AppsCount() int {
5251
// MemoryQuota -
5352
func (o *OrgReport) MemoryQuota() int {
5453
return o.orgRef.MemoryQuota
55-
5654
}
5755

5856
// MemoryUsage -
@@ -102,24 +100,22 @@ func (o *OrgReport) ServicesSuiteForPivotalPlatformCount() int {
102100

103101
}
104102

105-
// StoppedAppInstancesCount - TODO
103+
// StoppedAppInstancesCount -
106104
func (o *OrgReport) StoppedAppInstancesCount() int {
107-
// count := 0
108-
// for _, space := range o.spaceReportsRef {
109-
// count += space.ServicesSuiteForPivotalPlatformCount()
110-
// }
111-
// return count
112-
return 0
105+
count := 0
106+
for _, space := range o.spaceReportsRef {
107+
count += space.StoppedAppInstancesCount()
108+
}
109+
return count
113110
}
114111

115-
// StoppedAppsCount - TODO
112+
// StoppedAppsCount -
116113
func (o *OrgReport) StoppedAppsCount() int {
117-
// count := 0
118-
// for _, space := range o.spaceReportsRef {
119-
// count += space.ServicesSuiteForPivotalPlatformCount()
120-
// }
121-
// return count
122-
return 0
114+
count := 0
115+
for _, space := range o.spaceReportsRef {
116+
count += space.StoppedAppsCount()
117+
}
118+
return count
123119
}
124120

125121
// SpringCloudServicesCount -

models/space_report.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (s *SpaceReport) ServicesSuiteForPivotalPlatformCount() int {
5353
return count
5454
}
5555

56+
// Name -
5657
func (s *SpaceReport) Name() string {
5758
return s.spaceRef.Name
5859
}
@@ -88,9 +89,9 @@ func (s *SpaceReport) BillableAppInstancesCount() int {
8889
return count
8990
}
9091

91-
// ConsumedMemory returns the amount of memory consumed by all
92+
// MemoryUsage returns the amount of memory consumed by all
9293
// running canonical application instances within a space
93-
func (s *SpaceReport) ConsumedMemory() int {
94+
func (s *SpaceReport) MemoryUsage() int {
9495
count := 0
9596
for _, app := range s.spaceRef.Apps {
9697
count += int(app.RunningInstances * app.Memory)
@@ -139,18 +140,17 @@ func (s *SpaceReport) ServicesCount() int {
139140
return count
140141
}
141142

143+
// MemoryQuota - TODO unimplemented on 'space' level
142144
func (s *SpaceReport) MemoryQuota() int {
143-
return 0
144-
}
145-
146-
func (s *SpaceReport) MemoryUsage() int {
147-
return 0
145+
return -1
148146
}
149147

148+
// StoppedAppInstancesCount -
150149
func (s *SpaceReport) StoppedAppInstancesCount() int {
151-
return 0
150+
return s.AppInstancesCount() - s.RunningAppInstancesCount()
152151
}
153152

153+
// StoppedAppsCount -
154154
func (s *SpaceReport) StoppedAppsCount() int {
155-
return 0
155+
return s.AppsCount() - s.RunningAppsCount()
156156
}

models/summary_report.go

+84-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package models
22

3+
import "bytes"
4+
35
// SummaryReporter -
46
type SummaryReporter interface {
57
OrgReports() []OrgReporter
@@ -8,8 +10,8 @@ type SummaryReporter interface {
810

911
// SummaryReport holds an aggregated view of multiple OrgReports
1012
type SummaryReport struct {
11-
orgsRef []Org
1213
orgReportsRef []OrgReporter
14+
orgsRef []Org
1315
}
1416

1517
// NewSummaryReport -
@@ -25,8 +27,18 @@ func NewSummaryReport(orgs []Org) *SummaryReport {
2527
}
2628
}
2729

30+
// OrgReports -
31+
func (s *SummaryReport) OrgReports() []OrgReporter {
32+
return s.orgReportsRef
33+
}
34+
35+
// Name -
2836
func (s *SummaryReport) Name() string {
29-
return "nil"
37+
var name bytes.Buffer
38+
for _, org := range s.orgReportsRef {
39+
name.WriteString(org.Name())
40+
}
41+
return name.String()
3042
}
3143

3244
// ServicesSuiteForPivotalPlatformCount returns the number of service instances
@@ -35,11 +47,11 @@ func (s *SummaryReport) Name() string {
3547
// see: https://network.pivotal.io/products/pcf-services
3648
// (I know right? It's an intense function name)
3749
func (s *SummaryReport) ServicesSuiteForPivotalPlatformCount() int {
38-
return 0
39-
}
40-
41-
func (s *SummaryReport) OrgReports() []OrgReporter {
42-
return s.orgReportsRef
50+
count := 0
51+
for _, report := range s.orgReportsRef {
52+
count += report.ServicesSuiteForPivotalPlatformCount()
53+
}
54+
return count
4355
}
4456

4557
// AppInstancesCount returns the count of declared canonical app instances
@@ -53,7 +65,11 @@ func (s *SummaryReport) OrgReports() []OrgReporter {
5365
//
5466
// then you'd have "5 app instances"
5567
func (s *SummaryReport) AppInstancesCount() int {
56-
return 0
68+
count := 0
69+
for _, report := range s.orgReportsRef {
70+
count += report.AppInstancesCount()
71+
}
72+
return count
5773
}
5874

5975
// AppsCount returns the count of unique canonical app guids
@@ -67,31 +83,53 @@ func (s *SummaryReport) AppInstancesCount() int {
6783
//
6884
// then you'd have "3 unique apps"
6985
func (s *SummaryReport) AppsCount() int {
70-
return 0
86+
count := 0
87+
for _, report := range s.orgReportsRef {
88+
count += report.AppsCount()
89+
}
90+
return count
7191
}
7292

7393
// BillableAppInstancesCount returns the count of "billable" AIs
7494
//
7595
// This includes anything which Pivotal deems "billable" as an AI, even if CF
7696
// considers it a service; e.g., SCS instances (config server, service registry, etc.)
7797
func (s *SummaryReport) BillableAppInstancesCount() int {
78-
return 0
98+
count := 0
99+
for _, report := range s.orgReportsRef {
100+
count += report.BillableAppInstancesCount()
101+
}
102+
return count
79103
}
80104

81105
// BillableServicesCount returns the count of "billable" SIs
82106
//
83107
// This includes anything which Pivotal deems "billable" as an SI; this might mean
84108
// subtracting certain services (like SCS) from the count of `cf services`
85109
func (s *SummaryReport) BillableServicesCount() int {
86-
return 0
110+
count := 0
111+
for _, report := range s.orgReportsRef {
112+
count += report.BillableServicesCount()
113+
}
114+
return count
87115
}
88116

117+
// MemoryQuota -
89118
func (s *SummaryReport) MemoryQuota() int {
90-
return 0
119+
count := 0
120+
for _, report := range s.orgReportsRef {
121+
count += report.MemoryQuota()
122+
}
123+
return count
91124
}
92125

126+
// MemoryUsage -
93127
func (s *SummaryReport) MemoryUsage() int {
94-
return 0
128+
count := 0
129+
for _, report := range s.orgReportsRef {
130+
count += report.MemoryUsage()
131+
}
132+
return count
95133
}
96134

97135
// RunningAppInstancesCount returns the count of declared canonical app instances
@@ -105,7 +143,11 @@ func (s *SummaryReport) MemoryUsage() int {
105143
//
106144
// then you'd have "4 running app instances"
107145
func (s *SummaryReport) RunningAppInstancesCount() int {
108-
return 0
146+
count := 0
147+
for _, report := range s.orgReportsRef {
148+
count += report.RunningAppInstancesCount()
149+
}
150+
return count
109151
}
110152

111153
// RunningAppsCount returns the count of unique canonical app
@@ -119,7 +161,11 @@ func (s *SummaryReport) RunningAppInstancesCount() int {
119161
//
120162
// then you'd have "2 running apps"
121163
func (s *SummaryReport) RunningAppsCount() int {
122-
return 0
164+
count := 0
165+
for _, report := range s.orgReportsRef {
166+
count += report.RunningAppsCount()
167+
}
168+
return count
123169
}
124170

125171
// ServicesCount returns total count of registered services
@@ -129,21 +175,40 @@ func (s *SummaryReport) RunningAppsCount() int {
129175
// those aren't considered in this result. This only counts services registered which
130176
// show up in `cf services`
131177
func (s *SummaryReport) ServicesCount() int {
132-
return 0
178+
count := 0
179+
for _, report := range s.orgReportsRef {
180+
count += report.ServicesCount()
181+
}
182+
return count
133183
}
134184

135185
// SpringCloudServicesCount returns the number of service instances
136186
// from "spring cloud services" tile, e.g. config-server/service-registry/circuit-breaker/etc.
137187
//
138188
// see: https://network.pivotal.io/products/p-spring-cloud-services/
139189
func (s *SummaryReport) SpringCloudServicesCount() int {
140-
return 0
190+
count := 0
191+
for _, report := range s.orgReportsRef {
192+
count += report.SpringCloudServicesCount()
193+
}
194+
return count
141195
}
142196

197+
// StoppedAppInstancesCount -
143198
func (s *SummaryReport) StoppedAppInstancesCount() int {
144-
return 0
199+
count := 0
200+
for _, report := range s.orgReportsRef {
201+
count += report.StoppedAppInstancesCount()
202+
}
203+
return count
145204
}
146205

206+
// StoppedAppsCount -
147207
func (s *SummaryReport) StoppedAppsCount() int {
148-
return 0
208+
count := 0
209+
for _, report := range s.orgReportsRef {
210+
count += report.StoppedAppsCount()
211+
}
212+
return count
213+
149214
}

0 commit comments

Comments
 (0)