Exemplo n.º 1
0
func (getNetStatisticsInfoLinux *GetNetStatisticsInfoLinux) GetInfo() ([][]string, error) {
	ret := [][]string{}
	for iFace, netcards := range netInfos {
		var netRecvBytes int64 = 0
		if netcards[1] != nil {
			netRecvBytes = netcards[0].InBytes - netcards[1].InBytes
		}
		var netTransBytes int64 = 0
		if netcards[1] != nil {
			netTransBytes = netcards[0].OutBytes - netcards[1].OutBytes
		}
		var netTotalBytes int64 = 0
		if netcards[1] != nil {
			netTotalBytes = netcards[0].TotalBytes - netcards[1].TotalBytes
		}
		var netTotalDroppedBytes int64 = 0
		if netcards[1] != nil {
			netTotalDroppedBytes = netcards[0].TotalDropped - netcards[1].TotalDropped
		}

		item := []string{
			iFace,
			fmt.Sprintf("%s/s", utils.DisplaySizeStr(float64(netRecvBytes))),
			fmt.Sprintf("%s/s", utils.DisplaySizeStr(float64(netTransBytes))),
			fmt.Sprintf("%s/s", utils.DisplaySizeStr(float64(netTotalBytes))),
			fmt.Sprintf("%d/s", netTotalDroppedBytes),
		}
		ret = append(ret, item)
	}
	return ret, nil
}
Exemplo n.º 2
0
func (routeServerProcessInfo *RouteServerProcessInfo) Routes(m *martini.ClassicMartini) {
	m.Get("/server/info/process", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/info/process")
		shttp.SetResponseJsonHeader(w)
		r.ParseForm()
		serverName := r.FormValue("servername")
		if utils.IsEmptyStr(serverName) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		serverProcessInfo, err := service.NewGetServerProcessInfo().GetInfo(serverName)
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		result := map[string]string{}
		result["cpuRate"] = fmt.Sprintf("%.1f%%", serverProcessInfo.CPURate)
		result["memRate"] = fmt.Sprintf("%.1f%%", serverProcessInfo.MemRate)
		result["realMem"] = fmt.Sprintf("%s", utils.DisplaySizeStr(float64(serverProcessInfo.MemRealSize)))
		result["virtualMem"] = fmt.Sprintf("%s", utils.DisplaySizeStr(float64(serverProcessInfo.MemVmSize)))
		result["state"] = serverProcessInfo.State
		return model.GetDataDtoJson(result)
	})
}