func (ic inodeChecker) inodeCheck(path string) (string, error) {
	d, err := linuxproc.ReadDisk(path)
	if err != nil {
		return "", fmt.Errorf("Cannot read disk info of %s file system.", path)
	}
	if d.FreeInodes < ic.threshold {
		return fmt.Sprintf("%d", d.FreeInodes), fmt.Errorf("Lack of free inodes on %s : %d (< %d)", path, d.FreeInodes, ic.threshold)
	}
	return fmt.Sprintf("%d", d.FreeInodes), nil
}
func (dff diskFreeChecker) diskSpaceCheck(path string) (string, error) {
	d, err := linuxproc.ReadDisk(path)
	if err != nil {
		return "", fmt.Errorf("Cannot read disk info of %s file system.", path)
	}
	pctAvail := (float64(d.Free) / float64(d.All) * 100)
	if pctAvail < dff.thresholdPercent {
		return fmt.Sprintf("%2.1f%%", pctAvail), fmt.Errorf("Low free space on %s. Free disk space: %2.1f%%", path, pctAvail)
	}
	return fmt.Sprintf("%2.1f%%", pctAvail), nil
}
Пример #3
0
func main() {
	uaid := os.Getenv("UAID")

	if uaid == "" {
		panic("UAID environment required. Example: UAID=UA-XXXXXX-Y ./server-analytics")
	}

	client, err := ga.NewClient(uaid)

	if err != nil {
		panic(err)
	}

	ticker := time.NewTicker(15 * time.Second)
	quit := make(chan struct{})
	stop := false

	for !stop {
		select {
		case <-ticker.C:
			diskInfo, err := linuxproc.ReadDisk("/")
			_ = err

			client.Send(ga.NewEvent("Disk", "All").Label("Total Disk Space").Value(int64(diskInfo.All)))
			client.Send(ga.NewEvent("Disk", "Used").Label("Used Disk Space").Value(int64(diskInfo.Used)))
			client.Send(ga.NewEvent("Disk", "Free").Label("Free Disk Space").Value(int64(diskInfo.Free)))

			loadAvg, err := linuxproc.ReadLoadAvg("/proc/loadavg")
			_ = err

			client.Send(ga.NewEvent("Load Average", "1m").Label("1m").Value(int64(loadAvg.Last1Min)))
			client.Send(ga.NewEvent("Load Average", "5m").Label("5m").Value(int64(loadAvg.Last5Min)))
			client.Send(ga.NewEvent("Load Average", "15m").Label("15m").Value(int64(loadAvg.Last15Min)))
			client.Send(ga.NewEvent("Load Average", "Running").Label("Process Running").Value(int64(loadAvg.ProcessRunning)))
			client.Send(ga.NewEvent("Load Average", "Total").Label("Process Total").Value(int64(loadAvg.ProcessTotal)))

			meminfo, err := linuxproc.ReadMemInfo("/proc/meminfo")
			_ = err

			client.Send(ga.NewEvent("Memory", "Total").Label("Memory Total").Value(int64(meminfo.MemTotal)))
			client.Send(ga.NewEvent("Memory", "Free").Label("Memory Free").Value(int64(meminfo.MemFree)))

		case <-quit:
			ticker.Stop()
			return
		}
	}
}
Пример #4
0
// Report resources.
func (d *Disk) Report() {
	for {
		select {
		case <-time.Tick(d.Interval):
			log.Info("disk: reporting")
			stat, err := linux.ReadDisk(d.Path)

			if err != nil {
				log.Error("disk: %s", err)
				continue
			}

			d.client.Gauge("percent", int(percent(stat.Used, stat.All)))
			d.client.Gauge("free", int(stat.Free))
			d.client.Gauge("used", int(stat.Used))

		case <-d.exit:
			log.Info("disk: exiting")
			return
		}
	}
}