Пример #1
0
func NewIcmp(testMode bool, results publish.Transactions) (*Icmp, error) {
	icmp := &Icmp{}
	icmp.initDefaults()

	if !testMode {
		err := icmp.setFromConfig(config.ConfigSingleton.Protocols.Icmp)
		if err != nil {
			return nil, err
		}
	}

	var err error
	icmp.localIps, err = common.LocalIpAddrs()
	if err != nil {
		logp.Err("icmp", "Error getting local IP addresses: %s", err)
		icmp.localIps = []net.IP{}
	}
	logp.Debug("icmp", "Local IP addresses: %s", icmp.localIps)

	var removalListener = func(k common.Key, v common.Value) {
		icmp.expireTransaction(k.(hashableIcmpTuple), v.(*icmpTransaction))
	}

	icmp.transactions = common.NewCacheWithRemovalListener(
		icmp.transactionTimeout,
		protos.DefaultTransactionHashSize,
		removalListener)

	icmp.transactions.StartJanitor(icmp.transactionTimeout)

	icmp.results = results

	return icmp, nil
}
Пример #2
0
func (icmp *Icmp) init(results publish.Transactions, config *icmpConfig) error {
	icmp.setFromConfig(config)

	var err error
	icmp.localIps, err = common.LocalIpAddrs()
	if err != nil {
		logp.Err("icmp", "Error getting local IP addresses: %s", err)
		icmp.localIps = []net.IP{}
	}
	logp.Debug("icmp", "Local IP addresses: %s", icmp.localIps)

	var removalListener = func(k common.Key, v common.Value) {
		icmp.expireTransaction(k.(hashableIcmpTuple), v.(*icmpTransaction))
	}

	icmp.transactions = common.NewCacheWithRemovalListener(
		icmp.transactionTimeout,
		protos.DefaultTransactionHashSize,
		removalListener)

	icmp.transactions.StartJanitor(icmp.transactionTimeout)

	icmp.results = results

	return nil
}
Пример #3
0
// newHandleCache creates and returns a new handleCache that has been
// initialized (including starting a periodic janitor goroutine to purge
// expired Handles).
func newMessageFilesCache(eventLogName string, loader messageFileLoaderFunc,
	freer freeHandleFunc) *messageFilesCache {

	hc := &messageFilesCache{
		loader:       loader,
		freer:        freer,
		eventLogName: eventLogName,
	}
	hc.cache = common.NewCacheWithRemovalListener(expirationTimeout,
		initialSize, hc.evictionHandler)
	hc.cache.StartJanitor(janitorInterval)
	return hc
}
Пример #4
0
func (rpc *Rpc) init(results publish.Transactions, config *rpcConfig) error {
	rpc.setFromConfig(config)
	rpc.results = results
	rpc.callsSeen = common.NewCacheWithRemovalListener(
		rpc.transactionTimeout,
		protos.DefaultTransactionHashSize,
		func(k common.Key, v common.Value) {
			nfs, ok := v.(*Nfs)
			if !ok {
				logp.Err("Expired value is not a MapStr (%T).", v)
				return
			}
			rpc.handleExpiredPacket(nfs)
		})

	rpc.callsSeen.StartJanitor(rpc.transactionTimeout)
	return nil
}
Пример #5
0
func (dns *Dns) init(results publish.Transactions, config *dnsConfig) error {
	dns.setFromConfig(config)
	dns.transactions = common.NewCacheWithRemovalListener(
		dns.transactionTimeout,
		protos.DefaultTransactionHashSize,
		func(k common.Key, v common.Value) {
			trans, ok := v.(*DnsTransaction)
			if !ok {
				logp.Err("Expired value is not a *DnsTransaction.")
				return
			}
			dns.expireTransaction(trans)
		})
	dns.transactions.StartJanitor(dns.transactionTimeout)

	dns.results = results

	return nil
}
Пример #6
0
// newHandleCache creates and returns a new handleCache that has been
// initialized (including starting a periodic janitor goroutine to purge
// expired Handles).
func newMessageFilesCache(eventLogName string, loader messageFileLoaderFunc,
	freer freeHandleFunc) *messageFilesCache {

	size := &expvar.Int{}
	cacheStats.Set(eventLogName+"Size", size)

	hc := &messageFilesCache{
		loader:       loader,
		freer:        freer,
		eventLogName: eventLogName,
		hit:          func() { cacheStats.Add(eventLogName+"Hits", 1) },
		miss:         func() { cacheStats.Add(eventLogName+"Misses", 1) },
	}
	hc.cache = common.NewCacheWithRemovalListener(expirationTimeout,
		initialSize, hc.evictionHandler)
	hc.cache.StartJanitor(janitorInterval)
	hc.size = func() {
		s := hc.cache.Size()
		size.Set(int64(s))
		debugf("messageFilesCache[%s] size=%d", hc.eventLogName, s)
	}
	return hc
}
Пример #7
0
Файл: dns.go Проект: tsg/beats
func (dns *Dns) Init(test_mode bool, results publisher.Client) error {
	dns.initDefaults()
	if !test_mode {
		dns.setFromConfig(config.ConfigSingleton.Protocols.Dns)
	}

	dns.transactions = common.NewCacheWithRemovalListener(
		dns.transactionTimeout,
		protos.DefaultTransactionHashSize,
		func(k common.Key, v common.Value) {
			trans, ok := v.(*DnsTransaction)
			if !ok {
				logp.Err("Expired value is not a *DnsTransaction.")
				return
			}
			dns.expireTransaction(trans)
		})
	dns.transactions.StartJanitor(dns.transactionTimeout)

	dns.results = results

	return nil
}