コード例 #1
0
//percent memory utilization
//range returned is 1-100
func Collectmem(serverName string) (Metric, error) {
	values := Metric{}
	var err error
	values.Timestamp = time.Now()
	values.MetricType = "mem"
	var output string

	var response cpmserverapi.MetricMEMResponse
	request := &cpmserverapi.MetricMEMRequest{}
	var url = "http://" + serverName + ":10001"
	response, err = cpmserverapi.MetricMEMClient(url, request)
	if err != nil {
		logit.Error.Println("mem metric error:" + err.Error())
		return values, err
	}

	output = strings.TrimSpace(response.Output)

	values.Value, err = strconv.ParseFloat(output, 64)
	if err != nil {
		logit.Error.Println("parseFloat error in mem metric " + err.Error())
	}

	return values, err
}
func testMetricMEM() {
	var response cpmserverapi.MetricMEMResponse
	var err error
	request := &cpmserverapi.MetricMEMRequest{}
	response, err = cpmserverapi.MetricMEMClient("http://192.168.0.106:10001", request)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println("returned " + response.Output)
}