Skip to content

Commit

Permalink
Merge 0bcfe75 into e355e14
Browse files Browse the repository at this point in the history
  • Loading branch information
talal committed Jan 14, 2020
2 parents e355e14 + 0bcfe75 commit 98037cd
Show file tree
Hide file tree
Showing 29 changed files with 1,212 additions and 631 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ static-check: FORCE
@$(GO) vet $(GO_BUILDFLAGS) $(GO_ALLPKGS)

# detailed unit test run (incl. test coverage)
build/%.cover.out: FORCE build/mock-swift-dispersion-report build/mock-swift-recon
build/%.cover.out: FORCE build/mock-swift-dispersion build/mock-swift-recon
@printf "\e[1;36m>> go test $(subst _,/,$*)\e[0m\n"
$(GO) test $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' -coverprofile=$@ -covermode=count -coverpkg=$(subst $(space),$(comma),$(GO_COVERPKGS)) $(subst _,/,$*)
build/cover.out: $(GO_COVERFILES)
$(GO) run $(GO_BUILDFLAGS) test/cmd/gocovcat/main.go $(GO_COVERFILES) > $@
build/cover.html: build/cover.out
$(GO) tool cover -html $< -o $@

build/mock-swift-dispersion-report: FORCE
build/mock-swift-dispersion: FORCE
$(GO) install $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' '$(PKG)/test/cmd/mock-swift-dispersion-report'
$(GO) install $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' '$(PKG)/test/cmd/mock-swift-dispersion-report-with-errors'

build/mock-swift-recon: FORCE
$(GO) install $(GO_BUILDFLAGS) -ldflags '$(GO_LDFLAGS)' '$(PKG)/test/cmd/mock-swift-recon'
Expand Down
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,42 @@ for `swift-health-exporter`.

### Dispersion Report

| Metric | Labels |
| ---------------- | ----------- |
| `swift_dispersion_container_copies_expected` | |
| `swift_dispersion_container_copies_found` | |
| `swift_dispersion_container_copies_missing` | |
| `swift_dispersion_container_overlapping` | |
| `swift_dispersion_object_copies_expected` | |
| `swift_dispersion_object_copies_found` | |
| `swift_dispersion_object_copies_missing` | |
| `swift_dispersion_object_overlapping` | |
| `swift_dispersion_exit_code` | `query` |
| Metric | Labels |
| ---------------- | ----------- |
| `swift_dispersion_container_copies_expected` | |
| `swift_dispersion_container_copies_found` | |
| `swift_dispersion_container_copies_missing` | |
| `swift_dispersion_container_overlapping` | |
| `swift_dispersion_object_copies_expected` | |
| `swift_dispersion_object_copies_found` | |
| `swift_dispersion_object_copies_missing` | |
| `swift_dispersion_object_overlapping` | |
| `swift_dispersion_task_exit_code` | `task`, `failed_query` |

### Recon

| Metric | Labels |
| ---------------- | ----------- |
| `swift_cluster_accounts_quarantined` | `storage_ip` |
| `swift_cluster_accounts_replication_age` | `storage_ip` |
| `swift_cluster_accounts_replication_duration` | `storage_ip` |
| `swift_cluster_containers_quarantined` | `storage_ip` |
| `swift_cluster_containers_replication_age` | `storage_ip` |
| `swift_cluster_containers_replication_duration` | `storage_ip` |
| `swift_cluster_containers_updater_sweep_time` | `storage_ip` |
| `swift_cluster_drives_audit_errors` | `storage_ip` |
| `swift_cluster_drives_unmounted` | `storage_ip` |
| `swift_cluster_md5_all` | `kind` |
| `swift_cluster_md5_errors` | `kind` |
| `swift_cluster_md5_matched` | `kind` |
| `swift_cluster_md5_not_matched` | `kind` |
| `swift_cluster_objects_quarantined` | `storage_ip` |
| `swift_cluster_objects_replication_age` | `storage_ip` |
| `swift_cluster_objects_replication_duration` | `storage_ip` |
| `swift_cluster_objects_updater_sweep_time` | `storage_ip` |
| `swift_cluster_storage_capacity_bytes` | `storage_ip` |
| `swift_cluster_storage_free_bytes` | `storage_ip` |
| `swift_cluster_storage_used_bytes` | `storage_ip` |
| `swift_cluster_storage_used_percent_by_disk` | `storage_ip`, `disk` |
| `swift_cluster_storage_used_percent` | `storage_ip` |
| `swift_recon_exit_code` | `query` |
| Metric | Labels |
| ---------------- | ----------- |
| `swift_cluster_accounts_quarantined` | `storage_ip` |
| `swift_cluster_accounts_replication_age` | `storage_ip` |
| `swift_cluster_accounts_replication_duration` | `storage_ip` |
| `swift_cluster_containers_quarantined` | `storage_ip` |
| `swift_cluster_containers_replication_age` | `storage_ip` |
| `swift_cluster_containers_replication_duration` | `storage_ip` |
| `swift_cluster_containers_updater_sweep_time` | `storage_ip` |
| `swift_cluster_drives_audit_errors` | `storage_ip` |
| `swift_cluster_drives_unmounted` | `storage_ip` |
| `swift_cluster_md5_all` | `kind` |
| `swift_cluster_md5_errors` | `kind` |
| `swift_cluster_md5_matched` | `kind` |
| `swift_cluster_md5_not_matched` | `kind` |
| `swift_cluster_objects_quarantined` | `storage_ip` |
| `swift_cluster_objects_replication_age` | `storage_ip` |
| `swift_cluster_objects_replication_duration` | `storage_ip` |
| `swift_cluster_objects_updater_sweep_time` | `storage_ip` |
| `swift_cluster_storage_capacity_bytes` | `storage_ip` |
| `swift_cluster_storage_free_bytes` | `storage_ip` |
| `swift_cluster_storage_used_bytes` | `storage_ip` |
| `swift_cluster_storage_used_percent_by_disk` | `storage_ip`, `disk` |
| `swift_cluster_storage_used_percent` | `storage_ip` |
| `swift_recon_task_exit_code` | `task`, `failed_query` |
72 changes: 72 additions & 0 deletions collectors/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2015 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package collectors

import (
"fmt"
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/sapcc/go-bits/logg"
)

type typedDesc struct {
desc *prometheus.Desc
valueType prometheus.ValueType
}

func (d *typedDesc) mustNewConstMetric(value float64, labels ...string) prometheus.Metric {
return prometheus.MustNewConstMetric(d.desc, d.valueType, value, labels...)
}

func (d *typedDesc) describe(ch chan<- *prometheus.Desc) {
ch <- d.desc
}

// collectorTask is the interface that a specific collector task must implement.
type collectorTask interface {
describeMetrics(chan<- *prometheus.Desc)
collectMetrics(chan<- prometheus.Metric) error
}

// executeTask runs the metric collection for a specific collector task,
// and updates the respective exit code metric.
func executeTask(collectorName, taskName string, task collectorTask, ch chan<- prometheus.Metric, exitCodeTypedDesc typedDesc) {
exitCode := 0
failedQuery := ""

err := task.collectMetrics(ch)
if err != nil {
exitCode = 1
logg.Error("swift %s collector: %s: %s", collectorName, taskName, err.Error())
if e, ok := err.(*taskCollectionError); ok {
failedQuery = strings.Join(e.cmdArgs, " ")
}
}

ch <- exitCodeTypedDesc.mustNewConstMetric(float64(exitCode), taskName, failedQuery)
}

// taskCollectionError is a custom error type that a task.collectMetrics() can
// return in order to provide context about the specific command arguments
// that were used during that collection.
type taskCollectionError struct {
// we are only interested in the arguments, not the command itself
cmdArgs []string
inner error
}

func (e *taskCollectionError) Error() string {
return fmt.Sprintf("%s: %s", strings.Join(e.cmdArgs, " "), e.inner.Error())
}
Loading

0 comments on commit 98037cd

Please sign in to comment.