Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new metric application_buildpack #126

Merged
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ The exporter returns the following `Applications` metrics:
| *metrics.namespace*_application_instances_running | Number of running Cloud Foundry Application Instances | `environment`, `deployment`, `application_id`, `application_name`, `organization_id`, `organization_name`, `space_id`, `space_name`, `state` |
| *metrics.namespace*_application_memory_mb | Cloud Foundry Application Memory (Mb) | `environment`, `deployment`, `application_id`, `application_name`, `organization_id`, `organization_name`, `space_id`, `space_name` |
| *metrics.namespace*_application_disk_quota_mb | Cloud Foundry Application Disk Quota (Mb) | `environment`, `deployment`, `application_id`, `application_name`, `organization_id`, `organization_name`, `space_id`, `space_name` |
| *metrics.namespace*_application_buildpack | All the buildpacks used by an Application. | `environment`, `deployment`, `application_id`, `application_name`, `buildpack_name`
| *metrics.namespace*_applications_scrapes_total | Total number of scrapes for Cloud Foundry Applications | `environment`, `deployment` |
| *metrics.namespace*_applications_scrape_errors_total | Total number of scrape errors of Cloud Foundry Applications | `environment`, `deployment` |
| *metrics.namespace*_last_applications_scrape_error | Whether the last scrape of Applications metrics from Cloud Foundry resulted in an error (`1` for error, `0` for success) | `environment`, `deployment` |
Expand Down
27 changes: 27 additions & 0 deletions collectors/applications.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// collectors/applications.go

package collectors

import (
Expand All @@ -15,6 +17,7 @@ type ApplicationsCollector struct {
environment string
deployment string
applicationInfoMetric *prometheus.GaugeVec
applicationBuildpackMetric *prometheus.GaugeVec
applicationInstancesMetric *prometheus.GaugeVec
applicationInstancesRunningMetric *prometheus.GaugeVec
applicationMemoryMbMetric *prometheus.GaugeVec
Expand Down Expand Up @@ -42,6 +45,17 @@ func NewApplicationsCollector(
[]string{"application_id", "application_name", "detected_buildpack", "buildpack", "organization_id", "organization_name", "space_id", "space_name", "stack_id", "state"},
)

applicationBuildpackMetric := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "application",
Name: "buildpack",
Help: "Buildpack used by an Application.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "buildpack_name"},
)

applicationInstancesMetric := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Expand Down Expand Up @@ -141,6 +155,7 @@ func NewApplicationsCollector(
environment: environment,
deployment: deployment,
applicationInfoMetric: applicationInfoMetric,
applicationBuildpackMetric: applicationBuildpackMetric,
applicationInstancesMetric: applicationInstancesMetric,
applicationInstancesRunningMetric: applicationInstancesRunningMetric,
applicationMemoryMbMetric: applicationMemoryMbMetric,
Expand Down Expand Up @@ -185,6 +200,7 @@ func (c ApplicationsCollector) Describe(ch chan<- *prometheus.Desc) {
c.applicationDiskQuotaMbMetric.Describe(ch)
c.applicationsScrapesTotalMetric.Describe(ch)
c.applicationsScrapeErrorsTotalMetric.Describe(ch)
c.applicationBuildpackMetric.Describe(ch)
c.lastApplicationsScrapeErrorMetric.Describe(ch)
c.lastApplicationsScrapeTimestampMetric.Describe(ch)
c.lastApplicationsScrapeDurationSecondsMetric.Describe(ch)
Expand Down Expand Up @@ -242,6 +258,15 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
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))
}

c.applicationInfoMetric.WithLabelValues(
application.GUID,
application.Name,
Expand Down Expand Up @@ -305,6 +330,7 @@ func (c ApplicationsCollector) reportApplicationsMetrics(objs *models.CFObjects,
c.applicationInstancesRunningMetric.Reset()
c.applicationMemoryMbMetric.Reset()
c.applicationDiskQuotaMbMetric.Reset()
c.applicationBuildpackMetric.Reset()

for _, application := range objs.Apps {
err := c.reportApp(application, objs)
Expand All @@ -320,5 +346,6 @@ func (c ApplicationsCollector) reportApplicationsMetrics(objs *models.CFObjects,
c.applicationInstancesRunningMetric.Collect(ch)
c.applicationMemoryMbMetric.Collect(ch)
c.applicationDiskQuotaMbMetric.Collect(ch)
c.applicationBuildpackMetric.Collect(ch)
return res
}
5 changes: 1 addition & 4 deletions fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (c *Fetcher) workInit() {
c.worker.PushIf("service_bindings", c.fetchServiceBindings, filters.ServiceBindings)
c.worker.PushIf("users", c.fetchUsers, filters.Events)
c.worker.PushIf("events", c.fetchEvents, filters.Events)
c.worker.PushIf("application_buildpack", c.fetchApplications, filters.Applications)
adamspd marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *Fetcher) fetch() *models.CFObjects {
Expand All @@ -98,7 +99,3 @@ func (c *Fetcher) fetch() *models.CFObjects {
result.Error = c.worker.Do(session, result)
return result
}

// Local Variables:
// ispell-local-dictionary: "american"
// End: