Skip to content

Commit

Permalink
updating code to use better auth system
Browse files Browse the repository at this point in the history
also removed all fatal calls to do a better job of cleanup
on termination
  • Loading branch information
xphyr committed Sep 24, 2018
1 parent b18d95b commit 8fee9e5
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 114 deletions.
8 changes: 6 additions & 2 deletions collector/cluster-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ func NewEcsClusterCollector(emcecs *ecsclient.EcsClient, namespace string) (*Ecs
func (e *EcsClusterCollector) Collect(ch chan<- prometheus.Metric) {
log.Debugln("ECS Cluster collect starting")
if e.ecsClient == nil {
log.Errorln("ECS client not configured.")
log.Errorf("ECS client not configured.")
return
}

fields := e.ecsClient.RetrieveClusterState()
fields, err := e.ecsClient.RetrieveClusterState()
if err != nil {
log.Error("Cluster exporter received no info from array.")
return
}

// fmt.Printf("TotalDTNum: %v, UnreadyNum: %v, UnKnownNum: %v, NodeIP: %v\n", node.TotalDTnum, node.UnreadyDTnum, node.UnknownDTnum, node.NodeIP)
ch <- prometheus.MustNewConstMetric(transactionsuccess, prometheus.CounterValue, fields.TransactionSuccessTotal, fields.VdcName)
Expand Down
8 changes: 4 additions & 4 deletions collector/metering-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (e *EcsMeteringCollector) Collect(ch chan<- prometheus.Metric) {
start := time.Now()
// create a function to go get a list of all namespaces
nameSpaceReq := "https://" + e.ecsClient.ClusterAddress + ":4443/object/namespaces"
n := e.ecsClient.CallECSAPI(nameSpaceReq, 2)
n, _ := e.ecsClient.CallECSAPI(nameSpaceReq)

result := gjson.Get(n, "namespace.#.name")
// We need to limit the number of requests going to the API at once
Expand All @@ -70,14 +70,14 @@ func (e *EcsMeteringCollector) Collect(ch chan<- prometheus.Metric) {
defer func() { <-sem }()
// retrieve the quota applied
namespaceInfoReq := "https://" + e.ecsClient.ClusterAddress + ":4443/object/namespaces/namespace/" + ns + "/quota"
n := e.ecsClient.CallECSAPI(namespaceInfoReq, 2)
n, _ := e.ecsClient.CallECSAPI(namespaceInfoReq)
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")
}
// retrieve the current metering info
namespaceInfoReq = "https://" + e.ecsClient.ClusterAddress + ":4443/object/billing/namespace/" + ns + "/info?sizeunit=KB"
n = e.ecsClient.CallECSAPI(namespaceInfoReq, 2)
n, _ = e.ecsClient.CallECSAPI(namespaceInfoReq)
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")
}()
Expand All @@ -87,7 +87,7 @@ func (e *EcsMeteringCollector) Collect(ch chan<- prometheus.Metric) {
sem <- true
}
duration := float64(time.Since(start).Seconds())
log.Infof("Scrape of metering took %f seconds", duration)
log.Infof("Scrape of metering took %f seconds for cluster %s", duration, e.ecsClient.ClusterAddress)
log.Infoln("Metering exporter finished")
}

Expand Down
7 changes: 5 additions & 2 deletions collector/repl-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ func (e *EcsReplCollector) Collect(ch chan<- prometheus.Metric) {
return
}

replState := e.ecsClient.RetrieveReplState()
// fmt.Printf("Replication state is %v \n", replState)
replState, err := e.ecsClient.RetrieveReplState()
if err != nil {
log.Error("Replication exporter received no info from array.")
return
}

ch <- prometheus.MustNewConstMetric(replingresstraffic, prometheus.GaugeValue, replState.ReplicationIngressTraffic, replState.RgName)
ch <- prometheus.MustNewConstMetric(replegresstraffic, prometheus.GaugeValue, replState.ReplicationEgressTraffic, replState.RgName)
Expand Down
Loading

0 comments on commit 8fee9e5

Please sign in to comment.