Esempio n. 1
0
// NewReportLIFO XXX
func NewReportLIFO(r reporter, maxAge time.Duration) *ReportLIFO {
	l := ReportLIFO{
		reports:  []timedReport{},
		requests: make(chan chan report.Report),
		quit:     make(chan chan struct{}),
	}

	go func() {
		for {
			select {
			case report := <-r.Reports():
				tr := timedReport{
					Timestamp: time.Now(),
					Report:    report,
				}
				l.reports = append(l.reports, tr)
				l.reports = cleanOld(l.reports, time.Now().Add(-maxAge))

			case req := <-l.requests:
				report := report.MakeReport()
				for _, r := range l.reports {
					report.Merge(r.Report)
				}
				req <- report

			case q := <-l.quit:
				close(q)
				return
			}
		}
	}()
	return &l
}
Esempio n. 2
0
// Report returns a merged report over all added reports. It implements
// Reporter.
func (c *Collector) Report() report.Report {
	c.mtx.Lock()
	defer c.mtx.Unlock()

	c.reports = clean(c.reports, c.window)

	report := report.MakeReport()
	for _, tr := range c.reports {
		report.Merge(tr.report)
	}
	return report
}
Esempio n. 3
0
File: main.go Progetto: neviim/scope
func main() {
	var (
		defaultProbes = fmt.Sprintf("localhost:%d", xfer.ProbePort)
		probes        = flag.String("probes", defaultProbes, "list of probe endpoints, comma separated")
	)
	flag.Parse()
	if len(flag.Args()) != 0 {
		flag.Usage()
		os.Exit(1)
	}

	// Collector deals with the probes, and generates merged reports.
	xfer.MaxBackoff = 1 * time.Second
	c := xfer.NewCollector(1*time.Second, "id")
	for _, addr := range strings.Split(*probes, ",") {
		c.Add(addr)
	}
	defer c.Stop()

	report := report.MakeReport()
	irq := interrupt()
OUTER:
	for {
		select {
		case r := <-c.Reports():
			report.Merge(r)
		case <-irq:
			break OUTER
		}
	}

	b, err := json.Marshal(report)
	if err != nil {
		panic(err)
	}
	fmt.Print(string(b))
}