Beispiel #1
0
// createUnit implements the UnitFactory interface.
func (this *HostCpuUnitFactory) createUnit() Unit {
	u := &HostCpuUnit{
		lastCPUUsage: make([]float64, 8),
		newCPUUsage:  make([]float64, 8),

		metrics: []model.Metric{
			model.NewGauge("host.cpu.user").AddTag("hostname", hostname),
			model.NewGauge("host.cpu.nice").AddTag("hostname", hostname),
			model.NewGauge("host.cpu.system").AddTag("hostname", hostname),
			model.NewGauge("host.cpu.idle").AddTag("hostname", hostname),
			model.NewGauge("host.cpu.iowait").AddTag("hostname", hostname),
			model.NewGauge("host.cpu.irq").AddTag("hostname", hostname),
			model.NewGauge("host.cpu.softirq").AddTag("hostname", hostname),

			//			model.NewCounter("host.stat.intr").AddTag("hostname", hostname),
			//			model.NewCounter("host.stat.ctxt").AddTag("hostname", hostname),
			//			model.NewGauge("host.stat.btime").AddTag("hostname", hostname),
			//			model.NewCounter("host.stat.processes").AddTag("hostname", hostname),
			//			model.NewGauge("host.stat.procs_running").AddTag("hostname", hostname),
			//			model.NewGauge("host.stat.procs_blocked").AddTag("hostname", hostname),
		},
	}
	u.name = UNIT_NAME_HOST_CPU
	u.fetchStop = make(chan struct{})
	u.BaseUnit.unit = u

	go func() {
		err := u.updateStats()
		if err != nil {
			log.Errorf("update cpu stats error: ", err)
		}
		ticker := time.NewTicker(time.Second)
		for {
			select {
			case <-ticker.C:
				err = u.updateStats()
				if err != nil {
					log.Errorf("update cpu stats error: ", err)
				}
			}
		}
	}()

	return u
}
Beispiel #2
0
func (this *HostMemoryUnitFactory) createUnit() Unit {
	u := &HostMemoryUnit{
		metrics: []model.Metric{
			model.NewGauge("host.mem.total").AddTag("hostname", hostname),
			model.NewGauge("host.mem.free").AddTag("hostname", hostname),
			model.NewGauge("host.mem.available").AddTag("hostname", hostname),
			model.NewGauge("host.mem.app").AddTag("hostname", hostname),
			model.NewGauge("host.mem.os").AddTag("hostname", hostname),
			model.NewGauge("host.mem.buffers").AddTag("hostname", hostname),
			model.NewGauge("host.mem.cached").AddTag("hostname", hostname),
			model.NewGauge("host.mem.used").AddTag("hostname", hostname),
			model.NewGauge("host.mem.swaptotal").AddTag("hostname", hostname),
			model.NewGauge("host.mem.swapfree").AddTag("hostname", hostname),
			model.NewGauge("host.mem.swapused").AddTag("hostname", hostname),
			model.NewGauge("host.mem.free.percent").AddTag("hostname", hostname),
			model.NewGauge("host.mem.used.percent").AddTag("hostname", hostname),
			model.NewGauge("host.mem.swapfree.percent").AddTag("hostname", hostname),
			model.NewGauge("host.mem.swapused.percent").AddTag("hostname", hostname),
		},
	}
	u.name = UNIT_NAME_HOST_MEM
	u.fetchStop = make(chan struct{})
	u.BaseUnit.unit = u
	return u
}