Example #1
0
func activateEndpoints(endpoints []*scotty.Endpoint, s *store.Store) {
	aMetric := metrics.SimpleList{
		{
			Path:        "/foo/first",
			Description: "A description",
		},
		{
			Path:        "/foo/second",
			Description: "A description",
		},
		{
			Path:        "/foo/third",
			Description: "A description",
		},
		{
			Path:        "/foo/fourth",
			Description: "A description",
		},
	}
	for i := range aMetric {
		aMetric[i].Value = int64(i)
	}
	for i := range endpoints {
		s.AddBatch(endpoints[i], 1.0, aMetric[:])
	}
}
Example #2
0
func latestMetricsForEndpoint(
	metricStore *store.Store,
	app *datastructs.ApplicationStatus,
	canonicalPath string,
	json bool) (result []*messages.LatestMetric) {
	var appender store.Appender
	if json {
		appender = &latestMetricsAppenderJSON{
			result:   &result,
			hostName: app.EndpointId.HostName(),
			appName:  app.Name,
		}
	} else {
		appender = &latestMetricsAppender{
			result:   &result,
			hostName: app.EndpointId.HostName(),
			appName:  app.Name,
		}
	}
	metricStore.LatestByPrefixAndEndpointStrategy(
		canonicalPath,
		app.EndpointId,
		store.GroupMetricByPathAndNumeric,
		store.AppenderFilterFunc(
			appender,
			func(r *store.Record) bool {
				return r.Info.Path() == canonicalPath || strings.HasPrefix(
					r.Info.Path(), canonicalPath+"/")
			},
		),
	)
	sort.Sort(latestByPath(result))
	return
}
Example #3
0
func (p *pstoreHandlerType) EndVisit(theStore *store.Store) {
	p.consumer.Flush()
	p.visitorMetricsStore.SetTimeLeft(
		duration.FromFloat(theStore.TimeLeft(p.iteratorName())))
	totalTime := time.Now().Sub(p.startTime)
	p.totalTimeSpentDist.Add(totalTime)

}
Example #4
0
func createApplicationStats(
	appList *datastructs.ApplicationList,
	logger *log.Logger,
	tagvAdder suggest.Adder,
	maybeNilMemoryManager *memoryManagerType) *datastructs.ApplicationStatuses {
	var astore *store.Store
	fmt.Println("Initialization started.")
	if maybeNilMemoryManager != nil {
		memoryManager := maybeNilMemoryManager
		astore = store.NewStoreBytesPerPage(
			*fBytesPerPage,
			1,
			*fThreshhold,
			*fDegree)
		astore.SetExpanding(true)
		memoryManager.SetMemory(astore)
		if err := memoryManager.RegisterMetrics(); err != nil {
			log.Fatal(err)
		}
	} else {
		astore = store.NewStoreBytesPerPage(
			*fBytesPerPage, *fPageCount, *fThreshhold, *fDegree)
	}
	dirSpec, err := tricorder.RegisterDirectory("/store")
	if err != nil {
		log.Fatal(err)
	}
	if err := astore.RegisterMetrics(dirSpec); err != nil {
		log.Fatal(err)
	}
	stats := datastructs.NewApplicationStatuses(appList, astore)
	mdbChannel := mdbd.StartMdbDaemon(*fMdbFile, logger)
	machines := <-mdbChannel
	theHostNames := hostNames(machines.Machines)
	for _, aName := range theHostNames {
		tagvAdder.Add(aName)
	}
	stats.MarkHostsActiveExclusively(
		duration.TimeToFloat(time.Now()), theHostNames)
	fmt.Println("Initialization complete.")
	// Endpoint refresher goroutine
	go func() {
		for {
			machines := <-mdbChannel
			stats.MarkHostsActiveExclusively(
				duration.TimeToFloat(time.Now()),
				hostNames(machines.Machines))
		}
	}()
	return stats
}
Example #5
0
func (a *activeInactiveListType) Visit(
	s *store.Store, endpoint interface{}) error {
	a.activeFound = false
	s.LatestByEndpoint(endpoint, a)
	scottyEndpoint := endpoint.(*scotty.Endpoint)
	hostPortStr := fmt.Sprintf(
		"%s:%d", scottyEndpoint.HostName(), scottyEndpoint.Port())
	if a.activeFound {
		a.Active[hostPortStr] = true
	} else {
		a.Inactive[hostPortStr] = true
	}
	return nil
}
Example #6
0
func createNamedIterator(
	theStore *store.Store,
	endpointId interface{},
	iteratorName string,
	rollUpSpan time.Duration) (store.NamedIterator, float64) {
	if rollUpSpan == 0 {
		return theStore.NamedIteratorForEndpoint(
			iteratorName,
			endpointId,
			kLookAheadWritingToPStore,
		)
	}
	// TODO: Strategy hard coded for now, but really the pstore writer
	// in use should dictate the grouping strategy. For now, all our
	// pstore writers convert numeric metrics to float64 which is why
	// the store.GroupByPathAndNumeric strategy works for now.
	return theStore.NamedIteratorForEndpointRollUp(
		iteratorName,
		endpointId,
		rollUpSpan,
		kLookAheadWritingToPStore,
		store.GroupMetricByPathAndNumeric,
	)
}
Example #7
0
func addValues(
	t *testing.T,
	aStore *store.Store,
	endpointId interface{},
	path string,
	data ...float64) {
	if len(data)%2 != 0 {
		t.Fatal("Timestamp value pairs expected")
	}
	aMetric := metrics.SimpleList{
		{
			Path:        path,
			Description: "A description",
		},
	}
	dataLen := len(data)
	for i := 0; i < dataLen; i += 2 {
		aMetric[0].TimeStamp = duration.FloatToTime(data[i])
		aMetric[0].Value = data[i+1]
		if _, err := aStore.AddBatch(endpointId, 1000.0, aMetric); err != nil {
			t.Fatal(err)
		}
	}
}
Example #8
0
// gatherDataForEndpoint serves api/hosts pages.
// metricStore is the metric store.
// endpoint is the endpoint from which we are getting historical metrics.
// canonicalPath is the path of the metrics or the empty string for all
// metrics. canonicalPath is returned from canonicalisePath().
// history is the amount of time to go back in minutes.
// If isSingleton is true, fetched metrics have to match canonicalPath
// exactly.
// Otherwise fetched metrics have to be found underneath canonicalPath.
// On no match, gatherDataForEndpoint returns an empty
// messages.EndpointMetricsList instance
func gatherDataForEndpoint(
	metricStore *store.Store,
	endpoint *collector.Endpoint,
	canonicalPath string,
	history int,
	isSingleton bool) (result messages.EndpointMetricList) {
	result = make(messages.EndpointMetricList, 0)
	now := duration.TimeToFloat(time.Now())
	appender := newEndpointMetricsAppender(&result)
	if canonicalPath == "" {
		metricStore.ByEndpointStrategy(
			endpoint,
			now-60.0*float64(history),
			math.Inf(1),
			store.GroupMetricByKey,
			appender)
	} else {
		metricStore.ByNameAndEndpointStrategy(
			canonicalPath,
			endpoint,
			now-60.0*float64(history),
			math.Inf(1),
			store.GroupMetricByKey,
			appender)
		if len(result) == 0 && !isSingleton {
			metricStore.ByPrefixAndEndpointStrategy(
				canonicalPath+"/",
				endpoint,
				now-60.0*float64(history),
				math.Inf(1),
				store.GroupMetricByKey,
				appender)
		}

	}
	sortMetricsByPath(result)
	return
}