Exemplo n.º 1
0
func NewSinglePingCollector(name, prefix string, conf config.Config_single_pinger) *ping_collector {

	if conf.Target == "" {
		logging.Critical("CRITICAL: we cannot ping empty target.")
	}

	tags := conf.Tags.Copy()
	tags["target"] = conf.Target

	if conf.Packets <= 0 {
		conf.Packets = 1
	}

	c := &ping_collector{
		name:    name,
		enabled: true,
		config:  conf,
		prefix:  prefix,

		interval: conf.Interval.MustDuration(time.Second),
		timeout:  conf.Timeout.MustDuration(time.Millisecond * 500),
		tags:     tags,
	}
	return c
}
Exemplo n.º 2
0
func MustNewPingCollectors(name, prefix string, conf config.Config_Ping) []*ping_collector {
	var sconf config.Config_single_pinger
	var pings []*ping_collector

	sconf.Interval = conf.Interval
	sconf.Metric = conf.Metric
	sconf.Packets = conf.Packets
	sconf.Tags = conf.Tags
	sconf.Timeout = conf.Timeout

	for idx, target := range conf.Targets {
		sconf.Target = target
		ping := NewSinglePingCollector(fmt.Sprintf("%s_%d", name, idx), prefix, sconf)
		pings = append(pings, ping)
	}
	return pings
}