using System; using System.Collections; using System.Collections.Generic; using System.Text; using LitJson; using UnityEngine; using UnityEngine.Networking; using static Manager; using System.Security.Cryptography; using Random = System.Random; public class DataManager : MonoBehaviour { public static int admin=0; public static string acc=""; public static string email=""; public static string token=""; public static DataManager Instance; private void Awake() { Instance = this; // StartCoroutine(wx_demo("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx9a280bbd81c64f56&secret=aeb6e5818800f8196fcac007e992dae0")); } public IEnumerator SetdonghuanSetting(int a,int b,int c,Action callback) { JsonData d = new JsonData(); d["current_data_source"] = a; d["backup_data_switch_type"] = b; d["data_recover_type"] = c; yield return StartCoroutine(Post_Demo("/admin/donghuanSetting", d.ToJson(), (string msg) => { callback.Invoke(msg); })); } public IEnumerator SetzongjiSetting(int a,int b,int c,Action callback) { JsonData d = new JsonData(); d["current_data_source"] = a; d["backup_data_switch_type"] = b; d["data_recover_type"] = c; yield return StartCoroutine(Post_Demo("/admin/zongjiSetting", d.ToJson(), (string msg) => { callback.Invoke(msg); })); } public IEnumerator SetyunnengSetting(int a,int b,int c,Action callback) { JsonData d = new JsonData(); d["current_data_source"] = a; d["backup_data_switch_type"] = b; d["data_recover_type"] = c; yield return StartCoroutine(Post_Demo("/admin/yunnengSetting", d.ToJson(), (string msg) => { callback.Invoke(msg); })); } public IEnumerator SetgeneralSetting(bool b,Action callback) { JsonData d = new JsonData(); d["update_time_display_switch"] = b; yield return StartCoroutine(Post_Demo("/admin/generalSetting", d.ToJson(), (string msg) => { callback.Invoke(msg); })); } public IEnumerator GetUserList(Action callback) { yield return StartCoroutine(Get_Demo("/admin/userList", "", (string msg) => { callback.Invoke(msg); })); } public IEnumerator GetRePort(JsonData data,Action callback) { yield return StartCoroutine(Post_Demo("/admin/queryOperateLog", data.ToJson(), (string msg) => { callback.Invoke(msg); })); } // ButtonSpawnFruit // Token: 0x0600000B RID: 11 RVA: 0x00002170 File Offset: 0x00000370 public static string Sha1(string str) { byte[] bytes = Encoding.UTF8.GetBytes(str); byte[] array = SHA1.Create().ComputeHash(bytes); StringBuilder stringBuilder = new StringBuilder(); foreach (byte b in array) { stringBuilder.Append(b.ToString("X2")); } return stringBuilder.ToString().ToLower(); } // ButtonSpawnFruit // Token: 0x0600000A RID: 10 RVA: 0x00002110 File Offset: 0x00000310 public static string Md5(string str) { byte[] bytes = Encoding.UTF8.GetBytes(str); byte[] array = MD5.Create().ComputeHash(bytes); StringBuilder stringBuilder = new StringBuilder(); foreach (byte b in array) { stringBuilder.Append(b.ToString("X2")); } return stringBuilder.ToString().Substring(0, 20); } private static Random random = new Random(); public static string CreateNoncestr(int length) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; char[] nonceChars = new char[length]; for (int i = 0; i < length; i++) { nonceChars[i] = chars[random.Next(chars.Length)]; } return new String(nonceChars); } public static long GetCurrentUnixTimestampMillis() { // Unix时间戳是从1970年1月1日开始计算 DateTime unixStartTime = new DateTime(1970, 1, 1); // 当前时间 DateTime now = DateTime.UtcNow; // 当前时间与Unix时间戳的时间间隔 TimeSpan timeSpan = now - unixStartTime; // 将时间间隔转换为毫秒数 long timestamp = (long)timeSpan.TotalSeconds; return timestamp; } public IEnumerator wx_demo(string urls) { UnityWebRequest webRequest = UnityWebRequest.Get(urls); //发送请求 yield return webRequest.SendWebRequest(); //等待请求完成 while (!webRequest.isDone) { yield return null; } if (string.IsNullOrEmpty(webRequest.error)) {//Get的请求成功//Get请求的返回参数 var data = webRequest.downloadHandler.text; Debug.Log(data); Debug.Log("成功"); JsonData dataj = JsonMapper.ToObject(data); string nonceStr = CreateNoncestr(16); // 生成一个长度为16的随机字符串 string jsapi_ticket=dataj["access_token"].ToString(); long timestamp=GetCurrentUnixTimestampMillis(); string url="https://mp.ghz-tech.com/yx/"; //jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg&noncestr=Wm3WZYTPz0wzccnW×tamp=1414587457&url=http://mp.weixin.qq.com?params=value Debug.Log("nonceStr==>"+nonceStr); Debug.Log("jsapi_ticket==>"+jsapi_ticket); Debug.Log("timestamp==>"+timestamp); Debug.Log("url==>"+url); string sha1Hash = Sha1("jsapi_ticket="+jsapi_ticket+"&noncestr="+nonceStr+"×tamp="+timestamp+"&url="+url); Debug.Log("sha1Hash==>"+sha1Hash); } else {//Get的请求失败 Debug.Log("失败"); } } public void setPass(string oldpass, string newpass,Action callback) { JsonData jdata=new JsonData(); jdata["old_password"] =oldpass; jdata["new_password"] =newpass; StartCoroutine(Post_Demo("/admin/resetPassword", jdata.ToJson(), (string msg) => { callback.Invoke(msg); })); } public void setuserinfo(UserInfo info,Action callback) { StartCoroutine(Post_Demo("/admin/userInfo", JsonMapper.ToJson(info), (string msg) => { callback.Invoke(msg); })); } public void getuserinfo(Action callback) { StartCoroutine(Get_Demo("/admin/userInfo", "", (string msg) => { try{ if (msg == null) { msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"count\":\"ext_hujiajun\",\"name\":\"胡佳骏\",\"dept\":\"\",\"notes\":\"\",\"position\":\"\"}}"; } JsonData jdata = JsonMapper.ToObject(msg); if (jdata["data"] != null) { UserInfo data = JsonMapper.ToObject(jdata["data"].ToJson()); callback.Invoke(data); } else { msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"count\":\"ext_hujiajun\",\"name\":\"胡佳骏\",\"dept\":\"\",\"notes\":\"\",\"position\":\"\"}}"; jdata = JsonMapper.ToObject(msg); UserInfo data = JsonMapper.ToObject(jdata["data"].ToJson()); callback.Invoke(data); } }catch { } })); } public void login(JsonData data, Action callback) { StartCoroutine(Post_Demo("/admin/login", data.ToJson(), (string msg) => { callback.Invoke(msg); })); } public void createzh(JsonData data, Action callback) { StartCoroutine(Post_Demo("/admin/addUser", data.ToJson(), (string msg) => { callback.Invoke(msg); })); } public void getInfo( Action callback) { // StartCoroutine(Post_Demo("/admin/systemInfo", "", (string msg) => { try{ if (msg == null) { msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"general_option\":{\"update_time_display_switch\":false},\"yunneng_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"通算资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"k8S集群信息\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"告警数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"监控平台数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"zongji_ption\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"智算服务器\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU功率\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"交换机数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"donghuan_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"温湿度\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"电量数据\",\"update_rate_display\":\"24h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"功率数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"视频监控\",\"update_rate_display\":\"实时监控\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":0,\"update_rate_type\":0,\"update_Rate_value\":0}]}}}"; } JsonData jdata = JsonMapper.ToObject(msg); if (jdata["data"]!=null) { AdminsystemInfo data = JsonMapper.ToObject(jdata["data"].ToJson()); callback.Invoke(data); } else { msg = "{\"code\":200,\"message\":\"success\",\"data\":{\"general_option\":{\"update_time_display_switch\":false},\"yunneng_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"通算资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"k8S集群信息\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"告警数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"监控平台数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"zongji_ption\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"智算服务器\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU资源\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"GPU功率\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"交换机数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1}]},\"donghuan_option\":{\"current_data_source\":1,\"backup_data_switch_type\":1,\"data_recover_type\":1,\"details\":[{\"name\":\"温湿度\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"电量数据\",\"update_rate_display\":\"24h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":1,\"update_Rate_value\":1},{\"name\":\"功率数据\",\"update_rate_display\":\"1h\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":1,\"update_rate_type\":2,\"update_Rate_value\":1},{\"name\":\"视频监控\",\"update_rate_display\":\"实时监控\",\"current_data_source\":1,\"check_time\":\"2024-10-23 16:28:35\",\"real_data_status\":0,\"update_rate_type\":0,\"update_Rate_value\":0}]}}}"; jdata = JsonMapper.ToObject(msg); AdminsystemInfo data = JsonMapper.ToObject(jdata["data"].ToJson()); callback.Invoke(data); } } catch{ } })); } public void GetJiFang(Action callback) { ServerData sd = new ServerData(); sd.serverList = new List(); for (int i = 0; i < 8; i++) { ServerRoomData srd = new ServerRoomData(); srd.id = i; srd.name = i + "_机房"; sd.serverList.Add(srd); } callback.Invoke(sd); } IEnumerator getUsageInfo(ServerData data, Action callback, int type) { string typestr = "last_month_usage"; if (type == 0) { typestr = "last_week_usage"; } LineChartData data2 = new LineChartData(); data2.xdata = new List(); data2.sdata = new List(); yield return StartCoroutine(Post_Demo("/detail/electricUsageInfo", "", (string msg) => { try{ JsonData datamsg = JsonMapper.ToObject(msg); for (int j = 0; j < datamsg["data"][typestr].Count; j++) { if(!data2.xdata.Contains(datamsg["data"][typestr][j]["date"].ToString())) data2.xdata.Add(datamsg["data"][typestr][j]["date"].ToString()); } for (int i = 0; i < data.serverList.Count; i++) { LineChartSeriesData lc = new LineChartSeriesData(); lc.name = data.serverList[i].name; lc.values = new List(); for (int z = 0; z < datamsg["data"][typestr].Count; z++) { if(data.serverList[i].name == datamsg["data"][typestr][z]["server_room_name"].ToString()) { lc.values.Add(float.Parse(datamsg["data"][typestr][z]["usage"].ToString())); } } data2.sdata.Add(lc); } } catch{ } })); callback.Invoke(data2); } public void GetDLBiao(Action callback,int type) { GetWSD((data) => { StartCoroutine(getUsageInfo(data, callback, type)); }); return; LineChartData data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); for (int i = 0; i < 20; i++) { data.xdata.Add("xdata_" + i); } for (int i = 0; i < 8; i++) { LineChartSeriesData lc = new LineChartSeriesData(); lc.name = "数据_"+ i; lc.values = new List(); for (int j = 0; j < 20; j++) { lc.values.Add(UnityEngine.Random.Range(1, 1000)); } data.sdata.Add(lc); } callback.Invoke(data); } public void GetJL(int id,Action> callback) { List list = new List(); JsonData data = new JsonData(); data["server_room_id"] = id; StartCoroutine(Post_Demo("/detail/rackElectricInfo", data.ToJson(), (string msg) => { try{ JsonData data = JsonMapper.ToObject(msg); for (int i = 0; i < data["data"]["groups"].Count; i++) { ServerJiLongData jilong = new ServerJiLongData(); jilong.id = i; jilong.name = data["data"]["groups"][i]["name"].ToString(); jilong.jiguilist = new List(); for (int z = 0; z < data["data"]["groups"][i]["racks"].Count; z++) { ServerjiguiData jg = new ServerjiguiData(); jg.name = data["data"]["groups"][i]["racks"][z]["name"].ToString(); jg.srz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_day_usage"].ToString()); jg.syz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_month_usage"].ToString()); jg.szz = float.Parse(data["data"]["groups"][i]["racks"][z]["last_week_usage"].ToString()); jg.zgl = float.Parse(data["data"]["groups"][i]["racks"][z]["power"].ToString()); jilong.jiguilist.Add(jg); } list.Add(jilong); } callback.Invoke(list); } catch{ } })); } public void GetDL(Action callback) { GetWSD((data) => { for (int j = 0; j < data.serverList.Count; j++) { if(data.serverList[j].jilonglist==null) { data.serverList[j].jilonglist = new List(); } } callback.Invoke(data); }); return; ServerData sd = new ServerData(); sd.serverList = new List(); for (int i = 0; i < 8; i++) { ServerRoomData srd = new ServerRoomData(); srd.id = i; srd.name = i + "_机房"; srd.zonggonglv = UnityEngine.Random.Range(30.0f, 40.0f); srd.shangridl = UnityEngine.Random.Range(30.0f, 40.0f); srd.jilonglist = new List(); for (int j = 0; j < i; j++) { ServerJiLongData jilong = new ServerJiLongData(); jilong.id = j; jilong.name = i + "_" + j; jilong.jiguilist = new List(); int rand = UnityEngine.Random.Range(2,4)>2?4:2; for (int z = 0; z < rand; z++) { ServerjiguiData jg = new ServerjiguiData(); jg.name = i + "_" + j + "_" + z; jg.srz = 123; jg.syz = 123; jg.szz = 123; jg.zgl = 123; jilong.jiguilist.Add(jg); } srd.jilonglist.Add(jilong); } sd.serverList.Add(srd); } callback.Invoke(sd); } public static string ip = ""; public IEnumerator Post_Demo(string url,string lstformData,Action callback) { Debug.Log("开始请求" + url + "_" + lstformData); while (ip=="") { Debug.Log("ip未设置" + ip + "_" + lstformData); yield return null; } string m_url = ip + url; Debug.Log("请求地址" + m_url + "_" + lstformData); var request = new UnityWebRequest(m_url, "POST"); byte[] bodyRaw = Encoding.UTF8.GetBytes(lstformData); request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); DownloadHandler downloadHandler = new DownloadHandlerBuffer(); request.downloadHandler = downloadHandler; if (DataManager.token!="") request.SetRequestHeader("AUTHORIZATION", "Bearer " + DataManager.token); yield return request.SendWebRequest(); if (string.IsNullOrEmpty(request.error)) {//Post的请求成功 //Post请求的返回参数 var data = request.downloadHandler.text; Debug.Log(m_url+"_"+ lstformData + "——成功:" + data); callback.Invoke(data); } else {//Post的请求失败 Debug.Log(m_url + "失败"+ lstformData+"_"+ request.error); callback.Invoke(null); } } public IEnumerator Get_Demo(string url, string lstformData, Action callback) { Debug.Log("开始请求" + url + "_" + lstformData); while (ip == "") { Debug.Log("ip未设置" + ip + "_" + lstformData); yield return null; } string m_url = ip + url; Debug.Log("请求地址" + m_url + "_" + lstformData); var request = new UnityWebRequest(m_url, "Get"); byte[] bodyRaw = Encoding.UTF8.GetBytes(lstformData); request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); DownloadHandler downloadHandler = new DownloadHandlerBuffer(); request.downloadHandler = downloadHandler; if (DataManager.token != "") request.SetRequestHeader("AUTHORIZATION", "Bearer " + DataManager.token); yield return request.SendWebRequest(); if (string.IsNullOrEmpty(request.error)) {//Post的请求成功 //Post请求的返回参数 var data = request.downloadHandler.text; Debug.Log(m_url + "_" + lstformData + "——成功:" + data); callback.Invoke(data); } else {//Post的请求失败 Debug.Log(m_url + "失败" + lstformData + "_" + request.error); callback.Invoke(null); } } public void GetTwoWsdTb(int id,int rid, Action> callback) { JsonData data = new JsonData(); data["server_room_id"] = id; data["rack_id"] = rid; StartCoroutine(Post_Demo("/detail/tempHumiInfo", data.ToJson(), (string msg) => { List sjds = new List(); JsonData datamsg = JsonMapper.ToObject(msg); LineChartData data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); //24小时last_24h_temp 温度 LineChartSeriesData lc = new LineChartSeriesData(); lc.name = "温度"; lc.values = new List(); for (int i = 0; i < datamsg["data"]["last_24h_temp"].Count; i++) { data.xdata.Add(datamsg["data"]["last_24h_temp"][i]["date"].ToString().Split(' ')[1]); lc.values.Add(float.Parse(datamsg["data"]["last_24h_temp"][i]["value"].ToString())); } data.sdata.Add(lc); //24小时last_24h_humi 温度 LineChartSeriesData lc2 = new LineChartSeriesData(); lc2.name = "湿度"; lc2.values = new List(); for (int i = 0; i < datamsg["data"]["last_24h_humi"].Count; i++) { lc2.values.Add(float.Parse(datamsg["data"]["last_24h_humi"][i]["value"].ToString())); } data.sdata.Add(lc2); sjds.Add(data); data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); //24小时last_day_temp 温度 lc = new LineChartSeriesData(); lc.name = "温度"; lc.values = new List(); for (int i = 0; i < datamsg["data"]["last_day_temp"].Count; i++) { data.xdata.Add(datamsg["data"]["last_day_temp"][i]["date"].ToString().Split(' ')[1]); lc.values.Add(float.Parse(datamsg["data"]["last_day_temp"][i]["value"].ToString())); } data.sdata.Add(lc); //24小时last_day_humi 温度 lc2 = new LineChartSeriesData(); lc2.name = "湿度"; lc2.values = new List(); for (int i = 0; i < datamsg["data"]["last_day_humi"].Count; i++) { lc2.values.Add(float.Parse(datamsg["data"]["last_day_humi"][i]["value"].ToString())); } data.sdata.Add(lc2); sjds.Add(data); data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); //24小时last_weed_temp 温度 lc = new LineChartSeriesData(); lc.name = "温度"; lc.values = new List(); for (int i = 0; i < datamsg["data"]["last_week_temp"].Count; i++) { data.xdata.Add(datamsg["data"]["last_week_temp"][i]["date"].ToString().Split(' ')[0]); lc.values.Add(float.Parse(datamsg["data"]["last_week_temp"][i]["value"].ToString())); } data.sdata.Add(lc); //24小时last_week_humi 温度 lc2 = new LineChartSeriesData(); lc2.name = "湿度"; lc2.values = new List(); for (int i = 0; i < datamsg["data"]["last_week_humi"].Count; i++) { lc2.values.Add(float.Parse(datamsg["data"]["last_week_humi"][i]["value"].ToString())); } data.sdata.Add(lc2); sjds.Add(data); data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); //24小时last_weed_temp 温度 lc = new LineChartSeriesData(); lc.name = "温度"; lc.values = new List(); for (int i = 0; i < datamsg["data"]["last_month_temp"].Count; i++) { data.xdata.Add(datamsg["data"]["last_month_temp"][i]["date"].ToString().Split(' ')[0]); lc.values.Add(float.Parse(datamsg["data"]["last_month_temp"][i]["value"].ToString())); } data.sdata.Add(lc); //24小时last_week_humi 温度 lc2 = new LineChartSeriesData(); lc2.name = "湿度"; lc2.values = new List(); for (int i = 0; i < datamsg["data"]["last_month_humi"].Count; i++) { lc2.values.Add(float.Parse(datamsg["data"]["last_month_humi"][i]["value"].ToString())); } data.sdata.Add(lc2); sjds.Add(data); callback.Invoke(sjds); })); } public void GetTwoWsd(int id, Action> callback) { JsonData data = new JsonData(); data["server_room_id"] = id; StartCoroutine(Post_Demo("/detail/rackTempHumi", data.ToJson(), (string msg) => { List sjds = new List(); JsonData data = JsonMapper.ToObject(msg); for (int i = 0; i < data["data"]["racks"].Count; i++) { ServerjiguiData sjd = new ServerjiguiData(); sjd.id =int.Parse( data["data"]["racks"][i]["id"].ToString()); sjd.name = data["data"]["racks"][i]["name"].ToString(); sjd.shidu = float.Parse(data["data"]["racks"][i]["temp"].ToString()); sjd.wendu = float.Parse(data["data"]["racks"][i]["humi"].ToString()); sjds.Add(sjd); } callback.Invoke(sjds); })); } public void GetWSD(Action callback) { Debug.Log("获取温湿度===》"); StartCoroutine(Post_Demo("/overview/serverroom","",(string msg)=> { JsonData data = JsonMapper.ToObject(msg); ServerData sd = new ServerData(); sd.serverList = new List(); for (int i = 0; i < data["data"]["item_info"].Count; i++) { ServerRoomData srd = new ServerRoomData(); srd.id = int.Parse(data["data"]["item_info"][i]["server_room_id"].ToString()); srd.name = data["data"]["item_info"][i]["item_name"].ToString(); srd.wendu = float.Parse(data["data"]["item_info"][i]["item_temp"].ToString()); srd.shidu = float.Parse(data["data"]["item_info"][i]["item_humi"].ToString()); try { srd.shangridl = float.Parse(data["data"]["item_info"][i]["item_lastday_usage"].ToString()); srd.zonggonglv = float.Parse(data["data"]["item_info"][i]["item_total_power"].ToString()); } catch { } sd.serverList.Add(srd); } callback.Invoke(sd); })); return; ServerData sd = new ServerData(); sd.serverList = new List(); for (int i = 0; i < 8; i++) { ServerRoomData srd = new ServerRoomData(); srd.id = i; srd.name = i + "_机房"; srd.wendu = UnityEngine.Random.Range(30.0f, 40.0f); srd.shidu = UnityEngine.Random.Range(30.0f, 40.0f); srd.jilonglist = new List(); for (int j = 0; j < i; j++) { ServerJiLongData jilong = new ServerJiLongData(); jilong.id = j; jilong.name = i + "_" + j; jilong.jiguilist = new List(); int rand = UnityEngine.Random.Range(2, 4) > 2 ? 4 : 2; for (int z = 0; z < rand; z++) { ServerjiguiData jg = new ServerjiguiData(); jg.name = i + "_" + j + "_" + z; jg.wendu = 123; jg.shidu = 123; jilong.jiguilist.Add(jg); } srd.jilonglist.Add(jilong); } sd.serverList.Add(srd); } callback.Invoke(sd); } ServerRoomData checkroom(int id , List roomdata ) { for (int i = 0; i < roomdata.Count; i++) { if(roomdata[i].id == id) { return roomdata[i]; } } return null; } public void GetVideo(Action callback) { Debug.Log("获取video===》"); StartCoroutine(Post_Demo("/overview/serverLiveOverview", "", (string msg) => { JsonData data = JsonMapper.ToObject(msg); ServerData sd = new ServerData(); sd.serverList = new List(); for (int i = 0; i < data["data"]["items"].Count; i++) { ServerRoomData srd = new ServerRoomData(); srd.id = int.Parse(data["data"]["items"][i]["server_room_id"].ToString()); srd.name = data["data"]["items"][i]["server_name"].ToString(); srd.videolist = new List(); ServerVideoData svd = new ServerVideoData(); svd.id = 1; svd.type = 0; svd.name = "机房摄像头"; svd.url = new List(); srd.videolist.Add(svd); for (int j = 0; j < data["data"]["items"][i]["video_list"]["room"].Count; j++) { svd.url.Add(data["data"]["items"][i]["video_list"]["room"][j].ToString()); } ServerVideoData svd2 = new ServerVideoData(); svd2.id = 1; svd.type = 1; svd2.name = "机笼摄像头"; svd2.url = new List(); srd.videolist.Add(svd2); for (int j = 0; j < data["data"]["items"][i]["video_list"]["rack"].Count; j++) { svd2.url.Add(data["data"]["items"][i]["video_list"]["rack"][j].ToString()); } sd.serverList.Add(srd); } callback.Invoke(sd); })); return; ServerData sd = new ServerData(); sd.serverList = new List(); for (int i = 0; i < 8; i++) { ServerRoomData srd = new ServerRoomData(); srd.id = i; srd.videolist = new List(); ServerVideoData svd = new ServerVideoData(); svd.id = 1; svd.name = "机房摄像头"; svd.url = new List(); for (int j = 0; j < 8; j++) { svd.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8"); } srd.videolist.Add(svd); ServerVideoData svd2 = new ServerVideoData(); svd2.id = 1; svd2.name = "机笼摄像头"; svd2.url = new List(); for (int j = 0; j < 8; j++) { svd2.url.Add("https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8"); } srd.videolist.Add(svd2); sd.serverList.Add(srd); } callback.Invoke(sd); } public void GetTongSuan(Action callback) { StartCoroutine(Post_Demo("/overview/generalResourceOverview", "", (string msg) => { try{ JsonData data = JsonMapper.ToObject(msg)["data"]; TongSuanData jdata = new TongSuanData(); jdata.devct = float.Parse(data["network_device_number"].ToString()); jdata.serverct = float.Parse(data["server_number"].ToString()); jdata.zhiji = float.Parse(data["host_number"].ToString()); callback.Invoke(jdata); } catch{ } })); return; TongSuanData jdata = new TongSuanData(); jdata.devct = 123; jdata.serverct = 123; jdata.zhiji = 123; callback.Invoke(jdata); } public void GetJianKongPt(Action callback) { StartCoroutine(Post_Demo("/overview/monitor", "", (string msg) => { JsonData data = JsonMapper.ToObject(msg)["data"]; JianKongPtData jdata = new JianKongPtData(); jdata.shijianct =float.Parse( data["strategy_number"].ToString()) ; jdata.zhixingct = float.Parse(data["plugin_number"].ToString()); jdata.gaojingct = float.Parse(data["warn_number"].ToString()); callback.Invoke(jdata); })); return; JianKongPtData jdata = new JianKongPtData(); jdata.shijianct = 123; jdata.zhixingct = 123; jdata.gaojingct = 123; callback.Invoke(jdata); } public void GetSixServer(Action> callback) { Debug.Log("6个服务器===》"); StartCoroutine(Post_Demo("/overview/intelligentResourceOverview", "", (string msg) => { JsonData data = JsonMapper.ToObject(msg); List lp = new List(); for (int i = 0; i < 5; i++) { if(i< data["data"]["items"].Count) { PieChartData p = new PieChartData(); p.title = data["data"]["items"][i]["name"].ToString(); p.value = float.Parse(data["data"]["items"][i]["count"].ToString()); p.items = new List(); foreach (var k in data["data"]["items"][i].Keys) { if (k != "name" && k != "count") { PieChartItemData idata1 = new PieChartItemData(); idata1.name = k; idata1.value = float.Parse(data["data"]["items"][i][k].ToString().Split('%')[0]); p.items.Add(idata1); } } lp.Add(p); } else { PieChartData p = new PieChartData(); p.title ="空"; p.value = 0; p.items = new List(); PieChartItemData idata1 = new PieChartItemData(); idata1.name = "空"; idata1.value =0; p.items.Add(idata1); lp.Add(p); } } PieChartData p2 = new PieChartData(); p2.title = data["data"]["flops"]["name"].ToString(); p2.value = float.Parse(data["data"]["flops"]["value"].ToString().Split(' ')[0]); lp.Add(p2); callback.Invoke(lp); })); return; List lp = new List(); for (int i = 0; i < 6; i++) { PieChartData p = new PieChartData(); p.title = i.ToString(); p.value = 1000000; p.items = new List(); PieChartItemData idata1 = new PieChartItemData(); idata1.name = "RUN"; idata1.value = 27; p.items.Add(idata1); PieChartItemData idata2 = new PieChartItemData(); idata2.name = "IDLE"; idata2.value = 27; p.items.Add(idata2); lp.Add(p); } callback.Invoke(lp); } public void GetK8s(Action> callback) { Debug.Log("获取k8s===》"); List rvs = new List(); StartCoroutine(Post_Demo("/overview/kubernetsCluster", "", (string msg) => { JsonData datamsg = JsonMapper.ToObject(msg); RingValueData d1 = new RingValueData(); d1.value = datamsg["data"]["cluster_name"].ToString(); RingValueData d2 = new RingValueData(); d2.value = datamsg["data"]["cluster_status"].ToString(); datamsg["data"]["cluster_status"].ToString(); RingValueData d3 = new RingValueData(); d3.value = datamsg["data"]["cluster_node_count"][0].ToString(); d3.max = datamsg["data"]["cluster_node_count"][1].ToString(); rvs.Add(d1); rvs.Add(d2); rvs.Add(d3); callback.Invoke(rvs); })); return; } public void GetGPUData(Action callback) { Debug.Log("获取gpu===》"); StartCoroutine(Post_Demo("/overview/gpupower", "", (string msg) => { JsonData datamsg = JsonMapper.ToObject(msg); LineChartData data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); LineChartSeriesData lc = new LineChartSeriesData(); lc.name = "今日"; lc.values = new List(); for (int i = 0; i < datamsg["data"][ "today_info"].Count; i++) { data.xdata.Add(datamsg["data"]["today_info"][i]["time"].ToString().Split(' ')[1]); lc.values.Add(float.Parse(datamsg["data"]["today_info"][i]["value"].ToString())); } data.sdata.Add(lc); LineChartSeriesData lc2 = new LineChartSeriesData(); lc2.name = "昨日"; lc2.values = new List(); for (int i = 0; i < datamsg["data"]["yesterday_info"].Count; i++) { lc2.values.Add(float.Parse( datamsg["data"]["yesterday_info"][i]["value"].ToString())); } data.sdata.Add(lc2); callback.Invoke(data); })); return; LineChartData data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); for (int i = 0; i < 10; i++) { data.xdata.Add("xdata_" + i); } LineChartSeriesData lc = new LineChartSeriesData(); lc.name = "数据1"; lc.values = new List(); for (int i = 0; i < 10; i++) { lc.values.Add(UnityEngine.Random.Range(1, 800)); } data.sdata.Add(lc); LineChartSeriesData lc2 = new LineChartSeriesData(); lc2.name = "数据2"; lc2.values = new List(); for (int i = 0; i < 10; i++) { lc2.values.Add(UnityEngine.Random.Range(1, 800)); } data.sdata.Add(lc2); callback.Invoke(data); } public void GetGaoJingData(Action callback) { StartCoroutine(Post_Demo("/overview/warnData", "", (string msg) => { JsonData datamsg = JsonMapper.ToObject(msg); LineChartData data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); for (int i = 0; i < datamsg["data"]["prop_ame"].Count; i++) { LineChartSeriesData lc = new LineChartSeriesData(); lc.name = datamsg["data"]["prop_ame"][i].ToString(); lc.values = new List(); data.sdata.Add(lc); } try { for (int i = 0; i < datamsg["data"]["items"].Count; i++) { data.xdata.Add(datamsg["data"]["items"][i]["date"].ToString()); for (int j = 0; j < data.sdata.Count; j++) { data.sdata[j].values.Add(float.Parse(datamsg["data"]["items"][i]["prop_value"][j].ToString())); } } } catch { } callback.Invoke(data); })); return; LineChartData data = new LineChartData(); data.xdata = new List(); data.sdata = new List(); for (int i = 0; i < 20; i++) { data.xdata.Add("xdata_" + i); } LineChartSeriesData lc = new LineChartSeriesData(); lc.name = "数据1"; lc.values = new List(); for (int i = 0; i < 20; i++) { lc.values.Add(UnityEngine.Random.Range(1, 1000)); } data.sdata.Add(lc); LineChartSeriesData lc2 = new LineChartSeriesData(); lc2.name = "数据2"; lc2.values = new List(); for (int i = 0; i < 20; i++) { lc2.values.Add(UnityEngine.Random.Range(1, 1000)); } data.sdata.Add(lc2); LineChartSeriesData lc3 = new LineChartSeriesData(); lc3.name = "数据3"; lc3.values = new List(); for (int i = 0; i < 20; i++) { lc3.values.Add(UnityEngine.Random.Range(1, 1000)); } data.sdata.Add(lc2); callback.Invoke(data); } public void GetGaoJingJiLuData(Action callback) { StartCoroutine(Post_Demo("/overview/warnRecord", "", (string msg) => { JsonData datamsg = JsonMapper.ToObject(msg); GaoJingListData gjl = new GaoJingListData(); gjl.list = new List(); try{ for (int i = 0; i < datamsg["data"]["items"].Count; i++) { GaoJingItemData gjid = new GaoJingItemData(); gjid.lv = datamsg["data"]["items"][i]["level"].ToString(); gjid.time = datamsg["data"]["items"][i]["time"].ToString(); gjid.dev = datamsg["data"]["items"][i]["device"].ToString(); gjid.type = datamsg["data"]["items"][i]["status"].ToString(); gjl.list.Add(gjid); } }catch{ } callback.Invoke(gjl); })); return; GaoJingListData gjl = new GaoJingListData(); gjl.list = new List(); for (int i = 0; i < 2; i++) { GaoJingItemData gjid = new GaoJingItemData(); gjid.lv = "一般"; gjid.time = "2024-1-1 00:11"; gjid.dev = "111机房"; gjid.type = "已解决"; gjl.list.Add(gjid); } for (int i = 0; i < 2; i++) { GaoJingItemData gjid = new GaoJingItemData(); gjid.lv = "紧急"; gjid.time = "2024-1-1 00:11"; gjid.dev = "111机房"; gjid.type = "待解决"; gjl.list.Add(gjid); } for (int i = 0; i < 2; i++) { GaoJingItemData gjid = new GaoJingItemData(); gjid.lv = "严重"; gjid.time = "2024-1-1 00:11"; gjid.dev = "111机房"; gjid.type = "已解决"; gjl.list.Add(gjid); } callback.Invoke(gjl); } }