github.com/google/cadvisor@v0.49.1/utils/oomparser/oomexample/main.go (about) 1 // Copyright 2014 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "flag" 19 20 "k8s.io/klog/v2" 21 22 "github.com/google/cadvisor/utils/oomparser" 23 ) 24 25 // demonstrates how to run oomparser.OomParser to get OomInstance information 26 func main() { 27 klog.InitFlags(nil) 28 flag.Parse() 29 // out is a user-provided channel from which the user can read incoming 30 // OomInstance objects 31 outStream := make(chan *oomparser.OomInstance) 32 oomLog, err := oomparser.New() 33 if err != nil { 34 klog.Infof("Couldn't make a new oomparser. %v", err) 35 } else { 36 go oomLog.StreamOoms(outStream) 37 // demonstration of how to get oomLog's list of oomInstances or access 38 // the user-declared oomInstance channel, here called outStream 39 for oomInstance := range outStream { 40 klog.Infof("Reading the buffer. Output is %v", oomInstance) 41 } 42 } 43 }