Esempio n. 1
0
func main() {
	var (
		hosts     string
		community string
		sleep     int
		wg        sync.WaitGroup
	)

	m := metrics.New("")
	m.Option.StringVarP(&hosts, "hosts", "h", "127.0.0.1", "HOSTS")
	m.Option.StringVarP(&community, "community", "c", "public", "COMMUNITY")
	m.Option.IntVarP(&sleep, "sleep", "s", 1, "SLEEP")
	m.Init()

	for _, host := range strings.Split(hosts, ",") {
		wg.Add(1)

		go func(host string) {
			var port string

			beforeTraffics, err := snmpWalk(host, community)
			if err != nil {
				wg.Done()
				return
			}

			time.Sleep(time.Duration(sleep) * time.Second)

			afterTraffics, err := snmpWalk(host, community)
			if err != nil {
				wg.Done()
				return
			}

			tmp := metrics.New("").Hostname(host)
			for i := range beforeTraffics[0] {
				port = strconv.Itoa(i + 1)
				tmp.Scheme("snmp.rx_bytes." + port).Print(float64(afterTraffics[0][i] - beforeTraffics[0][i]))
				tmp.Scheme("snmp.tx_bytes." + port).Print(float64(afterTraffics[1][i] - beforeTraffics[1][i]))
			}

			wg.Done()
		}(host)
	}

	wg.Wait()
}
Esempio n. 2
0
func main() {
	m := metrics.New("disk.usage")

	usage, err := diskUsage()
	if err == nil {
		m.Print(usage)
	}
}
Esempio n. 3
0
func main() {
	m := metrics.New("memory.usage")

	usage, err := memoryUsage()
	if err == nil {
		m.Print(usage)
	}
}
Esempio n. 4
0
func main() {
	var sleep int

	m := metrics.New("cpu.usage")
	m.Option.IntVarP(&sleep, "sleep", "s", 1, "SLEEP")
	m.Init()

	usage, err := cpuUsage(sleep)
	if err == nil {
		m.Print(usage)
	}
}
func main() {
	var sleep int

	m := metrics.New("")
	m.Option.IntVarP(&sleep, "sleep", "s", 1, "SLEEP")
	m.Init()

	traffics, err := trafficsBytes(1)
	if err == nil {
		m.Scheme("traffic.rx_bytes").Print(float64(traffics[0]))
		m.Scheme("traffic.tx_bytes").Print(float64(traffics[1]))
	}
}