Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
89 changes: 50 additions & 39 deletions README.md

Large diffs are not rendered by default.

97 changes: 61 additions & 36 deletions collectors/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -53,7 +53,7 @@ func NewApplicationsCollector(
Help: "Buildpack used by an Application.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "buildpack_name"},
[]string{"application_id", "application_name", "buildpack_name", "detected_buildpack"},
)

applicationInstancesMetric := prometheus.NewGaugeVec(
Expand Down Expand Up @@ -224,6 +224,7 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
process = cProc
}
}

spaceRel, ok := application.Relationships[constant.RelationshipTypeSpace]
if !ok {
return fmt.Errorf("could not find space relation in application '%s'", application.GUID)
Expand All @@ -241,31 +242,14 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
return fmt.Errorf("could not find org with guid '%s'", orgRel.GUID)
}

appSum, ok := objs.AppSummaries[application.GUID]
if !ok {
return fmt.Errorf("could not find app summary with guid '%s'", application.GUID)
}

// 1.
detectedBuildpack := appSum.DetectedBuildpack
if len(detectedBuildpack) == 0 {
detectedBuildpack = appSum.Buildpack
}

// 2.
buildpack := appSum.Buildpack
if len(buildpack) == 0 {
buildpack = appSum.DetectedBuildpack
}

// 3. Use the droplet data for the buildpack metric
for _, bp := range application.Lifecycle.Data.Buildpacks {
c.applicationBuildpackMetric.WithLabelValues(
application.GUID,
application.Name,
bp,
).Set(float64(1))
stackGUID := ""
for _, stack := range objs.Stacks {
if stack.Name == application.Lifecycle.Data.Stack {
stackGUID = stack.GUID
break
}
}
detectedBuildpack, buildpack := c.collectAppBuildpacks(application, objs)

c.applicationInfoMetric.WithLabelValues(
application.GUID,
Expand All @@ -276,7 +260,7 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
organization.Name,
space.GUID,
space.Name,
appSum.StackID,
stackGUID,
string(application.State),
).Set(float64(1))

Expand All @@ -290,15 +274,27 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
string(application.State),
).Set(float64(process.Instances.Value))

c.applicationInstancesRunningMetric.WithLabelValues(
application.GUID,
application.Name,
organization.GUID,
organization.Name,
space.GUID,
space.Name,
string(application.State),
).Set(float64(appSum.RunningInstances))
// Use bbs data if available
runningInstances := 0
if len(objs.ProcessActualLRPs) > 0 {
LRPs, ok := objs.ProcessActualLRPs[process.GUID]
if ok {
for _, lrp := range LRPs {
if lrp.State == "RUNNING" {
runningInstances++
}
}
}
c.applicationInstancesRunningMetric.WithLabelValues(
application.GUID,
application.Name,
organization.GUID,
organization.Name,
space.GUID,
space.Name,
string(application.State),
).Set(float64(runningInstances))
}

c.applicationMemoryMbMetric.WithLabelValues(
application.GUID,
Expand All @@ -320,6 +316,35 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
return nil
}

func (c ApplicationsCollector) collectAppBuildpacks(application models.Application, objs *models.CFObjects) (detectedBuildpack string, buildpack string) {
detectedBuildpack = ""
buildpack = ""
if dropletGUID := application.Relationships[constant.RelationshipTypeCurrentDroplet].GUID; dropletGUID != "" {
if droplet, ok := objs.Droplets[dropletGUID]; ok {
// 1.
detectedBuildpack = droplet.Buildpacks[0].DetectOutput
// 2.
buildpack = droplet.Buildpacks[0].BuildpackName
if len(detectedBuildpack) == 0 {
detectedBuildpack = buildpack
}
if len(buildpack) == 0 {
buildpack = detectedBuildpack
}
// 3.Use the droplet data for the buildpack metric
for _, bp := range droplet.Buildpacks {
c.applicationBuildpackMetric.WithLabelValues(
application.GUID,
application.Name,
bp.BuildpackName,
bp.DetectOutput,
).Set(float64(1))
}
}
}
return detectedBuildpack, buildpack
}

// reportApplicationsMetrics
// 1. continue processing application list upon error
func (c ApplicationsCollector) reportApplicationsMetrics(objs *models.CFObjects, ch chan<- prometheus.Metric) error {
Expand Down
2 changes: 1 addition & 1 deletion collectors/buildpacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
18 changes: 11 additions & 7 deletions collectors/collectors.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package collectors

import (
"github.com/cloudfoundry/cf_exporter/fetcher"
"github.com/cloudfoundry/cf_exporter/filters"
"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/fetcher"
"github.com/cloudfoundry/cf_exporter/v2/filters"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -14,7 +14,8 @@ type ObjectCollector interface {

type Collector struct {
workers int
config *fetcher.CFConfig
cfConfig *fetcher.CFConfig
bbsConfig *fetcher.BBSConfig
filter *filters.Filter
collectors []ObjectCollector
}
Expand All @@ -24,12 +25,14 @@ func NewCollector(
environment string,
deployment string,
workers int,
config *fetcher.CFConfig,
cfConfig *fetcher.CFConfig,
bbsConfig *fetcher.BBSConfig,
filter *filters.Filter,
) (*Collector, error) {
res := &Collector{
workers: workers,
config: config,
cfConfig: cfConfig,
bbsConfig: bbsConfig,
filter: filter,
collectors: []ObjectCollector{},
}
Expand Down Expand Up @@ -118,8 +121,9 @@ func NewCollector(
}

func (c *Collector) Collect(ch chan<- prometheus.Metric) {
fetcher := fetcher.NewFetcher(c.workers, c.config, c.filter)
fetcher := fetcher.NewFetcher(c.workers, c.cfConfig, c.bbsConfig, c.filter)
objs := fetcher.GetObjects()

for _, collector := range c.collectors {
collector.Collect(objs, ch)
}
Expand Down
2 changes: 1 addition & 1 deletion collectors/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/isolation_segments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"code.cloudfoundry.org/cli/resources"
"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
Expand Down
2 changes: 1 addition & 1 deletion collectors/route_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/service_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/service_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"code.cloudfoundry.org/cli/resources"
"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/service_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/resources"
"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
Expand Down
2 changes: 1 addition & 1 deletion collectors/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion collectors/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collectors
import (
"time"

"github.com/cloudfoundry/cf_exporter/models"
"github.com/cloudfoundry/cf_exporter/v2/models"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
Loading