Esempio n. 1
0
func (c *CommSFlowClass) handleHostCounters(record sflow.Record) {
	m := &message.Message{
		Class:     "host-counters",
		Timestamp: clock.Time(),
		Content:   record,
	}
	switch record.(type) {
	case sflow.HostCPUCounters:
		m.Type = "CPU"
	case sflow.HostMemoryCounters:
		m.Type = "Memory"
	case sflow.HostDiskCounters:
		m.Type = "Disk"
	case sflow.HostNetCounters:
		m.Type = "Net"
	default:
		return
	}
	c.outbound <- m
}
Esempio n. 2
0
// processMessages delivers messages from internal device classes to
// other internal device classes, or escalates them to the global
// channel.
func (d *Device) processMessages() {
	for m := range d.internalMessages {
		if m.Timestamp == 0 {
			m.Timestamp = clock.Time()
		}
		if m.Global {
			// m is intended for a global class.
			select {
			case d.globalMessages <- m:
			default:
				// Drop.
			}
			continue
		}
		if !d.HasClass(m.Class) {
			log.Printf("  %v does not have class \"%s\" registered", d, m.Class)
			switch m.Class {
			case InfoHostCountersClassName:
				d.RegisterClass(NewInfoHostCountersClass(d.address, d.internalMessages))
			case InfoSwitchCountersClassName:
				d.RegisterClass(NewInfoSwitchCountersClass(d.address, d.internalMessages))
			case InfoFlowClassName:
				d.RegisterClass(NewInfoFlowClass(d.address, d.internalMessages))
			case InfoMetricsClassName:
				d.RegisterClass(NewInfoMetricsClass(d.metrics, d.address, d.internalMessages))
			case InfoDebugClassName:
				d.RegisterClass(NewInfoDebugClass())
			default:
				continue
			}
		}
		c := d.classes[m.Class]
		if processor, ok := c.(message.Processor); ok {
			processor.Process(m)
		}
	}
}