Esempio n. 1
0
func (m *Monitor) Run(mon *monitor.Monitor) {
	this_time := time.Now()

	statistics, err := Statistics()
	if err != nil {
		log.Fatal(err)
	}

	var progressiveStats []ProgressiveStat
	for _, stat := range statistics {
		if stat.In > 0 || stat.Out > 0 {
			last_stat := m.last_statistics[stat.Host]
			time_diff := float64(this_time.Sub(m.last_time).Nanoseconds()) / 1000000000

			bytes_per_second_in := float64(stat.In-last_stat.In) / time_diff
			bytes_per_second_out := float64(stat.Out-last_stat.Out) / time_diff

			stat := ProgressiveStat{
				stat,
				this_time,
				uint64(bytes_per_second_in),
				uint64(bytes_per_second_out),
			}
			progressiveStats = append(progressiveStats, stat)
		}
	}

	if !m.last_time.IsZero() {
		mon.SendData(progressiveStats)
	}

	m.last_time = this_time
	m.last_statistics = statistics
}
Esempio n. 2
0
func (mon *Monitor) Run(m *monitor.Monitor) {
	memory := GetMemoryStats()

	lanEth, _ := net.InterfaceByName("eth1")
	wanEth, _ := net.InterfaceByName("eth0")

	iData := InterfaceData{lanEth, wanEth}

	mon1 := HWMon{"hwmon0", []string{"2", "3"}}
	mon2 := HWMon{"hwmon1", []string{"1"}}

	temps1, err := mon1.Temperatures()
	if err != nil {
		panic(err)
	}
	temps2, err := mon2.Temperatures()
	if err != nil {
		panic(err)
	}

	allTemps := make(map[string]float64)
	for key, value := range temps1 {
		allTemps[key] = value
	}

	for key, value := range temps2 {
		allTemps[key] = value
	}

	data := Data{memory, iData, allTemps}

	m.SendData(&data)
}
Esempio n. 3
0
func trafficServer(es eventsource.EventSource, tm *monitor.Monitor) {
	ch := make(chan interface{}, 1)
	tm.RegisterChannel(ch)

	for item := range ch {
		stats := item.([]traffic.ProgressiveStat)

		json, _ := json.Marshal(stats)
		es.SendMessage(string(json), "", "")
	}
}
Esempio n. 4
0
func systemDataServer(es eventsource.EventSource, sm *monitor.Monitor) {
	ch := make(chan interface{}, 1)
	sm.RegisterChannel(ch)
	sm.Force()
	for item := range ch {
		data := item.(*system.Data)

		var lanIPs []string
		var wanIPs []string

		lanAddrs, _ := data.Interfaces.LAN.Addrs()
		wanAddrs, _ := data.Interfaces.WAN.Addrs()

		for _, addr := range lanAddrs {
			lanIPs = append(lanIPs, addr.String())
		}

		for _, addr := range wanAddrs {
			wanIPs = append(wanIPs, addr.String())
		}

		dataToSerialize := struct {
			Memory       system.MemoryStats
			Temperatures map[string]float64
			Interfaces   dataInterfaces
		}{
			data.Memory,
			data.Temperatures,
			dataInterfaces{
				dataInterface{
					data.Interfaces.LAN.HardwareAddr.String(),
					lanIPs,
				},
				dataInterface{
					data.Interfaces.WAN.HardwareAddr.String(),
					wanIPs,
				},
			},
		}
		json, _ := json.Marshal(dataToSerialize)
		es.SendMessage(string(json), "", "")
	}
}