123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191 |
- 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<string> 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<string> 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<string> 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<string> 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<string> callback)
- {
- yield return StartCoroutine(Get_Demo("/admin/userList", "", (string msg) => {
- callback.Invoke(msg);
- }));
-
- }
- public IEnumerator GetRePort(JsonData data,Action<string> 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<string> 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<string> callback)
- {
- StartCoroutine(Post_Demo("/admin/userInfo", JsonMapper.ToJson(info), (string msg) => {
- callback.Invoke(msg);
- }));
-
- }
- public void getuserinfo(Action<UserInfo> 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<UserInfo>(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<UserInfo>(jdata["data"].ToJson());
- callback.Invoke(data);
- }
- }catch
- {
- }
- }));
-
- }
- public void login(JsonData data, Action<string> callback)
- {
- StartCoroutine(Post_Demo("/admin/login", data.ToJson(), (string msg) => {
- callback.Invoke(msg);
- }));
- }
- public void createzh(JsonData data, Action<string> callback)
- {
- StartCoroutine(Post_Demo("/admin/addUser", data.ToJson(), (string msg) => {
- callback.Invoke(msg);
- }));
- }
- public void getInfo( Action<AdminsystemInfo> 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<AdminsystemInfo>(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<AdminsystemInfo>(jdata["data"].ToJson());
- callback.Invoke(data);
- }
- }
- catch{
- }
- }));
- }
- public void GetJiFang(Action<ServerData> callback)
- {
- ServerData sd = new ServerData();
- sd.serverList = new List<ServerRoomData>();
- 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<LineChartData> callback, int type)
- {
- string typestr = "last_month_usage";
- if (type == 0)
- {
- typestr = "last_week_usage";
- }
- LineChartData data2 = new LineChartData();
- data2.xdata = new List<string>();
- data2.sdata = new List<LineChartSeriesData>();
-
- 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<float>();
- 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<LineChartData> callback,int type)
- {
- GetWSD((data) =>
- {
- StartCoroutine(getUsageInfo(data, callback, type));
- });
- return;
- LineChartData data = new LineChartData();
- data.xdata = new List<string>();
- data.sdata = new List<LineChartSeriesData>();
- 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<float>();
- 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<List<ServerJiLongData>> callback)
- {
- List<ServerJiLongData> list = new List<ServerJiLongData>();
- 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<ServerjiguiData>();
- 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<ServerData> callback)
- {
- GetWSD((data) =>
- {
-
- for (int j = 0; j < data.serverList.Count; j++)
- {
- if(data.serverList[j].jilonglist==null)
- {
- data.serverList[j].jilonglist = new List<ServerJiLongData>();
- }
-
- }
- callback.Invoke(data);
- });
- return;
- ServerData sd = new ServerData();
- sd.serverList = new List<ServerRoomData>();
- 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<ServerJiLongData>();
- for (int j = 0; j < i; j++)
- {
- ServerJiLongData jilong = new ServerJiLongData();
- jilong.id = j;
- jilong.name = i + "_" + j;
- jilong.jiguilist = new List<ServerjiguiData>();
- 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<string> 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<string> 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<List<LineChartData>> callback)
- {
- JsonData data = new JsonData();
- data["server_room_id"] = id;
- data["rack_id"] = rid;
- StartCoroutine(Post_Demo("/detail/tempHumiInfo", data.ToJson(), (string msg) =>
- {
- List<LineChartData> sjds = new List<LineChartData>();
- JsonData datamsg = JsonMapper.ToObject(msg);
- LineChartData data = new LineChartData();
- data.xdata = new List<string>();
- data.sdata = new List<LineChartSeriesData>();
- //24小时last_24h_temp 温度
- LineChartSeriesData lc = new LineChartSeriesData();
- lc.name = "温度";
- lc.values = new List<float>();
- 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<float>();
- 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<string>();
- data.sdata = new List<LineChartSeriesData>();
- //24小时last_day_temp 温度
- lc = new LineChartSeriesData();
- lc.name = "温度";
- lc.values = new List<float>();
- 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<float>();
- 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<string>();
- data.sdata = new List<LineChartSeriesData>();
- //24小时last_weed_temp 温度
- lc = new LineChartSeriesData();
- lc.name = "温度";
- lc.values = new List<float>();
- 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<float>();
- 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<string>();
- data.sdata = new List<LineChartSeriesData>();
- //24小时last_weed_temp 温度
- lc = new LineChartSeriesData();
- lc.name = "温度";
- lc.values = new List<float>();
- 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<float>();
- 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<List<ServerjiguiData>> callback)
- {
- JsonData data = new JsonData();
- data["server_room_id"] = id;
-
- StartCoroutine(Post_Demo("/detail/rackTempHumi", data.ToJson(), (string msg) =>
- {
- List<ServerjiguiData> sjds = new List<ServerjiguiData>();
- 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<ServerData> callback)
- {
- Debug.Log("获取温湿度===》");
- StartCoroutine(Post_Demo("/overview/serverroom","",(string msg)=> {
-
- JsonData data = JsonMapper.ToObject(msg);
- ServerData sd = new ServerData();
- sd.serverList = new List<ServerRoomData>();
- 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<ServerRoomData>();
- 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<ServerJiLongData>();
- for (int j = 0; j < i; j++)
- {
- ServerJiLongData jilong = new ServerJiLongData();
- jilong.id = j;
- jilong.name = i + "_" + j;
- jilong.jiguilist = new List<ServerjiguiData>();
- 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<ServerRoomData> roomdata )
- {
- for (int i = 0; i < roomdata.Count; i++)
- {
- if(roomdata[i].id == id)
- {
- return roomdata[i];
- }
- }
- return null;
- }
- public void GetVideo(Action<ServerData> callback)
- {
- Debug.Log("获取video===》");
- StartCoroutine(Post_Demo("/overview/serverLiveOverview", "", (string msg) => {
-
- JsonData data = JsonMapper.ToObject(msg);
- ServerData sd = new ServerData();
- sd.serverList = new List<ServerRoomData>();
- 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>();
- ServerVideoData svd = new ServerVideoData();
- svd.id = 1;
- svd.type = 0;
- svd.name = "机房摄像头";
- svd.url = new List<string>();
- 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<string>();
- 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<ServerRoomData>();
- for (int i = 0; i < 8; i++)
- {
- ServerRoomData srd = new ServerRoomData();
- srd.id = i;
- srd.videolist = new List<ServerVideoData>();
- ServerVideoData svd = new ServerVideoData();
- svd.id = 1;
- svd.name = "机房摄像头";
- svd.url = new List<string>();
- 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<string>();
- 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<TongSuanData> 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<JianKongPtData> 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<List<PieChartData>> callback)
- {
- Debug.Log("6个服务器===》");
- StartCoroutine(Post_Demo("/overview/intelligentResourceOverview", "", (string msg) =>
- {
- JsonData data = JsonMapper.ToObject(msg);
- List<PieChartData> lp = new List<PieChartData>();
- 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<PieChartItemData>();
- 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>();
- 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<PieChartData> lp = new List<PieChartData>();
- for (int i = 0; i < 6; i++)
- {
- PieChartData p = new PieChartData();
- p.title = i.ToString();
- p.value = 1000000;
- p.items = new List<PieChartItemData>();
- 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<List<RingValueData>> callback)
- {
- Debug.Log("获取k8s===》");
- List<RingValueData> rvs = new List<RingValueData>();
- 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<LineChartData> callback)
- {
- Debug.Log("获取gpu===》");
- StartCoroutine(Post_Demo("/overview/gpupower", "", (string msg) => {
- JsonData datamsg = JsonMapper.ToObject(msg);
- LineChartData data = new LineChartData();
- data.xdata = new List<string>();
- data.sdata = new List<LineChartSeriesData>();
- LineChartSeriesData lc = new LineChartSeriesData();
- lc.name = "今日";
- lc.values = new List<float>();
- 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<float>();
- 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<string>();
- data.sdata = new List<LineChartSeriesData>();
- for (int i = 0; i < 10; i++)
- {
- data.xdata.Add("xdata_" + i);
- }
- LineChartSeriesData lc = new LineChartSeriesData();
- lc.name = "数据1";
- lc.values = new List<float>();
- 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<float>();
- 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<LineChartData> callback)
- {
- StartCoroutine(Post_Demo("/overview/warnData", "", (string msg) =>
- {
- JsonData datamsg = JsonMapper.ToObject(msg);
- LineChartData data = new LineChartData();
- data.xdata = new List<string>();
- data.sdata = new List<LineChartSeriesData>();
- 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<float>();
- 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<string>();
- data.sdata = new List<LineChartSeriesData>();
- for (int i = 0; i < 20; i++)
- {
- data.xdata.Add("xdata_" + i);
- }
- LineChartSeriesData lc = new LineChartSeriesData();
- lc.name = "数据1";
- lc.values = new List<float>();
- 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<float>();
- 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<float>();
- 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<GaoJingListData> callback)
- {
- StartCoroutine(Post_Demo("/overview/warnRecord", "", (string msg) =>
- {
- JsonData datamsg = JsonMapper.ToObject(msg);
- GaoJingListData gjl = new GaoJingListData();
- gjl.list = new List<GaoJingItemData>();
- 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<GaoJingItemData>();
- 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);
- }
- }
|