Ejemplo n.º 1
0
func NewManager(sources []source_api.Source, sinkManager sinks.ExternalSinkManager, res, bufferDuration time.Duration, c cache.Cache, useModel bool, modelRes time.Duration) (Manager, error) {
	var newModel model.Model = nil
	if useModel {
		newModel = model.NewModel(modelRes)
		// Temporary semi-hack to get model storage garbage-collected.
		c.AddCacheListener(newModel.GetCacheListener())
	}
	return &realManager{
		sources:      sources,
		sinkManager:  sinkManager,
		cache:        c,
		model:        newModel,
		lastSync:     time.Now(),
		resolution:   res,
		decoder:      sink_api.NewDecoder(),
		sinkStopChan: sinkManager.Sync(),
	}, nil
}
Ejemplo n.º 2
0
func getNodeMetrics(model model_api.Model, name string) (*types.DerivedNodeMetrics, error) {
	res, err := model.GetNodeStats(model_api.NodeRequest{
		NodeName: name,
	})
	if err != nil {
		return nil, err
	}
	metrics := &types.DerivedNodeMetrics{
		NodeName: name,
		NodeMetrics: types.MetricsWindows{
			EndTime: unversioned.NewTime(res.Timestamp),
		},
		// TODO: fill SystemContainers
		SystemContainers: make([]types.DerivedContainerMetrics, 0),
	}
	if err := portStats(&metrics.NodeMetrics, res.ByName); err != nil {
		return nil, err
	}
	return metrics, nil
}