sbd-npm 1.4.80 → 1.4.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/status.js +129 -90
  3. package/util.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.4.80",
3
+ "version": "1.4.81",
4
4
  "description": "Stock Big Data",
5
5
  "author": "DHQ <dhq314@gmail.com>",
6
6
  "license": "ISC",
package/status.js CHANGED
@@ -225,6 +225,7 @@ $(function () {
225
225
  {"name": "虚拟内存", "table_sort": 1},
226
226
  {"name": "启动命令"},
227
227
  {"name": "创建时间", "table_sort": 1},
228
+ {"name": "操作"}
228
229
  ]
229
230
  });
230
231
  $("#is_py_process").click(function () {
@@ -239,8 +240,19 @@ $(function () {
239
240
  let is_py_process = $("#is_py_process").prop("checked") ? "1" : "0";
240
241
  Util.post(location.pathname, {active_div: localStorage[Status.tab_token], is_py_process: is_py_process}, function (j) {
241
242
  let html = [], process_num = 0;
243
+ let screen_pid = j["screen_pid"] ? j["screen_pid"] : 0;
244
+ let screen_pid_date = j["screen_pid_date"] ? j["screen_pid_date"] : 0;
242
245
  j["data"].forEach(function (item) {
243
246
  process_num++;
247
+ let is_screen = 0;
248
+ if (screen_pid === item["pid"]) {
249
+ is_screen = 1;
250
+ } else {
251
+ let parameter_match = item["cmdline"].match(/\/do\.py\s+([A-Za-z0-9_]+)/);
252
+ if (parameter_match && parameter_match[1]) {
253
+ is_screen = 1;
254
+ }
255
+ }
244
256
  html.push("<tr>");
245
257
  html.push("<td>", item["pid"], "</td>");
246
258
  html.push("<td>", item["name"], "</td>");
@@ -250,10 +262,15 @@ $(function () {
250
262
  html.push("<td data-val='", item["vms"], "'>", Util.trans_byte_size(item["vms"]), "</td>");
251
263
  html.push("<td title='", item["cmdline"], "'>", Util.substring(item["cmdline"], 60), "</td>");
252
264
  html.push("<td>", Util.seconds_to_format(item["create_time"]), "</td>");
265
+ html.push(Status.pack_screen_html(is_screen, item["pid"], screen_pid, screen_pid_date));
253
266
  html.push("</tr>");
254
267
  });
255
268
  Util.render_table_html("process_div_body", html);
256
269
  $("#process_num").html(process_num);
270
+ // 终止进程
271
+ Status.handle_process_kill("process_div_body", 1);
272
+ // 进程会话
273
+ Status.handle_process_screen("process_div_body", 1);
257
274
  Util.hide_tips();
258
275
  });
259
276
  },
@@ -757,6 +774,7 @@ $(function () {
757
774
  }
758
775
  let html = [], process_num = 0;
759
776
  let screen_pid = j["screen_pid"] ? j["screen_pid"] : 0;
777
+ let screen_pid_date = j["screen_pid_date"] ? j["screen_pid_date"] : 0;
760
778
  j["process"].forEach(function (item) {
761
779
  process_num++;
762
780
  let is_xmr = 0, is_screen = 0;
@@ -787,111 +805,132 @@ $(function () {
787
805
  html.push("<td title='", item["cmdline"], "'>", cmdline, "</td>");
788
806
  }
789
807
  html.push("<td>", Util.seconds_to_format(item["create_time"]), "</td>");
790
- if (is_screen === 1) {
791
- let screen_html = "";
792
- if (screen_pid === item["pid"]) {
793
- if (j["screen_pid_date"] && j["screen_pid_date"] > 0) {
794
- screen_html = "<a data-screen='1' class='process_screen' href='#'><span title='会话数据已成功获取(" + Util.seconds_to_format(j["screen_pid_date"]) + ")' class='label label-success'>会话</span></a>";
795
- } else {
796
- screen_html = "<a class='process_screen' href='#'><span title='会话数据获取中...' class='label label-info'>会话</span></a>";
797
- }
798
- } else {
799
- screen_html = "<a class='process_screen' href='#'>会话</a>";
800
- }
801
- html.push("<td><a class='process_kill' href='#'>终止</a>&nbsp;&nbsp;", screen_html, "</td>");
802
- } else {
803
- html.push("<td><a class='process_kill' href='#'>终止</a></td>");
804
- }
808
+ html.push(Status.pack_screen_html(is_screen, item["pid"], screen_pid, screen_pid_date));
805
809
  html.push("</tr>");
806
810
  });
807
811
  Util.render_table_html("machine_process_div_body", html);
808
812
  $("#machine_process_tip").html('共 <span class="label label-info">' + process_num + '</span> 进程,最后更新时间:' + Util.seconds_to_format(j["date"]) + ',Revision:' + j["revision"] + ',MachineId:' + j["machine_id"]);
809
813
  $("#machines option[value='" + j["machine_id"] + "']").text(j["ip"] + "(" + process_num + ")");
810
- $("#machine_process_div_body .process_kill").each(function() {
811
- $(this).click(function() {
812
- let pid = $(this).parent().parent().children('td').eq(0).text();
813
- let cmdline = $(this).parent().parent().children('td').eq(2).text();
814
- let action = Status.parse_machine_action(cmdline);
815
- let pid_action = "[" + pid + "(" + action + ")]";
816
- if (confirm("是否确定要终止进程 " + pid_action + " ?")) {
817
- Util.show_loading();
818
- let instruction = "kill_pid_" + pid;
819
- Util.post(location.pathname, {active_div: "machine_instruction_add", "machine_id": $("#machines").val(), "instruction": instruction, action_type: 2}, function (j) {
820
- Util.hide_tips();
821
- if (j["code"] === 1) {
822
- Util.show_tips("进程 " + pid_action + " 已加到终止队列中", 4567, "alert-success");
823
- } else if (j["code"] === 2) {
824
- Util.show_tips("Machine 不存在!", 4567, "alert-danger");
825
- } else if (j["code"] === 3) {
826
- Util.show_tips("进程 " + pid_action + " 异常!", 4567, "alert-danger");
827
- } else {
828
- Util.show_tips("进程值不能为空!", 4567, "alert-danger");
829
- }
830
- });
814
+ // 终止进程
815
+ Status.handle_process_kill("machine_process_div_body", 2);
816
+ // 进程会话
817
+ Status.handle_process_screen("machine_process_div_body", 2);
818
+ } else if (is_init === 1) {
819
+ $('#machines').html('<option value="">暂无Machine</option>');
820
+ }
821
+ Util.hide_tips();
822
+ });
823
+ },
824
+
825
+ handle_process_kill: function(element_id, action_type) {
826
+ $("#" + element_id + " .process_kill").each(function() {
827
+ $(this).click(function() {
828
+ let pid = $(this).parent().parent().children('td').eq(0).text();
829
+ let cmdline_index = action_type === 2 ? 2 : 6;
830
+ let cmdline_obj = $(this).parent().parent().children('td').eq(cmdline_index);
831
+ let cmdline = cmdline_obj.attr('title') ? cmdline_obj.attr('title') : cmdline_obj.text();
832
+ let action = Status.parse_machine_action(cmdline);
833
+ let pid_action = "[" + pid + "(" + action + ")]";
834
+ if (confirm("是否确定要终止进程 " + pid_action + " ?")) {
835
+ Util.show_loading();
836
+ let instruction = "kill_pid_" + pid;
837
+ let machine_id = action_type === 2 ? $("#machines").val() : "";
838
+ Util.post(location.pathname, {active_div: "machine_instruction_add", "machine_id": machine_id, "instruction": instruction, "action_type": action_type}, function (j) {
839
+ Util.hide_tips();
840
+ if (j["code"] === 1) {
841
+ Util.show_tips("进程 " + pid_action + " 已加到终止队列中", 4567, "alert-success");
842
+ } else if (j["code"] === 2) {
843
+ Util.show_tips("Machine 不存在!", 4567, "alert-danger");
844
+ } else if (j["code"] === 3) {
845
+ Util.show_tips("进程 " + pid_action + " 异常!", 4567, "alert-danger");
846
+ } else {
847
+ Util.show_tips("进程值不能为空!", 4567, "alert-danger");
831
848
  }
832
849
  });
833
- });
834
- $("#machine_process_div_body .process_screen").each(function() {
835
- $(this).click(function() {
836
- Util.show_loading();
837
- let pid = $(this).parent().parent().children('td').eq(0).text();
838
- let cmdline = $(this).parent().parent().children('td').eq(2).text();
839
- let action = Status.parse_machine_action(cmdline);
840
- let is_fetch_screen = $(this).attr("data-screen");
841
- if (is_fetch_screen && is_fetch_screen == "1") {
842
- let instruction = "screen_" + pid + "_" + action;
843
- Util.post(location.pathname, {active_div: "machine_screen", "machine_id": $("#machines").val(), "pid": pid, "instruction": instruction}, function (j) {
844
- Util.hide_tips();
845
- if (j["data"]) {
846
- Util.showAlert(j["data"]);
847
- } else {
848
- Util.show_tips("数据异常!", 4567, "alert-danger");
849
- }
850
- });
850
+ }
851
+ });
852
+ });
853
+ },
854
+
855
+ handle_process_screen: function(element_id, action_type) {
856
+ $("#" + element_id + " .process_screen").each(function() {
857
+ $(this).click(function() {
858
+ Util.show_loading();
859
+ let pid = $(this).parent().parent().children('td').eq(0).text();
860
+ let cmdline_index = action_type === 2 ? 2 : 6;
861
+ let cmdline_obj = $(this).parent().parent().children('td').eq(cmdline_index);
862
+ let cmdline = cmdline_obj.attr('title') ? cmdline_obj.attr('title') : cmdline_obj.text();
863
+ let action = Status.parse_machine_action(cmdline);
864
+ let is_fetch_screen = $(this).attr("data-screen");
865
+ if (is_fetch_screen && is_fetch_screen == "1") {
866
+ let instruction = "screen_" + pid + "_" + action;
867
+ let machine_id = action_type === 2 ? $("#machines").val() : "";
868
+ Util.post(location.pathname, {active_div: "machine_screen", "machine_id": machine_id, "pid": pid, "instruction": instruction}, function (j) {
869
+ Util.hide_tips();
870
+ if (j["data"]) {
871
+ Util.showAlert(j["data"]);
851
872
  } else {
852
- let this_obj = $(this);
853
- if (this_obj.find("span.label-info").length > 0) {
854
- Util.hide_tips();
855
- Util.show_tips("进程 [" + pid + "(" + action + ")] 已在会话队列处理中", 4567, "alert-danger");
856
- } else {
857
- let instruction = "screen_" + pid + "_" + action;
858
- Util.post(location.pathname, {active_div: "machine_instruction_add", "machine_id": $("#machines").val(), "instruction": instruction, action_type: 2}, function (j) {
859
- Util.hide_tips();
860
- if (j["code"] === 1) {
861
- $('#machine_process_div_body a').each(function() {
862
- let span_obj = $(this).find('span.label.label-info');
863
- if (span_obj.length) {
864
- var span_text = span_obj.text();
865
- span_obj.remove();
866
- $(this).append(span_text);
867
- } else {
868
- let is_fetch_screen = $(this).attr("data-screen");
869
- if (is_fetch_screen && is_fetch_screen == "1") {
870
- $(this).text('会话').removeAttr('data-screen');
871
- }
872
- }
873
- });
874
- this_obj.html("<span title='会话数据获取中...' class='label label-info'>会话</span>");
875
- Util.show_tips("进程 [" + pid + "(" + action + ")] 已加到会话队列中", 4567, "alert-success");
876
- } else if (j["code"] === 2) {
877
- Util.show_tips("Machine 不存在!", 4567, "alert-danger");
878
- } else if (j["code"] === 3) {
879
- Util.show_tips("进程 [" + pid + "(" + action + ")] 异常!", 4567, "alert-danger");
873
+ Util.show_tips("数据异常!", 4567, "alert-danger");
874
+ }
875
+ });
876
+ } else {
877
+ let this_obj = $(this);
878
+ if (this_obj.find("span.label-info").length > 0) {
879
+ Util.hide_tips();
880
+ Util.show_tips("进程 [" + pid + "(" + action + ")] 已在会话队列处理中", 4567, "alert-danger");
881
+ } else {
882
+ let instruction = "screen_" + pid + "_" + action;
883
+ let machine_id = action_type === 2 ? $("#machines").val() : "";
884
+ Util.post(location.pathname, {active_div: "machine_instruction_add", "machine_id": machine_id, "instruction": instruction, "action_type": action_type}, function (j) {
885
+ Util.hide_tips();
886
+ if (j["code"] === 1) {
887
+ $('#machine_process_div_body a').each(function() {
888
+ let span_obj = $(this).find('span.label.label-info');
889
+ if (span_obj.length) {
890
+ var span_text = span_obj.text();
891
+ span_obj.remove();
892
+ $(this).append(span_text);
880
893
  } else {
881
- Util.show_tips("进程值不能为空!", 4567, "alert-danger");
894
+ let is_fetch_screen = $(this).attr("data-screen");
895
+ if (is_fetch_screen && is_fetch_screen == "1") {
896
+ $(this).text('会话').removeAttr('data-screen');
897
+ }
882
898
  }
883
899
  });
900
+ this_obj.html("<span title='会话数据获取中...' class='label label-info'>会话</span>");
901
+ Util.show_tips("进程 [" + pid + "(" + action + ")] 已加到会话队列中", 4567, "alert-success");
902
+ } else if (j["code"] === 2) {
903
+ Util.show_tips("Machine 不存在!", 4567, "alert-danger");
904
+ } else if (j["code"] === 3) {
905
+ Util.show_tips("进程 [" + pid + "(" + action + ")] 异常!", 4567, "alert-danger");
906
+ } else {
907
+ Util.show_tips("进程值不能为空!", 4567, "alert-danger");
884
908
  }
885
- }
886
- });
887
- });
888
- } else if (is_init === 1) {
889
- $('#machines').html('<option value="">暂无Machine</option>');
890
- }
891
- Util.hide_tips();
909
+ });
910
+ }
911
+ }
912
+ });
892
913
  });
893
914
  },
894
915
 
916
+ pack_screen_html: function(is_screen, pid, screen_pid, screen_pid_date) {
917
+ if (is_screen === 1) {
918
+ let screen_html = "";
919
+ if (screen_pid === pid) {
920
+ if (screen_pid_date > 0) {
921
+ screen_html = "<a data-screen='1' class='process_screen' href='#'><span title='会话数据已成功获取(" + Util.seconds_to_format(screen_pid_date) + ")' class='label label-success'>会话</span></a>";
922
+ } else {
923
+ screen_html = "<a class='process_screen' href='#'><span title='会话数据获取中...' class='label label-info'>会话</span></a>";
924
+ }
925
+ } else {
926
+ screen_html = "<a class='process_screen' href='#'>会话</a>";
927
+ }
928
+ return "<td><a class='process_kill' href='#'>终止</a>&nbsp;&nbsp;" + screen_html + "</td>";
929
+ } else {
930
+ return "<td><a class='process_kill' href='#'>终止</a></td>"
931
+ }
932
+ },
933
+
895
934
  parse_machine_action: function(cmdline) {
896
935
  if (cmdline.includes("xmrig") || cmdline.includes("zotonic")) {
897
936
  return "xmr";
package/util.js CHANGED
@@ -22,7 +22,7 @@
22
22
  */
23
23
  const Util = {
24
24
 
25
- version: "0",
25
+ version: "",
26
26
  tips_token: "util-tips-div",
27
27
  load_token: "loading_div",
28
28
  interval_timer: null,