Skip to content

Commit

Permalink
Merge pull request #126 from adamspd/PAASCFY-2654-ajouter-nouveaux-me…
Browse files Browse the repository at this point in the history
…trique

Added new metric application_buildpack
  • Loading branch information
gmllt authored Jun 19, 2024
2 parents dacfae1 + bc36c99 commit 686e22b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
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
}
4 changes: 0 additions & 4 deletions fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,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:

0 comments on commit 686e22b

Please sign in to comment.