From d34c1c0e0dc0743edcccab3b79b0edfd5ab1f5e1 Mon Sep 17 00:00:00 2001 From: Peiman Jafari <18074432+peimanja@users.noreply.github.com> Date: Mon, 17 Apr 2023 07:05:35 -0700 Subject: [PATCH] Make artifactory_artifacts_* metrics optional (#105) --- README.md | 1 + collector/collector.go | 16 ++++++++++------ config/config.go | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 542c2fc..b8385eb 100755 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ Some metrics are expensive to compute and are disabled by default. To enable the Supported optional metrics: +* `artifacts` - Extracts number of artifacts created/downloaded for each repository. Enabling this will add `artifactory_artifacts_*` metrics. Please note that on large Artifactory instances, this may impact the performance. * `replication_status` - Extracts status of replication for each repository which has replication enabled. Enabling this will add the `status` label to `artifactory_replication_enabled` metric. * `federation_status` - Extracts federation metrics. Enabling this will add two new metrics: `artifactory_federation_mirror_lag`, and `artifactory_federation_unavailable_mirror`. Please note that these metrics are only available in Artifactory Enterprise Plus and version 7.18.3 and above. diff --git a/collector/collector.go b/collector/collector.go index a065e8d..22cece3 100755 --- a/collector/collector.go +++ b/collector/collector.go @@ -89,8 +89,10 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { for _, m := range systemMetrics { ch <- m } - for _, m := range artifactsMetrics { - ch <- m + if e.optionalMetrics.Artifacts { + for _, m := range artifactsMetrics { + ch <- m + } } if e.optionalMetrics.FederationStatus { for _, m := range federationMetrics { @@ -174,11 +176,13 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) (up float64) { e.exportRepo(repoSummaryList, ch) // Get Downloaded and Created items for all repo in the last 1 and 5 minutes and add it to repoSummaryList - repoSummaryList, err = e.getTotalArtifacts(repoSummaryList) - if err != nil { - return 0 + if e.optionalMetrics.Artifacts { + repoSummaryList, err = e.getTotalArtifacts(repoSummaryList) + if err != nil { + return 0 + } + e.exportArtifacts(repoSummaryList, ch) } - e.exportArtifacts(repoSummaryList, ch) // Get Federation Mirror metrics if e.optionalMetrics.FederationStatus && e.client.IsFederationEnabled() { diff --git a/config/config.go b/config/config.go index 2699935..693ba9f 100644 --- a/config/config.go +++ b/config/config.go @@ -34,6 +34,7 @@ type Credentials struct { } type OptionalMetrics struct { + Artifacts bool ReplicationStatus bool FederationStatus bool } @@ -81,6 +82,8 @@ func NewConfig() (*Config, error) { optMetrics := OptionalMetrics{} for _, metric := range *optionalMetrics { switch metric { + case "artifacts": + optMetrics.Artifacts = true case "replication_status": optMetrics.ReplicationStatus = true case "federation_status":