Exemple #1
0
func (p ubuntu) GetSwapStats() (stats MemStats, err error) {
	swap := sigar.Swap{}
	err = swap.Get()
	if err != nil {
		return
	}

	stats.Total = swap.Total
	stats.Used = swap.Used

	return
}
func (s sigarStatsCollector) GetSwapStats() (stats MemStats, err error) {
	swap := sigar.Swap{}
	err = swap.Get()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Sigar Swap")
		return
	}

	stats.Total = swap.Total
	stats.Used = swap.Used

	return
}
func (s sigarStatsCollector) GetSwapStats() (usage Usage, err error) {
	swap := sigar.Swap{}
	err = swap.Get()
	if err != nil {
		err = bosherr.WrapError(err, "Getting Sigar Swap")
		return
	}

	usage.Total = swap.Total
	usage.Used = swap.Used

	return
}
Exemple #4
0
func postMetrics() error {
	var metrics = make(map[string]interface{})
	// Runtime Info
	metrics["agent.runtime.numcpu"] = runtime.NumCPU()
	metrics["agent.runtime.numgoroutine"] = runtime.NumGoroutine()

	// System Info
	avg := sigar.LoadAverage{}
	mem := sigar.Mem{}
	swap := sigar.Swap{}
	avg.Get()
	mem.Get()
	swap.Get()

	metrics["agent.system.loadavg.one"] = avg.One
	metrics["agent.system.loadavg.five"] = avg.Five
	metrics["agent.system.loadavg.fifteen"] = avg.Fifteen
	metrics["agent.system.mem.total"] = mem.Total
	metrics["agent.system.mem.used"] = mem.Used
	metrics["agent.system.mem.free"] = mem.Free
	metrics["agent.system.mem.actual_used"] = mem.ActualUsed
	metrics["agent.system.mem.actual_free"] = mem.ActualFree
	metrics["agent.system.swap.total"] = swap.Total
	metrics["agent.system.swap.used"] = swap.Used
	metrics["agent.system.swap.free"] = swap.Free

	// Disk Info
	fslist := sigar.FileSystemList{}
	fslist.Get()
	for _, fs := range fslist.List {
		if strings.HasPrefix(fs.DevName, "/") {
			dirname := fs.DirName
			usage := sigar.FileSystemUsage{}
			usage.Get(dirname)
			metrics[fmt.Sprintf("agent.disk.%s.total", dirname)] = usage.Total
			metrics[fmt.Sprintf("agent.disk.%s.used", dirname)] = usage.Used
			metrics[fmt.Sprintf("agent.disk.%s.avail", dirname)] = usage.Avail
			metrics[fmt.Sprintf("agent.disk.%s.used_percent", dirname)] = usage.UsePercent()
		}
	}

	if client, err := models.NewCounterClient(nil); err != nil {
		return err
	} else {
		return client.PostMany("statsd", metrics)
	}
}
WritebackTmp:          0 kB
CommitLimit:      973556 kB
Committed_AS:      55880 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       21428 kB
VmallocChunk:   34359713596 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       59328 kB
DirectMap2M:      333824 kB
`
			err := ioutil.WriteFile(meminfoFile, []byte(meminfoContents), 0444)
			Expect(err).ToNot(HaveOccurred())
		})

		It("returns correct memory info", func() {
			swap := sigar.Swap{}
			err := swap.Get()
			Expect(err).ToNot(HaveOccurred())

			Expect(swap.Total).To(BeNumerically("==", 786428*1024))
			Expect(swap.Free).To(BeNumerically("==", 786428*1024))
		})
	})
})