Skip to content

Commit

Permalink
Add scan errors and success metrics (#83)
Browse files Browse the repository at this point in the history
* Add scan errors and success metrics

* linting

* double value

Co-authored-by: wierg01 <[email protected]>
  • Loading branch information
gwiersma and wierg01 authored Mar 23, 2021
1 parent 36511d2 commit 4091c1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ make dockerbuild
|harbor_health_latency| | |
|harbor_scans_completed | | |
|harbor_scans_total | | |
|harbor_scans_success | | |
|harbor_scans_error | | |
|harbor_scans_requester | | |
|harbor_scans_latency| | |
|harbor_project_count_total| |type=[private_project, public_project, total_project]|
Expand Down
2 changes: 2 additions & 0 deletions harbor_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func createMetrics(instanceName string) {
allMetrics["scans_total"] = newMetricInfo(instanceName, "scans_total", "metrics of the latest scan all process", prometheus.GaugeValue, nil, nil)
allMetrics["scans_completed"] = newMetricInfo(instanceName, "scans_completed", "metrics of the latest scan all process", prometheus.GaugeValue, nil, nil)
allMetrics["scans_requester"] = newMetricInfo(instanceName, "scans_requester", "metrics of the latest scan all process", prometheus.GaugeValue, nil, nil)
allMetrics["scans_success"] = newMetricInfo(instanceName, "scans_success", "metrics of the current amount of succeeded scans", prometheus.GaugeValue, nil, nil)
allMetrics["scans_latency"] = newMetricInfo(instanceName, "scans_latency", "Time in seconds to collect scan metrics", prometheus.GaugeValue, nil, nil)
allMetrics["scans_error"] = newMetricInfo(instanceName, "scans_error", "Amount of failed scans", prometheus.GaugeValue, nil, nil)
allMetrics["project_count_total"] = newMetricInfo(instanceName, "project_count_total", "projects number relevant to the user", prometheus.GaugeValue, typeLabelNames, nil)
allMetrics["repo_count_total"] = newMetricInfo(instanceName, "repo_count_total", "repositories number relevant to the user", prometheus.GaugeValue, typeLabelNames, nil)
allMetrics["statistics_latency"] = newMetricInfo(instanceName, "statistics_latency", "Time in seconds to collect statistics metrics", prometheus.GaugeValue, nil, nil)
Expand Down
24 changes: 19 additions & 5 deletions metrics_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ func (h *HarborExporter) collectScanMetric(ch chan<- prometheus.Metric) bool {
start := time.Now()

type scanMetric struct {
Total float64
Completed float64
metrics []interface{}
Requester string
Ongoing bool
Total float64 `json:"total"`
Completed float64 `json:"completed"`
Metrics struct {
Error float64 `json:"Error"`
Success float64 `json:"Success"`
} `json:"metrics"`
Requester string `json:"requester"`
Ongoing bool `json:"ongoing"`
}


body, _ := h.request("/scans/all/metrics")
var data scanMetric

Expand All @@ -36,6 +41,15 @@ func (h *HarborExporter) collectScanMetric(ch chan<- prometheus.Metric) bool {
allMetrics["scans_total"].Desc, allMetrics["scans_total"].Type, float64(data.Total),
)

ch <- prometheus.MustNewConstMetric(
allMetrics["scans_error"].Desc, allMetrics["scans_error"].Type, float64(data.Metrics.Error),
)

ch <- prometheus.MustNewConstMetric(
allMetrics["scans_success"].Desc, allMetrics["scans_success"].Type, float64(data.Metrics.Success),
)


ch <- prometheus.MustNewConstMetric(
allMetrics["scans_completed"].Desc, allMetrics["scans_completed"].Type, float64(data.Completed),
)
Expand Down

0 comments on commit 4091c1b

Please sign in to comment.