Exemplo n.º 1
0
func New(instance, prefix_rates, prefix_timers, prefix_gauges, prefix_counters string, pct timers.Percentiles, flushInterval, max_unprocessed int, max_timers_per_s uint64, signalchan chan os.Signal, debug, legacy_namespace, flush_rates, flush_counts bool) *StatsDaemon {
	return &StatsDaemon{
		instance,
		"",
		"",
		"",
		"service_is_statsdaemon.instance_is_" + instance + ".",
		prefix_rates,
		prefix_counters,
		prefix_timers,
		prefix_gauges,
		legacy_namespace,
		flush_rates,
		flush_counts,
		pct,
		flushInterval,
		max_unprocessed,
		max_timers_per_s,
		signalchan,
		make(chan []*common.Metric, max_unprocessed),
		make(chan []*common.Metric, max_unprocessed),
		make(chan metricsStatsReq),
		topic.New(),
		topic.New(),
		topic.New(),
		debug,
		nil,
		nil,
		nil,
	}
}
Exemplo n.º 2
0
func main() {
	prog := path.Base(os.Args[0])
	log.SetFlags(0)
	log.SetPrefix(prog + ": ")

	flag.Usage = Usage
	flag.Parse()

	if flag.NArg() > 0 {
		Usage()
		os.Exit(1)
	}

	log.Printf("Serving at http://%s:%d/", *host, *port)

	chat := Chat{}
	chat.broadcast = topic.New()
	chat.registry = birpc.NewRegistry()
	chat.registry.RegisterService(&chat)
	defer close(chat.broadcast.Broadcast)
	upgrader := websocket.Upgrader{}

	serve := func(w http.ResponseWriter, req *http.Request) {
		ws, err := upgrader.Upgrade(w, req, nil)
		if err != nil {
			log.Println(err)
			return
		}
		endpoint := wetsock.NewEndpoint(chat.registry, ws)
		messages := make(chan interface{}, 10)
		chat.broadcast.Register(messages)
		go func() {
			defer chat.broadcast.Unregister(messages)
			for i := range messages {
				msg := i.(Outgoing)
				// Fire-and-forget.
				// TODO use .Notify when it exists
				_ = endpoint.Go("Chat.Message", msg, nil, nil)
			}
			// broadcast topic kicked us out for being too slow;
			// probably a hung TCP connection. let client
			// re-establish.
			log.Printf("Kicking slow client: %v", ws.RemoteAddr())
			ws.Close()
		}()

		if err := endpoint.Serve(); err != nil {
			log.Printf("websocket error from %v: %v", ws.RemoteAddr(), err)
		}
	}

	http.HandleFunc("/sock", serve)
	http.Handle("/", http.HandlerFunc(index))
	addr := fmt.Sprintf("%s:%d", *host, *port)
	err := http.ListenAndServe(addr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 3
0
Arquivo: store.go Projeto: hwhw/mesh
// open a bolt database file
func Open(file string) (b *DB, err error) {
	b = &DB{}
	b.DB, err = bolt.Open(file, 0600, nil)
	if err == nil {
		b.NotifyQuit = topic.New()
	}
	return
}
Exemplo n.º 4
0
Arquivo: nodedb.go Projeto: hwhw/mesh
// create a new database instance
func New(gluonvalid, visvalid time.Duration, storefile string, logfile string) (*NodeDB, error) {
	main, err := store.Open(storefile)
	if err != nil {
		return nil, err
	}
	logs, err := store.Open(logfile)
	if err != nil {
		return nil, err
	}

	db := NodeDB{
		Main:                   main,
		Logs:                   logs,
		NotifyPurgeVis:         topic.New(),
		NotifyUpdateNodeInfo:   topic.New(),
		NotifyUpdateStatistics: topic.New(),
		NotifyUpdateVis:        topic.New(),
		NotifyQuitUpdater:      topic.New(),
		NotifyQuitPurger:       topic.New(),
		NotifyQuitLogger:       topic.New(),
		validTimeGluon:         gluonvalid,
		validTimeVisData:       visvalid,
	}

	/*
		// run logging handlers
		db.Logger()
	*/

	return &db, nil
}
Exemplo n.º 5
0
func NullOutput() *Output {
	output := Output{
		Metrics:       make(chan *Metric),
		MetricAmounts: make(chan MetricAmount),
		Valid_lines:   topic.New(),
		Invalid_lines: topic.New(),
	}
	go func() {
		for {
			<-output.Metrics
		}
	}()
	go func() {
		for {
			<-output.MetricAmounts
		}
	}()
	return &output
}
Exemplo n.º 6
0
// return a new store instance
func NewStore(purgeAfter time.Duration, purgeInterval time.Duration) *Store {
	s := &Store{
		req:           make(chan interface{}),
		db:            make(map[string]map[uint8]*storeEntity),
		purgeAfter:    purgeAfter,
		purgeInterval: purgeInterval,
		NotifyUpdates: topic.New(),
	}
	go s.dispatch()
	return s
}
Exemplo n.º 7
0
func (tms *TopicMapStruct) Register(key string) chan interface{} {
	tms.Lock()
	t, ok := tms.m[key]
	if !ok {
		t = TopicMapEntry{topic.New(), 0}
		tms.m[key] = t
	}
	t.count++
	tms.Unlock()

	ch := make(chan interface{})
	t.t.Register(ch)
	return ch
}
Exemplo n.º 8
0
func New(instance, listen_addr, admin_addr, graphite_addr, prefix_rates, prefix_timers, prefix_gauges string, pct timers.Percentiles, flushInterval, max_unprocessed int, max_timers_per_s uint64, signalchan chan os.Signal, debug bool) *StatsDaemon {
	return &StatsDaemon{
		instance,
		listen_addr,
		admin_addr,
		graphite_addr,
		"service_is_statsdaemon.instance_is_" + instance + ".",
		prefix_rates,
		prefix_timers,
		prefix_gauges,
		pct,
		flushInterval,
		max_unprocessed,
		max_timers_per_s,
		signalchan,
		make(chan *common.Metric, max_unprocessed),
		make(chan common.MetricAmount, max_unprocessed),
		make(chan metricsStatsReq),
		topic.New(),
		topic.New(),
		topic.New(),
		debug,
	}
}
Exemplo n.º 9
0
)

type metricsStatsReq struct {
	Command []string
	Conn    *net.Conn
}

var (
	Metrics             = make(chan *common.Metric, MAX_UNPROCESSED_PACKETS)
	metricAmounts       = make(chan common.MetricAmount)
	metricStatsRequests = make(chan metricsStatsReq)
	counters            = make(map[string]float64)
	gauges              = make(map[string]float64)
	timers              = make(map[string]timer.Data)
	prefix_internal     string
	valid_lines         = topic.New()
	invalid_lines       = topic.New()
	// currently only used for flush
	events = topic.New()
)

// metricsMonitor basically guards the metrics datastructures.
// it typically receives metrics on the Metrics channel but also responds to
// external signals and every flushInterval, computes and flushes the data
func metricsMonitor() {
	period := time.Duration(*flushInterval) * time.Second
	ticker := time.NewTicker(period)
	for {
		select {
		case sig := <-signalchan:
			switch sig {