File size: 41,257 Bytes
020c337 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | [
{
"script_id": 99,
"type_id": 6,
"is_baota": 1,
"name": "端口检测",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport socket\narg = sys.argv[-1]\nip,port = arg.split(':')\ntry:\n s = socket.socket()\n s.settimeout(0.15)\n s.connect((ip,int(port)))\n s.close()\nexcept:\n print('closed')\n sys.exit(1)\n\nprint('open')",
"version": "1.0",
"return_type": "string",
"script_type": "python",
"ps": "输出说明:closed=端口已关闭,open=端口处理打开状态",
"create_time": 1668247589,
"is_args": 1,
"args_title": "检测目标",
"args_ps": "如:127.0.0.1:443"
},
{
"script_id": 98,
"type_id": 1,
"is_baota": 1,
"name": "获取PHP服务状态",
"status": 1,
"author": "堡塔",
"script": "php_version=\"${1/./}\"\n/etc/init.d/php-fpm-$php_version status",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含stopped则表示已停止(需要输入版本号)",
"create_time": 1668245068,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请填写PHP版本,如:8.1"
},
{
"script_id": 97,
"type_id": 3,
"is_baota": 1,
"name": "发送飞书通知",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nmsg = sys.argv[-1]\nres = public.push_msg('feishu',{'msg':msg})\nif 'status' in res and res['status']:\n print(\"done\")\nelse:\n print(res)",
"version": "1.0",
"return_type": "string",
"script_type": "python",
"ps": "需要在【面板设置】- 【告警通知】- 【告警设置】中配置好飞书机器人才能成功发送",
"create_time": 1668244213,
"is_args": 1,
"args_title": "通知内容",
"args_ps": "支持文本、Markdown格式"
},
{
"script_id": 96,
"type_id": 3,
"is_baota": 1,
"name": "发送企业微信通知",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nmsg = sys.argv[-1]\nres = public.push_msg('weixin',{'msg':msg})\nif 'status' in res and res['status']:\n print(\"done\")\nelse:\n print(res)",
"version": "1.0",
"return_type": "string",
"script_type": "python",
"ps": "需要在【面板设置】- 【告警通知】- 【告警设置】中配置好企业微信机器人才能成功发送",
"create_time": 1668244123,
"is_args": 1,
"args_title": "通知内容",
"args_ps": "支持字符串、Markdown格式"
},
{
"script_id": 95,
"type_id": 3,
"is_baota": 1,
"name": "发送钉钉通知",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nmsg = sys.argv[-1]\nres = public.push_msg('dingding',{'msg':msg})\nif 'status' in res and res['status']:\n print(\"done\")\nelse:\n print(res)",
"version": "1.0",
"return_type": "string",
"script_type": "python",
"ps": "需要在【面板设置】- 【告警通知】- 【告警设置】中配置好钉钉机器人才能成功发送",
"create_time": 1668243763,
"is_args": 1,
"args_title": "通知内容",
"args_ps": "支持文本、Markdown格式"
},
{
"script_id": 94,
"type_id": 3,
"is_baota": 1,
"name": "发送邮件通知",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nmsg = sys.argv[-1]\nres = public.push_msg('mail',{'title':\"【宝塔任务编排】\" + msg[:10],'msg':msg})\nif 'status' in res and res['status']:\n print(\"done\")\nelse:\n print(res)",
"version": "1.0",
"return_type": "string",
"script_type": "python",
"ps": "需要在【面板设置】- 【告警通知】- 【告警设置】中配置好【邮箱】及【收件者邮件】才能成功发送",
"create_time": 1668243392,
"is_args": 1,
"args_title": "通知内容",
"args_ps": "支持文本、HTML格式"
},
{
"script_id": 93,
"type_id": 3,
"is_baota": 1,
"name": "发送公众号通知",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nmsg = sys.argv[-1]\nres = public.push_msg('wx_account',{'msg':msg})\nif 'status' in res and res['status']:\n print(\"done\")\nelse:\n print(res)",
"version": "1.0",
"return_type": "string",
"script_type": "python",
"ps": "需要在【面板设置】- 【告警通知】- 【告警设置】中完成微信绑定才能成功发送",
"create_time": 1668243176,
"is_args": 1,
"args_title": "通知内容",
"args_ps": "支持文本、Markdown格式"
},
{
"script_id": 92,
"type_id": 5,
"is_baota": 1,
"name": "获取指定网站描述",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@author hwliang(hwl@bt.cn)\n#@print string\nimport sys\nimport requests\nimport re\n\nsys.stdout.reconfigure(encoding='utf-8')\nsys.stderr.reconfigure(encoding='utf-8')\n\nurl = sys.argv[-1]\ntry:\n res = requests.get(url,timeout=30)\n res.encoding = res.apparent_encoding\nexcept Exception as ex:\n print(ex)\n sys.exit(1)\ndescription = re.findall(r\"<meta\\s+name=\\\"description\\\"\\s+content=\\\"(.{0,1024})\\\"\\s?\\/?>\", res.text)\nif description:\n print(description[0])\nelse:\n print('无')",
"version": "1.1",
"return_type": "string",
"script_type": "python",
"ps": "如果结果为空或者未获取到,则输出\"空\"",
"create_time": 1668242334,
"is_args": 1,
"args_title": "URL地址",
"args_ps": "请填写URL地址,如:https://www.bt.cn"
},
{
"script_id": 91,
"type_id": 5,
"is_baota": 1,
"name": "获取指定网站关键词",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@author hwliang(hwl@bt.cn)\n#@print string\nimport sys\nimport requests\nimport re\n\nsys.stdout.reconfigure(encoding='utf-8')\nsys.stderr.reconfigure(encoding='utf-8')\n\nurl = sys.argv[-1]\ntry:\n res = requests.get(url,timeout=30)\n res.encoding = res.apparent_encoding\nexcept Exception as ex:\n print(ex)\n sys.exit(1)\nkeywords = re.findall(r\"<meta\\s+name=\\\"keywords\\\"\\s+content=\\\"(.{0,1024})\\\"\\s*\\/?>\", res.text)\nif keywords:\n print(keywords[0])\nelse:\n print('无')",
"version": "1.1",
"return_type": "string",
"script_type": "python",
"ps": "如果结果为空或者未获取到,则输出\"空\"",
"create_time": 1668242220,
"is_args": 1,
"args_title": "URL地址",
"args_ps": "请填写URL地址,如:https://www.bt.cn"
},
{
"script_id": 90,
"type_id": 5,
"is_baota": 1,
"name": "获取指定网站标题",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@author hwliang(hwl@bt.cn)\n#@print string\nimport sys\nimport requests\nimport re\n\nsys.stdout.reconfigure(encoding='utf-8')\nsys.stderr.reconfigure(encoding='utf-8')\n\nurl = sys.argv[-1]\ntry:\n res = requests.get(url,timeout=30)\n res.encoding = res.apparent_encoding\nexcept Exception as ex:\n print(ex)\n sys.exit(1)\ntitle = re.findall(r\"<title>[\\s]*(.{0,1024})\\s*<\\/title>\", res.text)\nif title:\n print(title[0])\nelse:\n print('无')",
"version": "1.1",
"return_type": "string",
"script_type": "python",
"ps": "如果结果为空或者未获取到,则输出\"空\"",
"create_time": 1668242092,
"is_args": 1,
"args_title": "URL地址",
"args_ps": "请填写URL地址,如:https://www.bt.cn"
},
{
"script_id": 89,
"type_id": 5,
"is_baota": 1,
"name": "获取指定URL地址的响应状态",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取指定URL地址的响应内容\n#@author hwliang(hwl@bt.cn)\n#@print string\nimport sys\nimport requests\n\nsys.stdout.reconfigure(encoding='utf-8')\nsys.stderr.reconfigure(encoding='utf-8')\n\nurl = sys.argv[-1]\ntry:\n res = requests.get(url,timeout=30)\n res.encoding = res.apparent_encoding\nexcept Exception as ex:\n print(ex)\n sys.exit(1)\nprint(res.status_code)",
"version": "1.1",
"return_type": "int",
"script_type": "python",
"ps": "获取指定URL地址的响应状态",
"create_time": 1668241817,
"is_args": 1,
"args_title": "URL地址",
"args_ps": "请填写URL地址,如:https://www.bt.cn"
},
{
"script_id": 88,
"type_id": 5,
"is_baota": 1,
"name": "获取指定URL地址的响应内容",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取指定URL地址的响应内容\n#@author hwliang(hwl@bt.cn)\n#@print string\nimport sys\nimport requests\n\nsys.stdout.reconfigure(encoding='utf-8')\nsys.stderr.reconfigure(encoding='utf-8')\n\nurl = sys.argv[-1]\ntry:\n res = requests.get(url,timeout=30)\n res.encoding = res.apparent_encoding\nexcept Exception as ex:\n print(ex)\n sys.exit(1)\nprint(res.text)",
"version": "1.1",
"return_type": "string",
"script_type": "python",
"ps": "获取指定URL地址的响应内容",
"create_time": 1668241548,
"is_args": 1,
"args_title": "URL地址",
"args_ps": "请填写URL地址,如:https://www.bt.cn"
},
{
"script_id": 87,
"type_id": 4,
"is_baota": 1,
"name": "获取指定分区的磁盘可用容量",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取/www分区的磁盘可用容量(单位GB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nimport sys\ndev_path = sys.argv[-1]\ndisk_usage = psutil.disk_usage(dev_path)\nfree_size = disk_usage.free / 1024 / 1024 / 1024\nprint(\"{:.2f}\".format(free_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(GB)",
"create_time": 1668241167,
"is_args": 1,
"args_title": "分区路径",
"args_ps": "请填写分区挂载路径,如:/www"
},
{
"script_id": 86,
"type_id": 2,
"is_baota": 1,
"name": "获取PHP的内存占用",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\n# PHP版本\nphp_version=sys.argv[-1]\nphp_version = php_version.replace('.','')\n# 进程名称(必需)\nprocess_name = 'php-fpm'\n# 进程绝对路径,可为None\nbin_file=None\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\n# 获取进程PID\ncmd_line = 'php-fpm: master process (/www/server/php/{}/etc/php-fpm.conf)'.format(php_version)\npid = public.get_process_pid(process_name,bin_file,cmd_line)\nif not pid:\n print(\"错误:获取进程PID失败: {}\".format(process_name))\n print(0)\n sys.exit(1)\n\n# 检查是否为有效PID\nif not public.pid_exists(pid):\n print(0)\n sys.exit(1)\n \nused_total_bytes = 0\n# 获取内存信息\ntry:\n process = psutil.Process(pid)\n mem_info = process.memory_full_info()\n used_total_bytes += mem_info.uss\nexcept:\n print(0)\n sys.exit(1)\n \nfor mpid in psutil.pids():\n try:\n process = psutil.Process(mpid)\n if process.name() != process_name: continue\n if process.ppid() != pid: continue\n mem_info = process.memory_full_info()\n used_total_bytes += mem_info.uss\n except:\n pass\n \n# 单位转换\nmem_used_size = used_total_bytes / 1024 / 1024\n\n# 输出\nprint(\"{:.2f}\".format(mem_used_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(MB)",
"create_time": 1668240991,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请填写PHP版本,如:8.1"
},
{
"script_id": 85,
"type_id": 2,
"is_baota": 1,
"name": "获取PHP的CPU使用率",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取指定进程CPU使用率\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\nimport threading\n# PHP版本\nphp_version=sys.argv[-1]\nphp_version = php_version.replace('.','')\n\n# 进程名称(必需)\nprocess_name = 'php-fpm'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/php/{}/sbin/php-fpm\".format(php_version)\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\ncpu_count = psutil.cpu_count()\ncpu_percent = 0.00\ndef get_percent(process):\n global cpu_count,cpu_percent\n c = process.cpu_percent(1) / cpu_count\n cpu_percent += c\n \n\n\n# 获取CPU使用率\npid_thread_dict = {}\nfor pid in psutil.pids():\n try:\n process = psutil.Process(pid)\n if process.name() != process_name: continue\n if bin_file and process.exe() != bin_file: continue\n pid_thread_dict[pid] = threading.Thread(target=get_percent,args=(process,))\n pid_thread_dict[pid].start()\n except:\n continue\n\nfor pid in pid_thread_dict.keys():\n pid_thread_dict[pid].join()\n\n# 输出\nprint(\"{:.2f}\".format(cpu_percent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(%)",
"create_time": 1668240881,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请填写PHP版本,如:8.1"
},
{
"script_id": 84,
"type_id": 1,
"is_baota": 1,
"name": "启动PHP服务",
"status": 1,
"author": "堡塔",
"script": "php_version=\"${1/./}\"\n/etc/init.d/php-fpm-$php_version start",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功(需要输入版本号)",
"create_time": 1668240713,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请填写PHP版本,如:8.1"
},
{
"script_id": 83,
"type_id": 1,
"is_baota": 1,
"name": "停止PHP服务",
"status": 1,
"author": "堡塔",
"script": "php_version=\"${1/./}\"\n/etc/init.d/php-fpm-$php_version stop",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功(需要输入版本号)",
"create_time": 1668240680,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请填写PHP版本,如:8.1"
},
{
"script_id": 82,
"type_id": 1,
"is_baota": 1,
"name": "重载PHP配置文件",
"status": 1,
"author": "堡塔",
"script": "php_version=\"${1/./}\"\n/etc/init.d/php-fpm-$php_version reload",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功(需要输入版本号)",
"create_time": 1668240627,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请填写PHP版本,如:8.1"
},
{
"script_id": 81,
"type_id": 1,
"is_baota": 1,
"name": "重启PHP服务",
"status": 1,
"author": "堡塔",
"script": "php_version=\"${1/./}\"\n/etc/init.d/php-fpm-$php_version restart",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功(需要输入版本号)",
"create_time": 1668240442,
"is_args": 1,
"args_title": "PHP版本",
"args_ps": "请输入PHP版本,如8.1"
},
{
"script_id": 79,
"type_id": 4,
"is_baota": 1,
"name": "获取网络收包数",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取网络收包数(个/秒)\n#@author hwliang(hwl@bt.cn)\n#@print int\nimport psutil\nimport time\nold_netio = psutil.net_io_counters()\ntime.sleep(1)\nnew_netio = psutil.net_io_counters()\npackets_recv = (new_netio.packets_recv - old_netio.packets_recv)\n\nprint(packets_recv)",
"version": "1.0",
"return_type": "int",
"script_type": "python",
"ps": "单位(个/秒)",
"create_time": 1668220545,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 78,
"type_id": 4,
"is_baota": 1,
"name": "获取网络发包数",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取网络发包数(个/秒)\n#@author hwliang(hwl@bt.cn)\n#@print int\nimport psutil\nimport time\nold_netio = psutil.net_io_counters()\ntime.sleep(1)\nnew_netio = psutil.net_io_counters()\npackets_sent = (new_netio.packets_sent - old_netio.packets_sent)\n\nprint(packets_sent)",
"version": "1.0",
"return_type": "int",
"script_type": "python",
"ps": "单位(个/秒)",
"create_time": 1668220488,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 77,
"type_id": 4,
"is_baota": 1,
"name": "获取网络下行速度",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取下行流量大小(单位KB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nimport time\nold_netio = psutil.net_io_counters()\ntime.sleep(1)\nnew_netio = psutil.net_io_counters()\nbytes_recv = (new_netio.bytes_recv - old_netio.bytes_recv) / 1024\n\nprint(\"{:.2f}\".format(bytes_recv))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(KB/秒)",
"create_time": 1668220379,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 76,
"type_id": 4,
"is_baota": 1,
"name": "获取网络上行速度",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取上行流量大小(单位KB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nimport time\nold_netio = psutil.net_io_counters()\ntime.sleep(1)\nnew_netio = psutil.net_io_counters()\nbytes_sent = (new_netio.bytes_sent - old_netio.bytes_sent) / 1024\n\nprint(\"{:.2f}\".format(bytes_sent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(KB/秒)",
"create_time": 1668220318,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 75,
"type_id": 4,
"is_baota": 1,
"name": "获取内存使用率",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取内存使用率\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nvirtual_memory = psutil.virtual_memory()\nmemory_percent = 100 * ((virtual_memory.total - (virtual_memory.free + virtual_memory.buffers + virtual_memory.cached)) / virtual_memory.total )\nprint(\"{:.2f}\".format(memory_percent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(%)",
"create_time": 1668219497,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 74,
"type_id": 4,
"is_baota": 1,
"name": "获取已用内存大小",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取已用内存大小(单位MB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nvirtual_memory = psutil.virtual_memory()\nused_size = (virtual_memory.total - (virtual_memory.free + virtual_memory.buffers + virtual_memory.cached)) / 1024 / 1024\nprint(\"{:.2f}\".format(used_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(MB)",
"create_time": 1668219428,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 73,
"type_id": 4,
"is_baota": 1,
"name": "获取可用内存大小",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取可用内存大小(单位MB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nvirtual_memory = psutil.virtual_memory()\nfree_size = (virtual_memory.free + virtual_memory.buffers + virtual_memory.cached) / 1024 / 1024\nprint(\"{:.2f}\".format(free_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(MB)",
"create_time": 1668219298,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 72,
"type_id": 4,
"is_baota": 1,
"name": "获取已使用的swap大小",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取已使用的swap大小(单位MB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nswap_memory = psutil.swap_memory()\nswap_used = swap_memory.used / 1024 / 1024\nprint(\"{:.2f}\".format(swap_used))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(MB)",
"create_time": 1668219039,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 71,
"type_id": 4,
"is_baota": 1,
"name": "获取/www分区的磁盘可用容量",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取/www分区的磁盘可用容量(单位GB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\ndisk_usage = psutil.disk_usage('/www')\nfree_size = disk_usage.free / 1024 / 1024 / 1024\nprint(\"{:.2f}\".format(free_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(GB)",
"create_time": 1668218898,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 70,
"type_id": 4,
"is_baota": 1,
"name": "获取根分区(/)的磁盘可用容量",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取根分区(/)的磁盘可用容量(单位GB)\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\ndisk_usage = psutil.disk_usage('/')\nfree_size = disk_usage.free / 1024 / 1024 / 1024\nprint(\"{:.2f}\".format(free_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(GB)",
"create_time": 1668218820,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 69,
"type_id": 4,
"is_baota": 1,
"name": "获取网络连接数",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取网络连接数\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\nprint(len(psutil.net_connections()))",
"version": "1.0",
"return_type": "int",
"script_type": "python",
"ps": "获取网络连接数",
"create_time": 1668218591,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 68,
"type_id": 4,
"is_baota": 1,
"name": "获取CPU使用率",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取CPU使用率\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport psutil\ncpu_count = psutil.cpu_count()\ncpu_percent = psutil.cpu_percent(1) / cpu_count\nprint(\"{:.2f}\".format(cpu_percent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "获取每秒CPU使用率(%)",
"create_time": 1668218234,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 67,
"type_id": 4,
"is_baota": 1,
"name": "获取系统进程数量",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取系统进程数量\n#@author hwliang(hwl@bt.cn)\n#@print int\nimport psutil\npids = psutil.pids()\nprint(len(pids))",
"version": "1.0",
"return_type": "int",
"script_type": "python",
"ps": "获取正在运行的进程数量(个)",
"create_time": 1668218094,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 66,
"type_id": 4,
"is_baota": 1,
"name": "获取最近15分钟平均负载",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取系统最近1分钟平均负载\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport os\nload_average = os.getloadavg()\nprint(load_average[2])",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "load average,系统最近15分钟平均负载",
"create_time": 1668217975,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 65,
"type_id": 4,
"is_baota": 1,
"name": "获取最近5分钟平均负载",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取系统最近1分钟平均负载\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport os\nload_average = os.getloadavg()\nprint(load_average[1])",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "load average,系统最近5分钟平均负载",
"create_time": 1668217953,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 64,
"type_id": 4,
"is_baota": 1,
"name": "获取最近1分钟平均负载",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取系统最近1分钟平均负载\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport os\nload_average = os.getloadavg()\nprint(load_average[0])",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "load average,系统最近1分钟平均负载",
"create_time": 1668217869,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 60,
"type_id": 2,
"is_baota": 1,
"name": "获取Apache的CPU使用率",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\n#@name 获取指定进程CPU使用率\n#@author hwliang(hwl@bt.cn)\n#@print float\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\nimport threading\n\n# 进程名称(必需)\nprocess_name = 'httpd'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/apache/bin/httpd\"\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\ncpu_count = psutil.cpu_count()\ncpu_percent = 0.00\ndef get_percent(process):\n global cpu_count,cpu_percent\n c = process.cpu_percent(1) / cpu_count\n cpu_percent += c\n \n\n\n# 获取CPU使用率\npid_thread_dict = {}\nfor pid in psutil.pids():\n try:\n process = psutil.Process(pid)\n if process.name() != process_name: continue\n if bin_file and process.exe() != bin_file: continue\n pid_thread_dict[pid] = threading.Thread(target=get_percent,args=(process,))\n pid_thread_dict[pid].start()\n except:\n continue\n\nfor pid in pid_thread_dict.keys():\n pid_thread_dict[pid].join()\n\n# 输出\nprint(\"{:.2f}\".format(cpu_percent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(%)",
"create_time": 1668157345,
"is_args": 0,
"args_title": "",
"args_ps": ""
},
{
"script_id": 59,
"type_id": 2,
"is_baota": 1,
"name": "获取Nginx的CPU使用率",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\nimport threading\n\n# 进程名称(必需)\nprocess_name = 'nginx'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/nginx/sbin/nginx\"\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\ncpu_count = psutil.cpu_count()\ncpu_percent = 0.00\ndef get_percent(process):\n global cpu_count,cpu_percent\n c = process.cpu_percent(1) / cpu_count\n cpu_percent += c\n \n\n\n# 获取CPU使用率\npid_thread_dict = {}\nfor pid in psutil.pids():\n try:\n process = psutil.Process(pid)\n if process.name() != process_name: continue\n if bin_file and process.exe() != bin_file: continue\n pid_thread_dict[pid] = threading.Thread(target=get_percent,args=(process,))\n pid_thread_dict[pid].start()\n except:\n continue\n\nfor pid in pid_thread_dict.keys():\n pid_thread_dict[pid].join()\n\n# 输出\nprint(\"{:.2f}\".format(cpu_percent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(%)",
"create_time": 1668156750,
"is_args": 0,
"args_title": "",
"args_ps": ""
},
{
"script_id": 58,
"type_id": 2,
"is_baota": 1,
"name": "获取MySQL的CPU使用率",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\nimport threading\n\n# 进程名称(必需)\nprocess_name = 'mysqld'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/mysql/bin/mysqld\"\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\ncpu_count = psutil.cpu_count()\ncpu_percent = 0.00\ndef get_percent(process):\n global cpu_count,cpu_percent\n c = process.cpu_percent(1) / cpu_count\n cpu_percent += c\n\n\n# 获取CPU使用率\npid_thread_dict = {}\nfor pid in psutil.pids():\n try:\n process = psutil.Process(pid)\n if process.name() != process_name: continue\n if bin_file and process.exe() != bin_file: continue\n pid_thread_dict[pid] = threading.Thread(target=get_percent,args=(process,))\n pid_thread_dict[pid].start()\n except:\n continue\n\nfor pid in pid_thread_dict.keys():\n pid_thread_dict[pid].join()\n\n# 输出\nprint(\"{:.2f}\".format(cpu_percent))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "仅mysqld进程,单位(%)",
"create_time": 1668155455,
"is_args": 0,
"args_title": "",
"args_ps": ""
},
{
"script_id": 54,
"type_id": 2,
"is_baota": 1,
"name": "获取Apache内存占用",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\n\n# 进程名称(必需)\nprocess_name = 'httpd'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/apache/bin/httpd\"\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\n# 获取进程PID\npid = public.get_process_pid(process_name,bin_file)\nif not pid:\n print(\"错误:获取进程PID失败: {}\".format(process_name))\n print(0)\n sys.exit(1)\n\n# 检查是否为有效PID\nif not public.pid_exists(pid):\n print(0)\n sys.exit(1)\n \n# 获取内存信息\ntry:\n process = psutil.Process(pid)\n mem_info = process.memory_full_info()\nexcept:\n print(0)\n sys.exit(1)\n \n# 单位转换\nmem_used_size = mem_info.uss / 1024 / 1024\n\n# 输出\nprint(\"{:.2f}\".format(mem_used_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(MB)",
"create_time": 1668150591,
"is_args": 0,
"args_title": "",
"args_ps": ""
},
{
"script_id": 53,
"type_id": 2,
"is_baota": 1,
"name": "获取Nginx内存占用",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\n\n# 进程名称(必需)\nprocess_name = 'nginx'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/nginx/sbin/nginx\"\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\n# 获取进程PID\npid = public.get_process_pid(process_name,bin_file)\nif not pid:\n print(\"错误:获取进程PID失败: {}\".format(process_name))\n print(0)\n sys.exit(1)\n\n# 检查是否为有效PID\nif not public.pid_exists(pid):\n print(0)\n sys.exit(1)\n \n# 获取内存信息\ntry:\n process = psutil.Process(pid)\n mem_info = process.memory_full_info()\nexcept:\n print(0)\n sys.exit(1)\n \n# 单位转换\nmem_used_size = mem_info.uss / 1024 / 1024\n\n# 输出\nprint(\"{:.2f}\".format(mem_used_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "单位(MB)",
"create_time": 1668150492,
"is_args": 0,
"args_title": "",
"args_ps": ""
},
{
"script_id": 52,
"type_id": 2,
"is_baota": 1,
"name": "获取MySQL内存占用",
"status": 1,
"author": "堡塔",
"script": "#coding: utf-8\nimport os\nimport sys\nos.chdir('/www/server/panel')\nsys.path.insert(0,'class/')\nimport public\nimport psutil\n\n# 进程名称(必需)\nprocess_name = 'mysqld'\n# 进程绝对路径,可为None\nbin_file=\"/www/server/mysql/bin/mysqld\"\n\n# 如果bin_file不为None,且指定路径不存在\nif bin_file and not os.path.exists(bin_file):\n print(\"错误:指定进程路径不存在: {}\".format(bin_file))\n print(0)\n sys.exit(1)\n\n# 获取进程PID\npid = public.get_process_pid(process_name,bin_file)\nif not pid:\n print(\"错误:获取进程PID失败: {}\".format(process_name))\n print(0)\n sys.exit(1)\n\n# 检查是否为有效PID\nif not public.pid_exists(pid):\n print(0)\n sys.exit(1)\n \n# 获取内存信息\ntry:\n process = psutil.Process(pid)\n mem_info = process.memory_full_info()\nexcept:\n print(0)\n sys.exit(1)\n \n# 单位转换\nmem_used_size = mem_info.uss / 1024 / 1024\n\n# 输出\nprint(\"{:.2f}\".format(mem_used_size))",
"version": "1.0",
"return_type": "float",
"script_type": "python",
"ps": "仅mysqld进程,单位(MB)",
"create_time": 1668149446,
"is_args": 0,
"args_title": "",
"args_ps": ""
},
{
"script_id": 49,
"type_id": 1,
"is_baota": 1,
"name": "启动Nginx",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/nginx start",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功",
"create_time": 1668044622,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 48,
"type_id": 1,
"is_baota": 1,
"name": "启动MySQL",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/mysqld start",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含Starting则表示成功",
"create_time": 1668044553,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 44,
"type_id": 1,
"is_baota": 1,
"name": "重载Nginx",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/nginx reload",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功",
"create_time": 1668044290,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 43,
"type_id": 1,
"is_baota": 1,
"name": "重载MySQL",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/mysqld reload",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含Reloading则表示成功",
"create_time": 1668044127,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 39,
"type_id": 1,
"is_baota": 1,
"name": "获取Nginx状态",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/nginx status",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含stopped则表示已停止",
"create_time": 1668043943,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 38,
"type_id": 1,
"is_baota": 1,
"name": "获取MySQL状态",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/mysqld status",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含dead则表示已停止",
"create_time": 1668043876,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 19,
"type_id": 1,
"is_baota": 1,
"name": "重启MySQL",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/mysqld restart",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功",
"create_time": 1667983888,
"is_args": 0,
"args_title": null,
"args_ps": null
},
{
"script_id": 18,
"type_id": 1,
"is_baota": 1,
"name": "重启Nginx",
"status": 1,
"author": "堡塔",
"script": "/etc/init.d/nginx restart",
"version": "1.0",
"return_type": "string",
"script_type": "bash",
"ps": "如果输出包含done则表示成功",
"create_time": 1667983870,
"is_args": 0,
"args_title": null,
"args_ps": null
}
] |