func (e *EcsMeteringCollector) Collect(ch chan<- prometheus.Metric) {
	log.WithFields(log.Fields{"package": "metering-collector"}).Debug("ECS Metering collect starting")
	if e.ecsClient == nil {
		log.WithFields(log.Fields{"package": "metering-collector"}).Error("ECS client not configured.")
		return
	}
	start := time.Now()
	nameSpaceReq := "https://" + e.ecsClient.ClusterAddress + ":4443/object/namespaces"
	n, err := e.ecsClient.CallECSAPI(nameSpaceReq)
	if err != nil {
		log.WithFields(log.Fields{"package": "metering-collector"}).Errorf("Error getting metering info: %s", err)
		return
	}
	result := gjson.Get(n, "namespace.#.name")
	concurrency := 4
	sem := make(chan bool, concurrency)
	gb2kb := math.Pow10(6)
	for _, name := range result.Array() {
		ns := name.String()
		sem <- true
		go func() {
			defer func() { <-sem }()
			namespaceInfoReq := "https://" + e.ecsClient.ClusterAddress + ":4443/object/namespaces/namespace/" + ns + "/quota"
			n, err := e.ecsClient.CallECSAPI(namespaceInfoReq)
			if err != nil {
				log.WithFields(log.Fields{"package": "metering-collector"}).Errorf("Error getting metering info quota: %s", err)
				return
			}
			if gjson.Get(n, "blockSize").Float() > 0 {
				ch <- prometheus.MustNewConstMetric(nameSpaceQuota, prometheus.GaugeValue, gjson.Get(n, "blockSize").Float()*gb2kb, ns, "block")
				ch <- prometheus.MustNewConstMetric(nameSpaceQuota, prometheus.GaugeValue, gjson.Get(n, "notificationSize").Float()*gb2kb, ns, "notification")
			}
			namespaceInfoReq = "https://" + e.ecsClient.ClusterAddress + ":4443/object/billing/namespace/" + ns + "/info?sizeunit=KB"
			n, err = e.ecsClient.CallECSAPI(namespaceInfoReq)
			if err != nil {
				log.WithFields(log.Fields{"package": "metering-collector"}).Errorf("Error getting metering info quota: %s", err)
				return
			}
			ch <- prometheus.MustNewConstMetric(nameSpaceObjectTotal, prometheus.GaugeValue, gjson.Get(n, "total_objects").Float(), ns)
			ch <- prometheus.MustNewConstMetric(nameSpaceQuota, prometheus.GaugeValue, gjson.Get(n, "total_size").Float(), ns, "used")
		}()
	}
	for i := 0; i < cap(sem); i++ {
		sem <- true
	}
	duration := float64(time.Since(start).Seconds())
	log.WithFields(log.Fields{"package": "metering-collector"}).Debugf("Scrape of metering took %f seconds for cluster %s\n", duration, e.ecsClient.ClusterAddress)
	log.WithFields(log.Fields{"package": "metering-collector"}).Debug("Metering exporter finished")
}
Collect fetches the metering information such as quota and usage from the cluster
It implements prometheus.Collector.
package collector
import (
	"math"
	"time"
	"github.com/paychex/prometheus-emcecs-exporter/pkg/ecsclient"
	"github.com/prometheus/client_golang/prometheus"
	log "github.com/sirupsen/logrus"
	"github.com/tidwall/gjson"
)
type EcsMeteringCollector struct {
	ecsClient *ecsclient.EcsClient
	namespace string
}
var (
	nameSpaceQuota = prometheus.NewDesc(
		prometheus.BuildFQName("emcecs", "metering", "namespacequota"),
		"quota information for namespace in KB",
		[]string{"ecsnamespace", "type"}, nil,
	)
	nameSpaceObjectTotal = prometheus.NewDesc(
		prometheus.BuildFQName("emcecs", "metering", "namespace_object_count"),
		"total count of objects in namespace",
		[]string{"ecsnamespace"}, nil,
	)
)
func NewEcsMeteringCollector(emcecs *ecsclient.EcsClient, namespace string) (*EcsMeteringCollector, error) {
	log.WithFields(log.Fields{"package": "metering-collector"}).Debug("Init Metering exporter")
	return &EcsMeteringCollector{
		ecsClient: emcecs,
		namespace: namespace,
	}, nil
}