Example #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
}
Example #2
0
func (tm *TaskManager) handleUnitUpdates(taskCfg *config.TaskConfig, ch <-chan *config.UnitConfig) {
	for unitCfg := range ch {
		//		log.Debugf("Received potential update for unit config %s", unitCfg.Identity)
		err := tm.updateUnits(unitCfg, taskCfg)
		if err != nil {
			log.Errorf("Error updating units: %s", err)
		}
	}
	log.Debug("handleUnitUpdates finished.")
}
Example #3
0
func reloadConfig(filename string, rls ...Reloadable) bool {
	log.Infof("Loading configuration file %s", filename)

	cfg, err := config.LoadConfig(filename)
	if err != nil {
		log.Errorf("Failed to load configuration file (-config.file=%s): %v", filename, err)
		return false
	}

	for _, rl := range rls {
		rl.ApplyConfig(cfg)
	}

	return true
}
Example #4
0
func (this *PublisherType) publishMetric(metric model.Metric) {
	ts, ok := metric["timestamp"].(model.Time)
	if !ok {
		log.Error("Missing 'timestamp' field in metric.")
	}

	_, ok = metric["type"].(string)
	if !ok {
		log.Error("Missing 'type' field in metric.")
	}

	for name, output := range this.Outputs {
		// TODO Try to concurrency publish.
		err := output.PublishMetric(time.Time(ts), metric)
		if err != nil {
			log.Errorf("Fail to publish metric on output: %s, error: %s", name, err)
		}
	}
}