dashboard.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. function fn_list_endpoints()
  2. {
  3. var qs = $.trim($("input[name='endpoint_search']").val());
  4. var tags = $.trim($("input[name='tag_search']").val());
  5. var limit = $("#endpoint-limit").val();
  6. var page = $("#endpoint-page").val();
  7. $(".loading").show();
  8. $.getJSON("/api/endpoints", {q: qs, tags: tags, limit:limit, page:page, _r:Math.random()}, function(ret){
  9. $(".loading").hide();
  10. if (!ret.ok) {
  11. err_message_quietly(ret.msg);
  12. return;
  13. }
  14. // display_endpoints
  15. var tbody_hosts = $("#tbody-endpoints");
  16. tbody_hosts.html("");
  17. for (var hidx in ret.data) {
  18. var h = ret.data[hidx].endpoint;
  19. var eid = ret.data[hidx].id;
  20. var line_html = '<tr>'
  21. + '<td><input type="checkbox" class="input shiftCheckbox" data-eid="'+ eid +'" data-fullname="'+ h +'"></input></td>'
  22. + '<td>' + h + '</td>'
  23. + '</tr>';
  24. tbody_hosts.append($(line_html));
  25. tbody_hosts.find('.shiftCheckbox').shiftcheckbox();
  26. }
  27. fn_check_all_hosts();
  28. }).error(function(req, ret, errorThrown){
  29. $(".loading").hide();
  30. err_message_quietly(req.statusText)
  31. })
  32. }
  33. function fn_list_counters(){
  34. var qs = $.trim($("#counter-search").val());
  35. var eids = new Array();
  36. $("#tbody-endpoints input:checked").each(function(i, o){
  37. var eid = $(o).attr("data-eid");
  38. eids.push(eid);
  39. });
  40. if (eids.length === 0){
  41. err_message_quietly("先选定一些endpoints");
  42. return false;
  43. }
  44. var limit = $("#counter-limit").val();
  45. var page = $("#counter-page").val();
  46. $(".loading").show();
  47. $.ajax({
  48. method: "POST",
  49. url: "/api/counters",
  50. dataType: "json",
  51. data: {"eids": JSON.stringify(eids), "q": qs, "limit": limit, "page":page, "_r": Math.random()},
  52. success:function(ret){
  53. $(".loading").hide();
  54. if(ret.ok){
  55. var items = ret.data;
  56. // display counters
  57. var tbody_items = $("#tbody-counters");
  58. tbody_items.html("");
  59. for (var i in items) {
  60. var c = items[i];
  61. var display_counter_type = "计数器";
  62. if(c[1] == "GAUGE") {
  63. display_counter_type = "原始值";
  64. }
  65. var line_html = '<tr>'
  66. + '<td><input type="checkbox" class="input shiftCheckbox" data-fullkey="'+c[0]+'"></input></td>'
  67. + '<td><a href="javascript:void(0);" onclick="fn_show_chart(\'' + c[0] + '\')" >' + c[0] + '</a></td>'
  68. + '<td>'+ display_counter_type +'</td>'
  69. + '<td>'+ c[2] +'s</td>'
  70. + '</tr>'
  71. tbody_items.append($(line_html));
  72. tbody_items.find('.shiftCheckbox').shiftcheckbox();
  73. }
  74. }else{
  75. err_message_quietly("搜索失败:" + ret.msg);
  76. return false;
  77. }
  78. }
  79. });
  80. }
  81. function fn_delete_counters(){
  82. var checked_hosts = new Array();
  83. $("#tbody-endpoints input:checked").each(function(i, o){
  84. if($(o).is(":visible")){
  85. var hostfullname = $(o).attr("data-fullname");
  86. checked_hosts.push(hostfullname);
  87. }
  88. });
  89. if(checked_hosts.length === 0){
  90. err_message_quietly("先选endpoint:)");
  91. return false;
  92. }
  93. var checked_items = new Array();
  94. $("#tbody-counters input:checked").each(function(i, o){
  95. if($(o).is(":visible")){
  96. var key_ = $(o).attr("data-fullkey");
  97. checked_items.push(key_);
  98. }
  99. });
  100. if (checked_items.length === 0){
  101. err_message_quietly("请选择counter");
  102. return false;
  103. }
  104. if(checked_items.length > 10) {
  105. err_message_quietly("每次删除不能超过10个,免得你后悔:");
  106. return false;
  107. }
  108. my_confirm("真的要删除么?这会删除MySQL中对应的内容,也会清除磁盘上对应的数据文件", [ '确定', '取消' ], function() {
  109. $.ajax({
  110. url: "/api/counters",
  111. dataType: "json",
  112. method: "DELETE",
  113. data: {"endpoints": checked_hosts, "counters": checked_items, "_r": Math.random()},
  114. success: function(ret) {
  115. if (ret.ok) {
  116. ok_message_quietly(ret.data);
  117. }else {
  118. err_message_quietly("请求出错了");
  119. }
  120. },
  121. error: function(){
  122. err_message_quietly("请求出错了");
  123. }
  124. });
  125. }, function() {
  126. });
  127. return false;
  128. }
  129. function fn_delete_endpoints(){
  130. var checked_hosts = new Array();
  131. $("#tbody-endpoints input:checked").each(function(i, o){
  132. if($(o).is(":visible")){
  133. var hostfullname = $(o).attr("data-fullname");
  134. checked_hosts.push(hostfullname);
  135. }
  136. });
  137. if(checked_hosts.length === 0){
  138. err_message_quietly("先选endpoint:)");
  139. return false;
  140. }
  141. if(checked_hosts.length > 2) {
  142. err_message_quietly("每次删除不能超过2个,免得你后悔:");
  143. return false;
  144. }
  145. my_confirm("真的要删除么?这会删除MySQL中对应的内容,也会清除磁盘上对应的数据文件", [ '确定', '取消' ], function() {
  146. $.ajax({
  147. url: "/api/endpoints",
  148. dataType: "json",
  149. method: "DELETE",
  150. data: {"endpoints": checked_hosts, "_r": Math.random()},
  151. success: function(ret) {
  152. if (ret.ok) {
  153. ok_message_quietly(ret.data);
  154. }else {
  155. err_message_quietly("请求出错了");
  156. }
  157. },
  158. error: function(){
  159. err_message_quietly("请求出错了");
  160. }
  161. });
  162. }, function() {
  163. });
  164. return false;
  165. }
  166. function filter_endpoint()
  167. {
  168. var filter_text = $("#endpoint-filter").val().toLowerCase();
  169. var targets = $("#tbody-endpoints tr");
  170. if(!filter_text){
  171. targets.each(function(i, obj){
  172. $(obj).show();
  173. });
  174. }else{
  175. var filter_pattern = new RegExp(filter_text, "i");
  176. targets.each(function(i, obj){
  177. var checkbox = $($(obj).find("input[type='checkbox']")[0]);
  178. var name = checkbox.attr("data-fullname");
  179. if(filter_pattern.exec(name) == null){
  180. $(obj).hide();
  181. }else{
  182. $(obj).show();
  183. }
  184. if($(obj).is(":visible")){
  185. checkbox.prop("checked", true);
  186. }else{
  187. checkbox.prop("checked", false);
  188. }
  189. });
  190. }
  191. };
  192. function filter_counter()
  193. {
  194. var filter_text = $("#counter-filter").val().toLowerCase();
  195. var targets = $("#tbody-counters tr");
  196. if(!filter_text){
  197. targets.each(function(i, obj){
  198. $(obj).show();
  199. });
  200. }else{
  201. var filter_pattern = new RegExp(filter_text, "i");
  202. targets.each(function(i, obj){
  203. var checkbox = $($(obj).find("input[type='checkbox']")[0]);
  204. var name = checkbox.attr("data-fullkey");
  205. if(filter_pattern.exec(name) == null){
  206. $(obj).hide();
  207. }else{
  208. $(obj).show();
  209. }
  210. if($(obj).is(":visible")){
  211. checkbox.prop("checked", true);
  212. }else{
  213. checkbox.prop("checked", false);
  214. }
  215. });
  216. }
  217. };
  218. function fn_show_chart(counter)
  219. {
  220. var checked_hosts = new Array();
  221. $("#tbody-endpoints input:checked").each(function(i, o){
  222. if($(o).is(":visible")){
  223. var hostfullname = $(o).attr("data-fullname");
  224. checked_hosts.push(hostfullname);
  225. }
  226. });
  227. if(checked_hosts.length === 0){
  228. err_message_quietly("先选endpoint:)");
  229. return false;
  230. }
  231. checked_items = new Array();
  232. checked_items.push(counter);
  233. var w = window.open();
  234. $.ajax({
  235. url: "/chart",
  236. dataType: "json",
  237. method: "POST",
  238. data: {"endpoints": checked_hosts, "counters": checked_items, "graph_type": "h", "_r": Math.random()},
  239. success: function(ret) {
  240. if (ret.ok) {
  241. setTimeout(function(){w.location='/chart/big?id='+ret.id;}, 0);
  242. } else {
  243. err_message_quietly("请求出错了");
  244. }
  245. },
  246. error: function(){
  247. err_message_quietly("请求出错了");
  248. }
  249. });
  250. return false;
  251. }
  252. function fn_show_all(graph_type)
  253. {
  254. var checked_hosts = new Array();
  255. $("#tbody-endpoints input:checked").each(function(i, o){
  256. if($(o).is(":visible")){
  257. var hostfullname = $(o).attr("data-fullname");
  258. checked_hosts.push(hostfullname);
  259. }
  260. });
  261. if(checked_hosts.length === 0){
  262. err_message_quietly("先选endpoint:)");
  263. return false;
  264. }
  265. var checked_items = new Array();
  266. $("#tbody-counters input:checked").each(function(i, o){
  267. if($(o).is(":visible")){
  268. var key_ = $(o).attr("data-fullkey");
  269. checked_items.push(key_);
  270. }
  271. });
  272. if (checked_items.length === 0){
  273. err_message_quietly("请选择counter");
  274. return false;
  275. }
  276. var w = window.open();
  277. $.ajax({
  278. url: "/chart",
  279. dataType: "json",
  280. method: "POST",
  281. data: {"endpoints": checked_hosts, "counters": checked_items, "graph_type": graph_type, "_r": Math.random()},
  282. success: function(ret) {
  283. if (ret.ok) {
  284. setTimeout(function(){w.location="/charts?id="+ret.id+"&graph_type="+graph_type;}, 0);
  285. }else {
  286. err_message_quietly("请求出错了");
  287. }
  288. },
  289. error: function(){
  290. err_message_quietly("请求出错了");
  291. }
  292. });
  293. return false;
  294. }
  295. function fn_check_all_items()
  296. {
  297. var box = $("#check_all_counters");
  298. if(box.prop("checked")){
  299. $("#tbody-counters").find("input:checkbox").each(function(i, o){
  300. $(o).prop("checked", true);
  301. });
  302. }else{
  303. $("#tbody-counters").find("input:checkbox").each(function(i, o){
  304. $(o).prop("checked", false);
  305. });
  306. }
  307. }
  308. function fn_check_all_hosts()
  309. {
  310. var box = $("#check_all_endpoints");
  311. if(box.prop("checked")){
  312. $("#tbody-endpoints").find("input:checkbox").each(function(i, o){
  313. $(o).prop("checked", true);
  314. });
  315. }else{
  316. $("#tbody-endpoints").find("input:checkbox").each(function(i, o){
  317. $(o).prop("checked", false);
  318. });
  319. }
  320. }
  321. function fn_filter_group()
  322. {
  323. var filter_text = $("#group-filter").val().toLowerCase();
  324. var group_objs = $(".group");
  325. if(!filter_text){
  326. group_objs.each(function(i, obj){
  327. $(obj).show();
  328. });
  329. }else if (filter_text.length <= 2) {
  330. }else{
  331. group_objs.each(function(i, obj){
  332. var groupname = $($(obj).children("a")[0]).attr("data-gname");
  333. if(groupname.toLowerCase().indexOf(filter_text) === -1){
  334. $(obj).hide();
  335. }else{
  336. $(obj).show();
  337. }
  338. });
  339. fn_collapse_in_groups();
  340. }
  341. };
  342. function fn_collapse_in_groups()
  343. {
  344. $(".accordion-body").each(function(i, obj){
  345. if(!$(obj).hasClass("in")){
  346. $(obj).collapse("show");
  347. }
  348. });
  349. };