Esempio n. 1
0
func (p *ProcUptime) Run() error {
	uptime, err := linuxproc.ReadUptime("/proc/uptime")
	if err != nil {
		return err
	}

	p.Data = uptime
	return nil
}
Esempio n. 2
0
func ProducerRunFuction(producer *producers.GenericProducer) events.Event {

	uptime, err := linuxproc.ReadUptime("/proc/uptime")
	if err != nil {
		log.Fatal("Failed while getting uptime")
	}

	load, err := linuxproc.ReadLoadAvg("/proc/loadavg")
	if err != nil {
		log.Fatal("Failed while getting uptime")
	}

	uptimeStr := fmt.Sprintf("Up:%v ", time.Duration(time.Duration(int64(uptime.Total))*time.Second).String())
	loadStr := fmt.Sprintf("Load:%v %v %v", load.Last1Min, load.Last5Min, load.Last15Min)
	return events.Event{uptimeStr + loadStr, producer.Name, time.Now(), events.PRIORITY_LOW}

}
Esempio n. 3
0
func uptime() {
	for {
		//http://stackoverflow.com/questions/6807590/how-to-stop-a-goroutine
		select {
		case <-H.quit:
			return
		default:

		}

		uptime, err := linuxproc.ReadUptime("/proc/uptime")
		if err != nil {
			return
		}

		msg, _ := json.Marshal(&map[string]interface{}{"uptime_total": fmt.Sprintf("%s", uptime.GetTotalDuration()), "uptime_idle": fmt.Sprintf("%s", uptime.GetIdleDuration())})
		H.broadcast <- []byte(msg)

		time.Sleep(time.Second * 1)
	}
}