本文整理汇总了Golang中github.com/google/cadvisor/cache/memory.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: New
// Creates a cAdvisor and exports its API on the specified port if port > 0.
func New(port uint) (Interface, error) {
sysFs, err := sysfs.NewRealSysFs()
if err != nil {
return nil, err
}
// Create and start the cAdvisor container manager.
m, err := manager.New(memory.New(statsCacheDuration, nil), sysFs)
if err != nil {
return nil, err
}
cadvisorClient := &cadvisorClient{
Manager: m,
}
// Export the HTTP endpoint if a port was specified.
if port > 0 {
err = cadvisorClient.exportHTTP(port)
if err != nil {
return nil, err
}
}
return cadvisorClient, nil
}
开发者ID:qingyuancloud,项目名称:qingyuan,代码行数:26,代码来源:cadvisor_linux.go
示例2: New
// Creates a cAdvisor and exports its API on the specified port if port > 0.
func New(backendStorageName string, port uint) (Interface, error) {
backendStorage, err := NewBackendStorage(backendStorageName)
if err != nil {
glog.Fatalf("Failed to connect to database: %s", err)
}
sysFs, err := sysfs.NewRealSysFs()
if err != nil {
return nil, err
}
// Create and start the cAdvisor container manager.
m, err := manager.New(memory.New(statsCacheDuration, backendStorage), sysFs, maxHousekeepingInterval, allowDynamicHousekeeping, cadvisorMetrics.MetricSet{cadvisorMetrics.NetworkTcpUsageMetrics: struct{}{}})
if err != nil {
return nil, err
}
cadvisorClient := &cadvisorClient{
Manager: m,
}
err = cadvisorClient.exportHTTP(port)
if err != nil {
return nil, err
}
return cadvisorClient, nil
}
开发者ID:xachca,项目名称:kubernetes-1.2,代码行数:27,代码来源:cadvisor_linux.go
示例3: NewMemoryStorage
// NewMemoryStorage creates a memory storage with an optional backend storage option.
func NewMemoryStorage() (*memory.InMemoryCache, error) {
backendStorage, err := storage.New(*storageDriver)
if err != nil {
return nil, err
}
if *storageDriver != "" {
glog.Infof("Using backend storage type %q", *storageDriver)
}
glog.Infof("Caching stats in memory for %v", *storageDuration)
return memory.New(*storageDuration, backendStorage), nil
}
开发者ID:hyperhq,项目名称:cadvisor,代码行数:12,代码来源:storagedriver.go
示例4: NewMemoryStorage
// NewMemoryStorage creates a memory storage with an optional backend storage option.
func NewMemoryStorage(backendStorageName string) (*memory.InMemoryCache, error) {
backendStorage, err := storage.New(backendStorageName)
if err != nil {
return nil, err
}
if backendStorageName != "" {
glog.Infof("Using backend storage type %q", backendStorageName)
}
glog.Infof("Caching stats in memory for %v", *storageDuration)
storageDriver := memory.New(*storageDuration, backendStorage)
return storageDriver, nil
}
开发者ID:normanjoyner,项目名称:cadvisor,代码行数:13,代码来源:storagedriver.go
示例5: setupContainerData
// Create a containerData instance for a test.
func setupContainerData(t *testing.T, spec info.ContainerSpec) (*containerData, *container.MockContainerHandler, *memory.InMemoryCache) {
mockHandler := container.NewMockContainerHandler(containerName)
mockHandler.On("GetSpec").Return(
spec,
nil,
)
memoryCache := memory.New(60, nil)
ret, err := newContainerData(containerName, memoryCache, mockHandler, false, &collector.GenericCollectorManager{}, 60*time.Second, true)
if err != nil {
t.Fatal(err)
}
return ret, mockHandler, memoryCache
}
开发者ID:chrisdo,项目名称:cadvisor,代码行数:14,代码来源:container_test.go
示例6: initContainerManager
func initContainerManager() {
sysFs, err := sysfs.NewRealSysFs()
if err != nil {
log.Infof("stats: failed to create a system interface (%v)", err)
return
}
// TODO: support influxdb or other backend storage
cmgr, err = manager.New(memory.New(storageDuration, nil), sysFs, maxHousekeepingInterval, allowDynamicHousekeeping)
if err != nil {
log.Infof("stats: failed to create a container Manager (%v)", err)
return
}
if err := cmgr.Start(); err != nil {
log.Infof("stats: failed to start container manager (%v)", err)
return
}
}
开发者ID:wangtuanjie,项目名称:cfs,代码行数:17,代码来源:container.go
示例7: expectManagerWithContainers
// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
// and map of MockContainerHandler objects.}
func expectManagerWithContainers(containers []string, query *info.ContainerInfoRequest, t *testing.T) (*manager, map[string]*info.ContainerInfo, map[string]*container.MockContainerHandler) {
infosMap := make(map[string]*info.ContainerInfo, len(containers))
handlerMap := make(map[string]*container.MockContainerHandler, len(containers))
for _, container := range containers {
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
}
memoryCache := memory.New(time.Duration(query.NumStats)*time.Second, nil)
sysfs := &fakesysfs.FakeSysFs{}
m := createManagerAndAddContainers(
memoryCache,
sysfs,
containers,
func(h *container.MockContainerHandler) {
cinfo := infosMap[h.Name]
ref, err := h.ContainerReference()
if err != nil {
t.Error(err)
}
for _, stat := range cinfo.Stats {
err = memoryCache.AddStats(ref, stat)
if err != nil {
t.Error(err)
}
}
spec := cinfo.Spec
h.On("ListContainers", container.ListSelf).Return(
[]info.ContainerReference(nil),
nil,
)
h.On("GetSpec").Return(
spec,
nil,
)
handlerMap[h.Name] = h
},
t,
)
return m, infosMap, handlerMap
}
开发者ID:RomainVabre,项目名称:origin,代码行数:45,代码来源:manager_test.go
示例8: New
// Creates a cAdvisor and exports its API on the specified port if port > 0.
func New(port uint) (Interface, error) {
sysFs, err := sysfs.NewRealSysFs()
if err != nil {
return nil, err
}
// Create and start the cAdvisor container manager.
m, err := manager.New(memory.New(statsCacheDuration, nil), sysFs, maxHousekeepingInterval, allowDynamicHousekeeping)
if err != nil {
return nil, err
}
cadvisorClient := &cadvisorClient{
Manager: m,
}
err = cadvisorClient.exportHTTP(port)
if err != nil {
return nil, err
}
return cadvisorClient, nil
}
开发者ID:alena1108,项目名称:kubernetes,代码行数:23,代码来源:cadvisor_linux.go
示例9: New
// Creates a cAdvisor and exports its API on the specified port if port > 0.
func New(port uint, runtime string) (Interface, error) {
sysFs, err := sysfs.NewRealSysFs()
if err != nil {
return nil, err
}
// Create and start the cAdvisor container manager.
m, err := manager.New(memory.New(statsCacheDuration, nil), sysFs, maxHousekeepingInterval, allowDynamicHousekeeping, cadvisorMetrics.MetricSet{cadvisorMetrics.NetworkTcpUsageMetrics: struct{}{}})
if err != nil {
return nil, err
}
cadvisorClient := &cadvisorClient{
runtime: runtime,
Manager: m,
}
err = cadvisorClient.exportHTTP(port)
if err != nil {
return nil, err
}
return cadvisorClient, nil
}
开发者ID:hyperhq,项目名称:hypernetes,代码行数:24,代码来源:cadvisor_linux.go
示例10: NewMemoryStorage
// Creates a memory storage with an optional backend storage option.
func NewMemoryStorage(backendStorageName string) (*memory.InMemoryCache, error) {
var storageDriver *memory.InMemoryCache
var backendStorage storage.StorageDriver
var err error
switch backendStorageName {
case "":
backendStorage = nil
case "influxdb":
var hostname string
hostname, err = os.Hostname()
if err != nil {
return nil, err
}
backendStorage, err = influxdb.New(
hostname,
*argDbTable,
*argDbName,
*argDbUsername,
*argDbPassword,
*argDbHost,
*argDbIsSecure,
*argDbBufferDuration,
)
case "bigquery":
var hostname string
hostname, err = os.Hostname()
if err != nil {
return nil, err
}
backendStorage, err = bigquery.New(
hostname,
*argDbTable,
*argDbName,
)
case "redis":
//machineName: We use os.Hostname as the machineName (A unique identifier to identify the host that runs the current cAdvisor)
//argDbName: the key for redis's data
//argDbHost: the redis's server host
var machineName string
machineName, err = os.Hostname()
if err != nil {
return nil, err
}
backendStorage, err = redis.New(
machineName,
*argDbName,
*argDbHost,
*argDbBufferDuration,
)
case "elasticsearch":
//argIndexName: the index for elasticsearch
//argTypeName: the type for index
//argElasticHost: the elasticsearch's server host
var machineName string
machineName, err = os.Hostname()
if err != nil {
return nil, err
}
backendStorage, err = elasticsearch.New(
machineName,
*argIndexName,
*argTypeName,
*argElasticHost,
*argEnableSniffer,
)
case "statsd":
backendStorage, err = statsd.New(
*argDbName,
*argDbHost,
)
case "stdout":
backendStorage, err = stdout.New(
*argDbHost,
)
default:
err = fmt.Errorf("unknown backend storage driver: %v", *argDbDriver)
}
if err != nil {
return nil, err
}
if backendStorageName != "" {
glog.Infof("Using backend storage type %q", backendStorageName)
} else {
glog.Infof("No backend storage selected")
}
glog.Infof("Caching stats in memory for %v", *storageDuration)
storageDriver = memory.New(*storageDuration, backendStorage)
return storageDriver, nil
}
开发者ID:ramitsurana,项目名称:cadvisor,代码行数:91,代码来源:storagedriver.go
注:本文中的github.com/google/cadvisor/cache/memory.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论