Example #1
0
File: index.go Project: vadv/ostent
func diskMeta(disk operating.MetricDF) operating.DiskMeta {
	devname := disk.DevName.Snapshot().Value()
	dirname := disk.DirName.Snapshot().Value()
	return operating.DiskMeta{
		DevName: devname,
		DirName: operating.Field(dirname),
	}
}
Example #2
0
func _getmem(kind string, in sigar.Swap) operating.Memory {
	total, approxtotal, _ := format.HumanBandback(in.Total)
	used, approxused, _ := format.HumanBandback(in.Used)

	return operating.Memory{
		Kind:       operating.Field(kind),
		Total:      total,
		Used:       used,
		Free:       format.HumanB(in.Free),
		UsePercent: format.FormatPercent(approxused, approxtotal),
	}
}
Example #3
0
File: index.go Project: vadv/ostent
func (ir *IndexRegistry) UpdateCPU(cpus []sigar.Cpu) {
	ir.Mutex.Lock()
	defer ir.Mutex.Unlock()
	all := sigar.Cpu{}
	for coreno, core := range cpus {
		ir.GetOrRegisterPrivateCPU(coreno).Update(core)
		operating.AddSCPU(&all, core)
	}
	if ir.PrivateCPUAll.N == "all" {
		ir.PrivateCPUAll.N = operating.Field(fmt.Sprintf("all %d", len(cpus)))
	}
	ir.PrivateCPUAll.Update(all)
}
Example #4
0
File: index.go Project: vadv/ostent
func FormatCPU(mc operating.MetricCPU) operating.CoreInfo {
	user := uint(mc.User.Percent.Snapshot().Value()) // rounding
	// .Nice is unused
	sys := uint(mc.Sys.Percent.Snapshot().Value())   // rounding
	idle := uint(mc.Idle.Percent.Snapshot().Value()) // rounding
	N := string(mc.N)
	if prefix := "cpu-"; strings.HasPrefix(N, prefix) { // true for all but "all"
		N = "#" + N[len(prefix):] // fmt.Sprintf("#%d", n)
	}
	return operating.CoreInfo{
		N:    operating.Field(N),
		User: user,
		Sys:  sys,
		Idle: idle,
	}
}
Example #5
0
File: index.go Project: vadv/ostent
func (procs MPSlice) Ordered(para *params.Params) *PStable {
	uids := map[uint]string{}

	pslen := uint(len(procs))
	limitPS := para.LIMIT["psn"].Value
	notdec := limitPS <= 1
	notexp := limitPS >= pslen

	if limitPS >= pslen { // notexp
		limitPS = pslen // NB modified limitPS
	}

	pst := &PStable{}
	pst.PSnotDecreasable = new(operating.Bool)
	*pst.PSnotDecreasable = operating.Bool(notdec)
	pst.PSnotExpandable = new(operating.Bool)
	*pst.PSnotExpandable = operating.Bool(notexp)
	pst.PSplusText = new(string)
	*pst.PSplusText = fmt.Sprintf("%d+", limitPS)

	if para.BOOL["hideps"].Value {
		return pst
	}

	operating.MetricProcSlice(procs).SortSortBy(LessProcFunc(uids, *para.ENUM["ps"])) // not .StableSortBy
	if !notexp {
		procs = procs[:limitPS]
	}
	for _, proc := range procs {
		pst.List = append(pst.List, operating.ProcData{
			PID:      operating.Field(fmt.Sprintf("%d", proc.PID)),
			UID:      proc.UID,
			Priority: proc.Priority,
			Nice:     proc.Nice,
			Time:     format.FormatTime(proc.Time),
			Name:     proc.Name,
			User:     username(uids, proc.UID),
			Size:     format.HumanB(proc.Size),
			Resident: format.HumanB(proc.Resident),
		})
	}
	return pst
}
Example #6
0
File: index.go Project: vadv/ostent
// GetOrRegisterPrivateInterface produces a registered in PrivateInterfaceRegistry operating.MetricInterface.
func (ir *IndexRegistry) GetOrRegisterPrivateInterface(name string) operating.MetricInterface {
	ir.PrivateMutex.Lock()
	defer ir.PrivateMutex.Unlock()
	if metric := ir.PrivateInterfaceRegistry.Get(name); metric != nil {
		return metric.(operating.MetricInterface)
	}
	i := operating.MetricInterface{
		Interface: &operating.Interface{
			Name:       operating.Field(name),
			BytesIn:    operating.NewGaugeDiff("interface-"+name+".if_octets.rx", ir.Registry),
			BytesOut:   operating.NewGaugeDiff("interface-"+name+".if_octets.tx", ir.Registry),
			ErrorsIn:   operating.NewGaugeDiff("interface-"+name+".if_errors.rx", ir.Registry),
			ErrorsOut:  operating.NewGaugeDiff("interface-"+name+".if_errors.tx", ir.Registry),
			PacketsIn:  operating.NewGaugeDiff("interface-"+name+".if_packets.rx", ir.Registry),
			PacketsOut: operating.NewGaugeDiff("interface-"+name+".if_packets.tx", ir.Registry),
		},
	}
	ir.PrivateInterfaceRegistry.Register(name, i) // error is ignored
	// errs when the type is not derived from (go-)metrics types
	return i
}
Example #7
0
func vagrantmachines() (*VagrantMachines, error) {
	currentUser, _ := user.Current()
	lockFilename := currentUser.HomeDir + "/.vagrant.d/data/machine-index/index.lock"
	indexFilename := currentUser.HomeDir + "/.vagrant.d/data/machine-index/index"

	lock_file, err := os.Open(lockFilename)
	if err != nil {
		return nil, err
	}
	if err := syscall.Flock(int(lock_file.Fd()), syscall.LOCK_EX); err != nil {
		return nil, err
	}
	defer syscall.Flock(int(lock_file.Fd()), syscall.LOCK_UN)

	open, err := os.Open(indexFilename) // text, err := ioutil.ReadFile(indexFilename)
	if err != nil {
		return nil, err
	}

	status := new(struct {
		Machines *map[string]operating.Vgmachine // the key is UUID
		// Version int // unused
	})
	if err := json.NewDecoder(open).Decode(status); err != nil { // json.Unmarshal(text, status)
		return nil, err
	}
	machines := new(VagrantMachines)
	if status.Machines != nil {
		for uuid, machine := range *status.Machines {
			machine.UUID = operating.Field(uuid)
			machines.List = append(machines.List, machine)
		}
	}
	machines.List.StableSortBy(LessVgmachine)
	return machines, nil
}