@@ -2,6 +2,7 @@ package main
22
33import (
44 "strings"
5+ "bytes"
56
67 as "github.com/aerospike/aerospike-client-go"
78 "github.com/prometheus/client_golang/prometheus"
@@ -271,7 +272,7 @@ func (nc nsCollector) describe(ch chan<- *prometheus.Desc) {
271272}
272273
273274func (nc nsCollector ) parseStorage (s string , d string ) (string , error ) {
274- r := ""
275+ buf := bytes. Buffer {}
275276 for _ , l := range strings .Split (s , ";" ) {
276277 for _ , v := range strings .Split (l , ":" ) {
277278 kv := strings .SplitN (v , "=" , 2 )
@@ -281,32 +282,36 @@ func (nc nsCollector) parseStorage(s string, d string) (string, error) {
281282 kv [0 ] = strings .Replace (kv [0 ] + "." , d , "" , 1 )
282283 kv [0 ] = strings .Replace (kv [0 ], "." , "" , - 1 )
283284 }
284- r += kv [0 ] + "=" + kv [1 ] + ";"
285+ buf . WriteString ( kv [0 ] + "=" + kv [1 ] + ";" )
285286 }
286287 }
287288 }
289+ r := buf .String ()
288290 return r , nil
289291}
290292
291- func (nc nsCollector ) splitInfo (s map [string ]string , ns string ) (map [string ]string , map [string ]string , map [string ]string ) {
292- ns_metrics := map [string ]string {}
293- ns_storage_metrics := map [string ]string {}
294- ns_storage_devices := map [string ]string {}
293+ func (nc nsCollector ) splitInfo (s string ) (string , string , map [string ]string ) {
294+ nsStorageMounts := map [string ]string {}
295295
296- for _ , l := range strings .Split (s ["namespace/" + ns ], ";" ) {
296+ bufStandardMetrics := bytes.Buffer {}
297+ bufStorageMetrics := bytes.Buffer {}
298+
299+ for _ , l := range strings .Split (s , ";" ) {
297300 for _ , v := range strings .Split (l , ":" ) {
298301 kv := strings .SplitN (v , "=" , 2 )
299302 if strings .HasPrefix (kv [0 ], "storage-engine" ) {
300- ns_storage_metrics [ "namespace/" + ns ] += v + ";"
303+ bufStorageMetrics . WriteString ( v + ";" )
301304 if strings .HasSuffix (kv [0 ], "]" ) {
302- ns_storage_devices [kv [1 ]] = kv [0 ]
305+ nsStorageMounts [kv [1 ]] = kv [0 ]
303306 }
304307 } else {
305- ns_metrics [ "namespace/" + ns ] += v + ";"
308+ bufStandardMetrics . WriteString ( v + ";" )
306309 }
307310 }
308311 }
309- return ns_storage_metrics , ns_metrics , ns_storage_devices
312+ nsStandardMetrics := bufStandardMetrics .String ()
313+ nsStorageMetrics := bufStorageMetrics .String ()
314+ return nsStorageMetrics , nsStandardMetrics , nsStorageMounts
310315}
311316
312317func (nc nsCollector ) collect (conn * as.Connection ) ([]prometheus.Metric , error ) {
@@ -316,23 +321,23 @@ func (nc nsCollector) collect(conn *as.Connection) ([]prometheus.Metric, error)
316321 }
317322 var metrics []prometheus.Metric
318323 for _ , ns := range strings .Split (info ["namespaces" ], ";" ) {
319- nsinfo , err := as .RequestInfo (conn , "namespace/" + ns )
324+ nsInfo , err := as .RequestInfo (conn , "namespace/" + ns )
320325 if err != nil {
321326 return nil , err
322327 }
323328
324- nsinfo_storage , nsinfo_standart , nsinfo_devices := nc .splitInfo (nsinfo , ns )
329+ nsInfoStorage , nsInfoStandard , nsInfoStorageDevices := nc .splitInfo (nsInfo [ "namespace/" + ns ] )
325330
326331 metrics = append (
327332 metrics ,
328- infoCollect (cmetrics (nc ), nsinfo_standart [ "namespace/" + ns ] , ns )... ,
333+ infoCollect (cmetrics (nc ), nsInfoStandard , ns )... ,
329334 )
330335
331- for name , metric := range nsinfo_devices {
332- nsinfo_storage [ "namespace/" + ns ] , err = nc .parseStorage (nsinfo_storage [ "namespace/" + ns ], metric )
336+ for mountName , metricName := range nsInfoStorageDevices {
337+ nsInfoStorage , err = nc .parseStorage (nsInfoStorage , metricName )
333338 metrics = append (
334339 metrics ,
335- infoCollect (cmetrics (nc ), nsinfo_storage [ "namespace/" + ns ] , ns , name )... ,
340+ infoCollect (cmetrics (nc ), nsInfoStorage , ns , mountName )... ,
336341 )
337342 }
338343 }
0 commit comments