Skip to content

Commit

Permalink
Make artifactory_artifacts_* metrics optional (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
peimanja authored Apr 17, 2023
1 parent d36e76f commit d34c1c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 10 additions & 6 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Credentials struct {
}

type OptionalMetrics struct {
Artifacts bool
ReplicationStatus bool
FederationStatus bool
}
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit d34c1c0

Please sign in to comment.