Add freezer stats
This one is a problem because the most useful stat is a string and not a float like verything else. We may have to change the return type Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
		
							parent
							
								
									e09e819712
								
							
						
					
					
						commit
						21e6eeffb9
					
				
					 1 changed files with 39 additions and 1 deletions
				
			
		|  | @ -1,7 +1,13 @@ | ||||||
| package fs | package fs | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
| 	"github.com/dotcloud/docker/pkg/cgroups" | 	"github.com/dotcloud/docker/pkg/cgroups" | ||||||
|  | 	"io/ioutil" | ||||||
|  | 	"os" | ||||||
|  | 	"path/filepath" | ||||||
|  | 	"strconv" | ||||||
|  | 	"strings" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type freezerGroup struct { | type freezerGroup struct { | ||||||
|  | @ -20,5 +26,37 @@ func (s *freezerGroup) Remove(d *data) error { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *freezerGroup) Stats(d *data) (map[string]float64, error) { | func (s *freezerGroup) Stats(d *data) (map[string]float64, error) { | ||||||
| 	return nil, ErrNotSupportStat | 	var ( | ||||||
|  | 		paramData = make(map[string]float64) | ||||||
|  | 		params    = []string{ | ||||||
|  | 			"parent_freezing", | ||||||
|  | 			"self_freezing", | ||||||
|  | 			// comment out right now because this is string "state", | ||||||
|  | 		} | ||||||
|  | 	) | ||||||
|  | 
 | ||||||
|  | 	path, err := d.path("freezer") | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	for _, param := range params { | ||||||
|  | 		f, err := os.Open(filepath.Join(path, fmt.Sprintf("freezer.%s", param))) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 		defer f.Close() | ||||||
|  | 
 | ||||||
|  | 		data, err := ioutil.ReadAll(f) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		v, err := strconv.ParseFloat(strings.TrimSuffix(string(data), "\n"), 64) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 		paramData[param] = v | ||||||
|  | 	} | ||||||
|  | 	return paramData, nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue