Example #1
0
func (routeServerGeneralInfo *RouteServerGeneralInfo) Routes(m *martini.ClassicMartini) {
	m.Get("/server/info/general", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/info/general")
		shttp.SetResponseJsonHeader(w)
		result := map[string]string{}
		val, err := service.NewGetSystemTimeInfo().GetInfo()
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		result["time"] = val
		runTimeInfo, err1 := service.NewGetSystemRunTimeInfo().GetInfo()
		if nil != err1 {
			return model.GetErrorObjDtoJson(err1)
		}
		result["runtime"] = fmt.Sprintf("%d天 %d小时 %d分钟", runTimeInfo.Day, runTimeInfo.Hour, runTimeInfo.Min)
		hostname, err3 := os.Hostname()
		if nil != err3 {
			return model.GetErrorObjDtoJson(err3)
		}
		result["hostname"] = hostname
		ver, err2 := utils.CmdOutputNoLn("uname", "-r")
		if nil != err2 {
			return model.GetErrorObjDtoJson(err2)
		}
		result["kernel"] = ver
		return model.GetDataDtoJson(result)
	})
}
Example #2
0
func (routeServerNetCardInfo *RouteServerNetCardInfo) Routes(m *martini.ClassicMartini) {
	m.Get("/server/info/netcard", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/info/netcard")
		shttp.SetResponseJsonHeader(w)
		result, err := service.NewGetNetStatisticsInfo().GetInfo()
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		return model.GetDataDtoJson(result)
	})
}
Example #3
0
func (routeServerConfigSave *routeServerConfigSave) Routes(m *martini.ClassicMartini) {
	m.Post("/server/saveconfig", func(w http.ResponseWriter, r *http.Request, re render.Render) string {
		log.WriteLog("addr: /server/saveconfig")
		shttp.SetResponseJsonHeader(w)
		r.ParseForm()
		err := service.NewServerConfigSaveRequestHandle().Save(r)
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		return model.GetDataDtoJson("")
	})
}
Example #4
0
func (routeServerMemInfo *RouteServerMemInfo) Routes(m *martini.ClassicMartini) {
	m.Get("/server/info/mem", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/info/mem")
		shttp.SetResponseJsonHeader(w)
		mem, err := service.NewGetMemInfo().GetInfo()
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		memFree := mem.MemFree + mem.Buffers + mem.Cached
		memUsed := mem.MemTotal - memFree
		return model.GetDataDtoJson([]interface{}{mem.MemTotal, memUsed, memFree})
	})
}
Example #5
0
func (routeServerConfigRoot *routeServerConfigRoot) Routes(m *martini.ClassicMartini) {
	m.Get("/serverconfig", func(w http.ResponseWriter, r *http.Request, re render.Render) string {
		log.WriteLog("addr: /serverconfig")
		shttp.SetResponseJsonHeader(w)
		r.ParseForm()
		serverName := r.FormValue("servername")
		if utils.IsEmptyStr(serverName) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		serverInfo, serverSetupInfo, err := service.NewGetServerSetupInfo().GetInfo(serverName)
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		return model.GetDataDtoJson([]interface{}{serverInfo, serverSetupInfo})
	})
}
Example #6
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)
	})
}
Example #7
0
func (routeServerSave *RouteServerSave) Routes(m *martini.ClassicMartini) {
	m.Post("/server/save", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/save")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取服务器信息失败")
		}
		r.ParseForm()
		log.WriteLog("server save %v", r.Form)
		oservername := r.Form.Get("oservername")
		servername := r.Form.Get("servername")
		addFlag := utils.IsEmptyStr(oservername)
		address := r.Form.Get("address")
		iType, err := strconv.Atoi(r.FormValue("servertype"))
		if nil != err {
			log.WriteLog("error: %v", err)
			iType = common.SERVER_TYPE_CMS
		}
		if utils.IsEmptyStr(servername) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		if utils.IsEmptyStr(address) {
			return model.GetErrorDtoJson("没有服务器地址")
		}
		index := setupInfo.GetServerIndexByServerName(servername)
		oindex := setupInfo.GetServerIndexByServerName(oservername)
		var pServerInfo *model.ServerInfo = nil
		if addFlag {
			if index > -1 {
				return model.GetErrorDtoJson("服务器名称输入重复")
			}
			serverInfo := model.ServerInfo{ServerName: servername, Address: address, Type: iType}
			setupInfo.AddServerInfo(serverInfo)
			pServerInfo = &serverInfo
		} else {
			if oindex < 0 {
				return model.GetErrorDtoJson("没有找到服务器")
			} else {
				if index > -1 && oindex != index {
					return model.GetErrorDtoJson("服务器名称输入重复")
				}
			}
			setupInfo.Servers[oindex].ServerName = servername
			setupInfo.Servers[oindex].Address = address
			setupInfo.Servers[oindex].Type = iType
			pServerInfo = &setupInfo.Servers[oindex]
		}
		if nil != routeServerSave.CheckServerSave {
			err := routeServerSave.CheckServerSave.CheckServerSave(oservername, pServerInfo)
			if nil != err {
				return model.GetErrorObjDtoJson(err)
			}
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除服务器信息失败")
			return model.GetErrorDtoJson("保存删除服务器信息失败")
		}
		return model.GetDataDtoJson(model.ServerSaveInfo{ServerInfo: *pServerInfo, OServerName: oservername, AddFlag: addFlag})
	})
}