github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/client/structs/structs.go (about)

     1  package structs
     2  
     3  // MemoryStats holds memory usage related stats
     4  type MemoryStats struct {
     5  	RSS            uint64
     6  	Cache          uint64
     7  	Swap           uint64
     8  	MaxUsage       uint64
     9  	KernelUsage    uint64
    10  	KernelMaxUsage uint64
    11  
    12  	// A list of fields whose values were actually sampled
    13  	Measured []string
    14  }
    15  
    16  func (ms *MemoryStats) Add(other *MemoryStats) {
    17  	ms.RSS += other.RSS
    18  	ms.Cache += other.Cache
    19  	ms.Swap += other.Swap
    20  	ms.MaxUsage += other.MaxUsage
    21  	ms.KernelUsage += other.KernelUsage
    22  	ms.KernelMaxUsage += other.KernelMaxUsage
    23  	ms.Measured = joinStringSet(ms.Measured, other.Measured)
    24  }
    25  
    26  // CpuStats holds cpu usage related stats
    27  type CpuStats struct {
    28  	SystemMode       float64
    29  	UserMode         float64
    30  	TotalTicks       float64
    31  	ThrottledPeriods uint64
    32  	ThrottledTime    uint64
    33  	Percent          float64
    34  
    35  	// A list of fields whose values were actually sampled
    36  	Measured []string
    37  }
    38  
    39  func (cs *CpuStats) Add(other *CpuStats) {
    40  	cs.SystemMode += other.SystemMode
    41  	cs.UserMode += other.UserMode
    42  	cs.TotalTicks += other.TotalTicks
    43  	cs.ThrottledPeriods += other.ThrottledPeriods
    44  	cs.ThrottledTime += other.ThrottledTime
    45  	cs.Percent += other.Percent
    46  	cs.Measured = joinStringSet(cs.Measured, other.Measured)
    47  }
    48  
    49  // ResourceUsage holds information related to cpu and memory stats
    50  type ResourceUsage struct {
    51  	MemoryStats *MemoryStats
    52  	CpuStats    *CpuStats
    53  }
    54  
    55  func (ru *ResourceUsage) Add(other *ResourceUsage) {
    56  	ru.MemoryStats.Add(other.MemoryStats)
    57  	ru.CpuStats.Add(other.CpuStats)
    58  }
    59  
    60  // TaskResourceUsage holds aggregated resource usage of all processes in a Task
    61  // and the resource usage of the individual pids
    62  type TaskResourceUsage struct {
    63  	ResourceUsage *ResourceUsage
    64  	Timestamp     int64
    65  	Pids          map[string]*ResourceUsage
    66  }
    67  
    68  // AllocResourceUsage holds the aggregated task resource usage of the
    69  // allocation.
    70  type AllocResourceUsage struct {
    71  	// ResourceUsage is the summation of the task resources
    72  	ResourceUsage *ResourceUsage
    73  
    74  	// Tasks contains the resource usage of each task
    75  	Tasks map[string]*TaskResourceUsage
    76  
    77  	// The max timestamp of all the Tasks
    78  	Timestamp int64
    79  }
    80  
    81  // joinStringSet takes two slices of strings and joins them
    82  func joinStringSet(s1, s2 []string) []string {
    83  	lookup := make(map[string]struct{}, len(s1))
    84  	j := make([]string, 0, len(s1))
    85  	for _, s := range s1 {
    86  		j = append(j, s)
    87  		lookup[s] = struct{}{}
    88  	}
    89  
    90  	for _, s := range s2 {
    91  		if _, ok := lookup[s]; !ok {
    92  			j = append(j, s)
    93  		}
    94  	}
    95  
    96  	return j
    97  }