Jelajahi Sumber

add dump method for standard registry

Sergey Kacheev 8 tahun lalu
induk
melakukan
972ba8f8e0
1 mengubah file dengan 6 tambahan dan 1 penghapusan
  1. 6 1
      json.go

+ 6 - 1
json.go

@@ -9,6 +9,11 @@ import (
 // MarshalJSON returns a byte slice containing a JSON representation of all
 // the metrics in the Registry.
 func (r *StandardRegistry) MarshalJSON() ([]byte, error) {
+	return json.Marshal(r.Dump())
+}
+
+// Dump all the metrics in the Registry
+func (r *StandardRegistry) Dump() map[string]map[string]interface{} {
 	data := make(map[string]map[string]interface{})
 	r.Each(func(name string, i interface{}) {
 		values := make(map[string]interface{})
@@ -65,7 +70,7 @@ func (r *StandardRegistry) MarshalJSON() ([]byte, error) {
 		}
 		data[name] = values
 	})
-	return json.Marshal(data)
+	return data
 }
 
 // WriteJSON writes metrics from the given registry  periodically to the