diff --git a/collectors/applications.go b/collectors/applications.go index b195c68e..3abc84b4 100644 --- a/collectors/applications.go +++ b/collectors/applications.go @@ -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( @@ -242,30 +242,37 @@ 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 + detectedBuildpack := "" + buildpack := "" + stackGUID := "" + for _, stack := range objs.Stacks { + if stack.Name == application.Lifecycle.Data.Stack { + stackGUID = stack.GUID + break + } } - - // 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)) + 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)) + } + } } c.applicationInfoMetric.WithLabelValues( @@ -277,7 +284,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)) @@ -291,15 +298,14 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m string(application.State), ).Set(float64(process.Instances.Value)) - runningInstances := appSum.RunningInstances // Use bbs data if available + runningInstances := 0 if len(objs.ProcessActualLRPs) > 0 { - runningsInstances := 0 - lrps, ok := objs.ProcessActualLRPs[process.GUID] + LRPs, ok := objs.ProcessActualLRPs[process.GUID] if ok { - for _, lrp := range lrps { + for _, lrp := range LRPs { if lrp.State == "RUNNING" { - runningsInstances++ + runningInstances++ } } } diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go index d1a86507..5e1d9aa5 100644 --- a/fetcher/fetcher.go +++ b/fetcher/fetcher.go @@ -67,6 +67,7 @@ func (c *Fetcher) workInit() { c.worker.PushIf("spaces", c.fetchSpaces, filters.Applications, filters.Spaces) c.worker.PushIf("space_quotas", c.fetchSpaceQuotas, filters.Spaces) c.worker.PushIf("applications", c.fetchApplications, filters.Applications) + c.worker.PushIf("droplets", c.fetchDroplets, filters.Droplets) c.worker.PushIf("domains", c.fetchDomains, filters.Domains) c.worker.PushIf("process", c.fetchProcesses, filters.Applications) c.worker.PushIf("routes", c.fetchRoutes, filters.Routes) diff --git a/fetcher/fetcher_handlers.go b/fetcher/fetcher_handlers.go index c5bdad2d..be7a0787 100644 --- a/fetcher/fetcher_handlers.go +++ b/fetcher/fetcher_handlers.go @@ -1,7 +1,6 @@ package fetcher import ( - "fmt" "regexp" "time" @@ -9,7 +8,6 @@ import ( "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" "code.cloudfoundry.org/cli/resources" - "github.com/cloudfoundry/cf_exporter/filters" "github.com/cloudfoundry/cf_exporter/models" log "github.com/sirupsen/logrus" ) @@ -74,33 +72,10 @@ func (c *Fetcher) fetchOrgQuotas(session *SessionExt, _ *BBSClient, entry *model // summary fetching attempt. See cloudfoundry/cf_exporter#85 func (c *Fetcher) fetchSpaces(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error { spaces, _, _, err := session.V3().GetSpaces(LargeQuery) - if err != nil { - return err - } - - loadIndex(entry.Spaces, spaces, func(r resources.Space) string { return r.GUID }) - total := len(spaces) - for idx := 0; idx < total; idx++ { - space := spaces[idx] - name := fmt.Sprintf("space_summaries %04d/%04d (%s)", idx, total, space.GUID) - c.worker.PushIf(name, func(session *SessionExt, bbs *BBSClient, entry *models.CFObjects) error { - spaceSum, err := session.GetSpaceSummary(space.GUID) - if err == nil { - c.Lock() - entry.SpaceSummaries[spaceSum.GUID] = *spaceSum - for _, app := range spaceSum.Apps { - entry.AppSummaries[app.GUID] = app - } - c.Unlock() - } else { - log.WithError(err).Warnf("could not fetch space '%s' summary", space.GUID) - } - // 1 - return nil - }, filters.Applications) + if err == nil { + loadIndex(entry.Spaces, spaces, func(r resources.Space) string { return r.GUID }) } - - return nil + return err } func (c *Fetcher) fetchSpaceQuotas(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error { @@ -169,6 +144,14 @@ func (c *Fetcher) fetchSecurityGroups(session *SessionExt, _ *BBSClient, entry * return err } +func (c *Fetcher) fetchDroplets(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error { + droplets, _, err := session.V3().GetDroplets(LargeQuery) + if err == nil { + loadIndex(entry.Droplets, droplets, func(r resources.Droplet) string { return r.GUID }) + } + return err +} + func (c *Fetcher) fetchStacks(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error { stacks, _, err := session.V3().GetStacks(LargeQuery) if err == nil { diff --git a/filters/filters.go b/filters/filters.go index b4d3c247..4969129d 100644 --- a/filters/filters.go +++ b/filters/filters.go @@ -7,6 +7,7 @@ import ( const ( Applications = "applications" + Droplets = "droplets" Buildpacks = "buildpacks" Domains = "domains" Events = "events" @@ -22,12 +23,12 @@ const ( Spaces = "spaces" Stacks = "stacks" Tasks = "tasks" - InstancesRunning = "instances_running" ) var ( All = []string{ Applications, + Droplets, Buildpacks, Domains, Events, @@ -54,6 +55,7 @@ func NewFilter(active ...string) (*Filter, error) { filter := &Filter{ activated: map[string]bool{ Applications: true, + Droplets: true, Buildpacks: true, Domains: true, IsolationSegments: true, @@ -69,7 +71,6 @@ func NewFilter(active ...string) (*Filter, error) { Stacks: true, Tasks: false, Events: false, - InstancesRunning: false, }, } @@ -86,6 +87,7 @@ func (f *Filter) setActive(active []string) error { // override default states with all disabled f.activated = map[string]bool{ Applications: false, + Droplets: false, Buildpacks: false, Domains: false, IsolationSegments: false, @@ -101,7 +103,6 @@ func (f *Filter) setActive(active []string) error { Stacks: false, Tasks: false, Events: false, - InstancesRunning: false, } // enable only given filters diff --git a/main.go b/main.go index 41496d3c..81b42865 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/version" log "github.com/sirupsen/logrus" - kingpin "gopkg.in/alecthomas/kingpin.v2" + "gopkg.in/alecthomas/kingpin.v2" ) var ( @@ -195,9 +195,6 @@ func main() { SkipCertVerify: *bbsSkipSSLValidation, } - log.Infof("cfConfig: %+v", cfConfig) - log.Infof("bbsConfig: %+v", bbsConfig) - active := []string{} if len(*filterCollectors) != 0 { active = strings.Split(*filterCollectors, ",") diff --git a/models/model.go b/models/model.go index c7093fbe..a40a80ac 100644 --- a/models/model.go +++ b/models/model.go @@ -17,6 +17,7 @@ type CFObjects struct { Spaces map[string]resources.Space `json:"spaces"` SpaceQuotas map[string]Quota `json:"space_quotas"` Apps map[string]Application `json:"apps"` + Droplets map[string]resources.Droplet `json:"droplets"` Processes map[string]resources.Process `json:"process"` Tasks map[string]Task `json:"tasks"` Routes map[string]resources.Route `json:"routes"` @@ -26,13 +27,12 @@ type CFObjects struct { SecurityGroups map[string]resources.SecurityGroup `json:"security_groups"` Stacks map[string]resources.Stack `json:"stacks"` Buildpacks map[string]resources.Buildpack `json:"buildpacks"` + BuildpacksByName map[string]resources.Buildpack `json:"builpacks_by_name"` Domains map[string]resources.Domain `json:"domains"` ServiceBrokers map[string]resources.ServiceBroker `json:"service_brokers"` ServiceOfferings map[string]resources.ServiceOffering `json:"service_offerings"` ServicePlans map[string]resources.ServicePlan `json:"service_plans"` ServiceBindings map[string]resources.ServiceCredentialBinding `json:"service_bindings"` - SpaceSummaries map[string]SpaceSummary `json:"space_summaries"` - AppSummaries map[string]AppSummary `json:"app_summaries"` AppProcesses map[string][]resources.Process `json:"app_processes"` ProcessActualLRPs map[string][]*models.ActualLRP `json:"process_actual_lrps"` Events map[string]Event `json:"events"` @@ -159,6 +159,7 @@ func NewCFObjects() *CFObjects { Spaces: map[string]resources.Space{}, SpaceQuotas: map[string]Quota{}, Apps: map[string]Application{}, + Droplets: map[string]resources.Droplet{}, Processes: map[string]resources.Process{}, Tasks: map[string]Task{}, Routes: map[string]resources.Route{}, @@ -173,8 +174,6 @@ func NewCFObjects() *CFObjects { ServiceOfferings: map[string]resources.ServiceOffering{}, ServicePlans: map[string]resources.ServicePlan{}, ServiceBindings: map[string]resources.ServiceCredentialBinding{}, - SpaceSummaries: map[string]SpaceSummary{}, - AppSummaries: map[string]AppSummary{}, AppProcesses: map[string][]resources.Process{}, ProcessActualLRPs: map[string][]*models.ActualLRP{}, Users: map[string]resources.User{},