11package main
22
33import (
4- "strings"
54 "bytes"
5+ "strings"
66
77 as "github.com/aerospike/aerospike-client-go"
88 "github.com/prometheus/client_golang/prometheus"
@@ -226,12 +226,11 @@ var (
226226 // and this plugin thinks "storage-engine.device[0].write_q" is malformed.
227227 }
228228 NamespaceStorageMetrics = []metric {
229- counter ("defrag_reads" , "defrag reads" ),
229+ counter ("defrag_reads" , "defrag reads" ),
230230 counter ("defrag_writes" , "defrag writes" ),
231- gauge ("shadow_write_q" , "shadow write queue" ),
231+ gauge ("shadow_write_q" , "shadow write queue" ),
232232 gauge ("defrag_q" , "defrag queue" ),
233- gauge ("write_q" , "write queue" ),
234-
233+ gauge ("write_q" , "write queue" ),
235234 }
236235)
237236
@@ -273,45 +272,45 @@ func (nc nsCollector) describe(ch chan<- *prometheus.Desc) {
273272
274273func (nc nsCollector ) parseStorage (s string , d string ) (string , error ) {
275274 buf := bytes.Buffer {}
276- for _ , l := range strings .Split (s , ";" ) {
275+ for _ , l := range strings .Split (s , ";" ) {
277276 for _ , v := range strings .Split (l , ":" ) {
278277 kv := strings .SplitN (v , "=" , 2 )
279278 if len (kv ) > 1 {
280- if strings .HasPrefix (kv [0 ], d ) {
281- //todo: optimize
282- kv [0 ] = strings .Replace (kv [0 ] + "." , d , "" , 1 )
283- kv [0 ] = strings .Replace (kv [0 ], "." , "" , - 1 )
284- }
279+ if strings .HasPrefix (kv [0 ], d ) {
280+ //todo: optimize
281+ kv [0 ] = strings .Replace (kv [0 ]+ "." , d , "" , 1 )
282+ kv [0 ] = strings .Replace (kv [0 ], "." , "" , - 1 )
283+ }
285284 buf .WriteString (kv [0 ] + "=" + kv [1 ] + ";" )
286285 }
287286 }
288287 }
289288 r := buf .String ()
290- return r , nil
289+ return r , nil
291290}
292291
293292func (nc nsCollector ) splitInfo (s string ) (string , string , map [string ]string ) {
294- nsStorageMounts := map [string ]string {}
293+ nsStorageMounts := map [string ]string {}
295294
296- bufStandardMetrics := bytes.Buffer {}
295+ bufStandardMetrics := bytes.Buffer {}
297296 bufStorageMetrics := bytes.Buffer {}
298297
299- for _ , l := range strings .Split (s , ";" ) {
298+ for _ , l := range strings .Split (s , ";" ) {
300299 for _ , v := range strings .Split (l , ":" ) {
301300 kv := strings .SplitN (v , "=" , 2 )
302301 if strings .HasPrefix (kv [0 ], "storage-engine" ) {
303302 bufStorageMetrics .WriteString (v + ";" )
304- if strings .HasSuffix (kv [0 ], "]" ) {
305- nsStorageMounts [kv [1 ]] = kv [0 ]
306- }
303+ if strings .HasSuffix (kv [0 ], "]" ) {
304+ nsStorageMounts [kv [1 ]] = kv [0 ]
305+ }
307306 } else {
308307 bufStandardMetrics .WriteString (v + ";" )
309308 }
310309 }
311310 }
312311 nsStandardMetrics := bufStandardMetrics .String ()
313312 nsStorageMetrics := bufStorageMetrics .String ()
314- return nsStorageMetrics , nsStandardMetrics , nsStorageMounts
313+ return nsStorageMetrics , nsStandardMetrics , nsStorageMounts
315314}
316315
317316func (nc nsCollector ) collect (conn * as.Connection ) ([]prometheus.Metric , error ) {
@@ -333,13 +332,13 @@ func (nc nsCollector) collect(conn *as.Connection) ([]prometheus.Metric, error)
333332 infoCollect (cmetrics (nc ), nsInfoStandard , ns )... ,
334333 )
335334
336- for mountName , metricName := range nsInfoStorageDevices {
337- nsInfoStorage , err = nc .parseStorage (nsInfoStorage , metricName )
338- metrics = append (
339- metrics ,
340- infoCollect (cmetrics (nc ), nsInfoStorage , ns , mountName )... ,
341- )
342- }
335+ for mountName , metricName := range nsInfoStorageDevices {
336+ nsInfoStorage , err = nc .parseStorage (nsInfoStorage , metricName )
337+ metrics = append (
338+ metrics ,
339+ infoCollect (cmetrics (nc ), nsInfoStorage , ns , mountName )... ,
340+ )
341+ }
343342 }
344343 return metrics , nil
345344}
0 commit comments