當前位置: 首頁>>代碼示例>>Golang>>正文


Golang oomparser.New函數代碼示例

本文整理匯總了Golang中github.com/google/cadvisor/utils/oomparser.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

// demonstrates how to run oomparser.OomParser to get OomInstance information
func main() {
	flag.Parse()
	// out is a user-provided channel from which the user can read incoming
	// OomInstance objects
	outStream := make(chan *oomparser.OomInstance)
	oomLog, err := oomparser.New()
	if err != nil {
		glog.Infof("Couldn't make a new oomparser. %v", err)
	} else {
		go oomLog.StreamOoms(outStream)
		// demonstration of how to get oomLog's list of oomInstances or access
		// the user-declared oomInstance channel, here called outStream
		for oomInstance := range outStream {
			glog.Infof("Reading the buffer. Output is %v", oomInstance)
		}
	}
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:18,代碼來源:main.go

示例2: watchForNewOoms

func (self *manager) watchForNewOoms() error {
	glog.Infof("Started watching for new ooms in manager")
	outStream := make(chan *oomparser.OomInstance, 10)
	oomLog, err := oomparser.New()
	if err != nil {
		return err
	}
	go oomLog.StreamOoms(outStream)

	go func() {
		for oomInstance := range outStream {
			// Surface OOM and OOM kill events.
			newEvent := &info.Event{
				ContainerName: oomInstance.ContainerName,
				Timestamp:     oomInstance.TimeOfDeath,
				EventType:     info.EventOom,
			}
			err := self.eventHandler.AddEvent(newEvent)
			if err != nil {
				glog.Errorf("failed to add OOM event for %q: %v", oomInstance.ContainerName, err)
			}
			glog.V(3).Infof("Created an OOM event in container %q at %v", oomInstance.ContainerName, oomInstance.TimeOfDeath)

			newEvent = &info.Event{
				ContainerName: oomInstance.VictimContainerName,
				Timestamp:     oomInstance.TimeOfDeath,
				EventType:     info.EventOomKill,
				EventData: info.EventData{
					OomKill: &info.OomKillEventData{
						Pid:         oomInstance.Pid,
						ProcessName: oomInstance.ProcessName,
					},
				},
			}
			err = self.eventHandler.AddEvent(newEvent)
			if err != nil {
				glog.Errorf("failed to add OOM kill event for %q: %v", oomInstance.ContainerName, err)
			}
		}
	}()
	return nil
}
開發者ID:niclange,項目名稱:cadvisor,代碼行數:42,代碼來源:manager.go


注:本文中的github.com/google/cadvisor/utils/oomparser.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。