Exemplo n.º 1
0
func (meter *process) sampleStatm() {
	body, err := ioutil.ReadFile("/proc/self/statm")
	if err != nil {
		klog.KFatalf("meter.process.statm.error", err.Error())
	}

	var virt, rss, shared uint64
	if _, err := fmt.Sscanf(string(body), "%d %d %d", &virt, &rss, &shared); err != nil {
		klog.KFatalf("meter.process.statm.parse.error", err.Error())
	}

	meter.Memory.Resident.Change(float64(rss * 1000))
	meter.Memory.Virtual.Change(float64(virt * 1000))
	meter.Memory.Shared.Change(float64(shared * 1000))
}
Exemplo n.º 2
0
// Register associates the given value's type with the short and fully qualified
// name.
func (reg *Registry) Register(value interface{}) {
	if value == nil {
		klog.KPanicf("blueprint.registry.error", "attempted to register nil")
	}

	typ := reflect.TypeOf(value)
	for typ.Kind() == reflect.Ptr || typ.Kind() == reflect.Interface {
		typ = typ.Elem()
	}

	reg.mutex.Lock()

	if reg.types == nil {
		reg.types = make(map[string]reflect.Type)
	}

	name := typ.Name()
	if pkg := typ.PkgPath(); pkg != "" {
		name = pkg + "/" + name
	}

	if _, ok := reg.types[name]; ok {
		klog.KFatalf("blueprint.registry.error", "duplicate registration attempt for '%s'", name)
	}

	reg.types[name] = typ

	// Add a shorthand alias to make life simpler.
	if _, ok := reg.types[typ.Name()]; !ok {
		reg.types[typ.Name()] = typ
	}

	reg.mutex.Unlock()
}
Exemplo n.º 3
0
// RegisterConverter makes the given converter for the type of the given object.
func RegisterConverter(obj interface{}, conv Converter) {
	convertersMutex.Lock()
	defer convertersMutex.Unlock()

	typ := reflect.TypeOf(obj)

	if converters == nil {
		converters = make(map[reflect.Type]Converter)
	}

	if _, ok := converters[typ]; ok {
		klog.KFatalf("blueprint.converters.register.error", "duplicate converters for type '%s'", typ)
	}

	converters[typ] = conv
}
Exemplo n.º 4
0
func (handler *HTTPHandler) init() {
	if handler.URL == "" {
		klog.KFatal("meter.http.init.error", "no URL configured")
	}

	if handler.Method == "" {
		klog.KFatal("meter.http.init.error", "no HTTP method configured")
	}

	if _, err := url.Parse(handler.URL); err != nil {
		klog.KFatalf("meter.http.init.error", "invalid URL '%s': %s", handler.URL, err)
	}

	if handler.HTTPClient == nil {
		handler.HTTPClient = http.DefaultClient
	}

	handler.client = &rest.Client{
		Client: handler.HTTPClient,
		Root:   handler.URL,
	}
}
Exemplo n.º 5
0
func (meter *process) rusage() (result syscall.Rusage) {
	if err := syscall.Getrusage(syscall.RUSAGE_SELF, &result); err != nil {
		klog.KFatalf("meter.process.rusage.error", err.Error())
	}
	return
}