首页 > 系统相关 >web nginx 大量time_wait 几乎没有establish

web nginx 大量time_wait 几乎没有establish

时间:2023-11-16 11:02:13浏览次数:35  
标签:web stdout mem replace nginx read time print disk

 

#!/usr/bin/python
# -*- coding: utf-8 -*-

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#@auhor by ruiy
#
#
#
#pip install paramiko -i https://pypi.tuna.tsinghua.edu.cn/simple
#
#pip install psutil -i https://pypi.tuna.tsinghua.edu.cn/simple
#
#注意:添加openssh 账号sshadmin必须加入administrator组,否则获取相关监控指标数据为null
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import paramiko
import datetime
import time
import os
#import psutil

dt = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
#print(type(dt))
print("时间%s"%dt)

#psutil

def get_cpu_infos():
    cpu_count = psutil.cpu_count(logical=False)
    xc_count = psutil.cpu_count()
    cpu_percent = round((psutil.cpu_percent(1)),2)
    cpu_info = (cpu_count,xc_count,cpu_percent)
    return cpu_info


def get_mem_infos():
    memory = psutil.virtual_memory()
    total_mem = round((float(memory.total) / 1024 / 1024 / 1024),2)
    used_mem = round((float(memory.used) / 1024 / 1024 / 1024),2)
    free_mem = round((float(memory.free) / 1024 / 1024 / 1024),2)
    percent_mem = round((float(memory.used) / float(memory.total) * 100),2)
    mem_info = (total_mem,used_mem,free_mem,percent_mem)
    return mem_info

def get_disk_infos():
    list = psutil.disk_partitions()
    ilen = len(list)
    i = 0
    retlist1 = []
    retlist2 = []
    disk_info_list = []

    while i < ilen:
        diskinfo = psutil.disk_usage(list[i].device)
        total_disk = round((float(diskinfo.total) / 1024 / 1024 / 1024),2)
        used_disk = round((float(diskinfo.used) / 1024 / 1024 / 1024),2)
        free_disk = round((float(diskinfo.free) / 1024 / 1024 / 1024),2)
        #percent_disk = diskinfo.percent()
        retlist1 = [i,list[i].device,total_disk,used_disk,free_disk]
        disk_info_list.append(retlist1)
        i = i + 1
    return disk_info_list

#windows


#linux

if __name__ == '__main__':
    hosts = [
    'hostname="4",port=2,username="root",password=""',
    ]
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    for i in hosts:
        #print(i)
        splitx = i.split(',')
        ipx = splitx[0].split('=')[1].replace('"','')
        #print(ipx)
        portx = int(splitx[1].split('=')[1])
        #print(portx)
        unamex = splitx[2].split('=')[1].replace('"','')
        #print(unamex)
        pwdx = splitx[3].split('=')[1].replace('"','')
        #print(pwdx)
        try:
            #建立连接
            ssh.connect(hostname=ipx,port=portx,username=unamex,password=pwdx)
            #print("建立连接")
            #ssh.connect(hostname='1.2.3.172',port=22,username='sshadmin',password='321',timeout=3)
            #ssh.connect(hostname='1.2.3.172',port=22,username='sshadmin',password='321')
            stdin_init,stdout_init,stderr_init = ssh.exec_command("hostname")
            #print((stdout_init.read()).decode('gbk'))

            time.sleep(1)

            #stdin,stdout,stderr = ssh.exec_command("kubectl exec web-deploy-86f46546f6-rzzln -n pre -- netstat | grep :80|grep ESTABLISH")
            stdin,stdout,stderr = ssh.exec_command("x=`kubectl get pods -n pre | grep web-deploy | awk '{print $1}'`&& echo pre环境-${x} && kubectl exec $x -n pre -- netstat  | grep :80")
            conns = stdout.read().decode('utf-8')
            print(conns)

            stdin_vip,stdout_vip,stderr_vip = ssh.exec_command("x=`kubectl get pods -n vip | grep web-deploy | awk '{print $1}'`&& echo vip环境-${x} && kubectl exec $x -n vip -- netstat  | grep :80")
            conns_vip = stdout_vip.read().decode('utf-8')
            print(conns_vip)
            """
            #'''
            #windows
            #cpu利用率:wmic cpu get loadpercentage
            #stdin,stdout,stderr = ssh.exec_command("wmic cpu get loadpercentage")
            stdin,stdout,stderr = ssh.exec_command("w | grep 'load average'")
            #print(stdout.read())
            #time.sleep(100)
            #cpu_percent = stdout.read().decode('utf-8').replace('LoadPercentage','').replace('\n','')
            cpu_percent = stdout.read().decode('utf-8').replace('LoadPercentage','')
            #print("cpu利用率{x}".format(x = cpu_percent))
            xx = cpu_percent
            #print(type(xx))
            #print(xx)
            #print("rui%s"%(xx))
            #xr = xx
            #print("亲%s"%xr)
            print("cpu利用率%:{var}".format(var=xx))
            time.sleep(1)

            #free -g
            stdin_mem,stdout_mem,stderr_mem = ssh.exec_command("free -g")
            mem_info = stdout_mem.read().decode('utf-8')
            print(mem_info)

            #netstat -naoltp | grep ESTABLISHED | wc -l
            stdin_conn,stdout_conn,stderr_conn = ssh.exec_command("netstat -naoltp | grep ESTABLISHED | wc -l")
            conn_info = stdout_conn.read().decode('utf-8')
            print("服务器已建立连接数:{v}".format(v=conn_info))

            #iostat sysstat
            stdin_disk_io_exec,stdout_disk_io_exec,stderr_disk_io_exec = ssh.exec_command('yum install sysstat -y')
            stdin_disk_io,stdout_disk_io,stderr_disk_io = ssh.exec_command('iostat -d -k 1 1 | grep "vda"')
            disk_io = stdout_disk_io.read().decode('utf-8')
            print(disk_io)

            #测试磁盘性能 dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct
            #
            stdin_diskiotest,stdout_diskiotest,stderr_diskiotest = ssh.exec_command("dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct")
            #stdin_diskiotest,stdout_diskiotest,stderr_diskiotest = ssh.exec_command("free -g")
            diskio = stderr_diskiotest.read().decode('utf-8')
            print("磁盘性能io测试:\n{disk_value}".format(disk_value=diskio))
            time.sleep(1)
            """
            '''

            #占用cpu前5 进程
            stdin,stdout,stderr = ssh.exec_command('Powershell.exe -Command "  Get-Process | select *,@{N=\'CPUPC\';E={[float]$_.cpu}}|sort CPUPC -desc|select Id,name -first 5"')
            cpu5 = stdout.read().decode('utf-8')
            print(cpu5)

            #mem内存信息
            #systeminfo | findstr "物理内存总量:"
            stdin,stdout,stderr = ssh.exec_command('systeminfo | findstr "物理内存总量:"')
            mem_total = stdout.read().decode('gbk').replace('物理内存总量:','').replace('\t','').replace('MB','').replace(',','').replace('\n','').replace('     ','')
            print("总内存M:%s"%mem_total)
            time.sleep(1)

            #systeminfo | findstr "可用的物理内存:"
            stdin,stdout,stderr = ssh.exec_command('systeminfo | findstr "可用的物理内存:"')
            mem_free = stdout.read().decode('gbk').replace('可用的物理内存:','').replace('\t','').replace('MB','').replace(',','').replace('\n','').replace('     ','')
            print("可用内存M:%s"%mem_free)

            mem_use = int(mem_total) - int(mem_free)
            print("已使用内存M:%s"%mem_use)
            mem_use_percent = round(mem_use / int(mem_total),2)
            print("内存使用率%:{varx}".format(varx = float(mem_use_percent) * 100))
            #print()
            time.sleep(1)

            #占用mem前5
            stdin,stdout,stderr = ssh.exec_command('Powershell.exe -Command " Get-Process | select *,@{N=\'PrivateMemorySizePC\';E={[float]$_.PrivateMemorySize}}|sort PrivateMemorySize -desc|select Id,name -first 5"')
            mem5 = stdout.read().decode('utf-8')
            print(mem5)

            #disk
            #fsutil volume diskfree c:
            #wmic logicaldisk get caption

            stdin,stdout,stderr = ssh.exec_command('wmic logicaldisk get caption')
            #disk_partion_label = stdout.read().decode('gbk')
            #print(disk_partion_label)
            time.sleep(1)
            disk_partion_l = bytes.decode(stdout.read()).split('Caption')[1].replace('\r\r\n','').replace('      ','').split(":")
            #print(disk_partion_l)
            #print(len(disk_partion_l))
            #print(disk_partion_l[0])
            #x = "{}:".format(disk_partion_l[0])
            #print(x)
            #fsutil volume diskfree x
            #剔除list中空元素
            while ' ' in disk_partion_l:
                disk_partion_l.remove(' ')
            #print(disk_partion_l)
            for i in disk_partion_l:
                lab = "{}:".format(i)
                #print(lab)
                #stdin,stdout,stderr = ssh.exec_command("{}".format(lab))
                #print("fsutil volume diskfree %s"%(lab))
                stdin,stdout,stderr = ssh.exec_command("fsutil volume diskfree %s"%(lab))
                print(stdout.read().decode('gbk'))
                time.sleep(1)
            #disk_partion_label = stdout.read().decode('gbk').replace('Caption','').replace('\r\r','').split('\n')
            #disk_partion_label = stdout.read().decode('gbk').replace('Caption','').replace('\t','').replace("\r\r\n\r\r\n",'').replace('\r\r\n','').split(":")
            #print(disk_partion_label)
            #print(disk_partion_label[0])
            """
            print(len(disk_partion_label))
            for i in disk_partion_label:
                if i =='':
                    print("null")
                else:
                    print(i)
            """
            #mem_total = bytes.decode(stdout.read())
            #print(mem_total)
            #print(os.environ['SYSTEMDRIVE'])
            #stdin_init,stdout_init,stderr_init = ssh.exec_command("wmic os get TotalVisibleMemorySize")
            #mem_total = stdout_init.read().decode('utf-8').replace('TotalVisibleMemorySize','').replace('\t','').replace('\n','').replace('MB','')
            #mem_total = stdout_init.read()
            #print(float(float(int(mem_total)) / 1024 / 1024),2)
            #print(int(mem_total))
            #print((stdout_init.read()).decode('utf-8'))
            #print((stdout_init.read()))

            #infos = bytes.decode(stdout_init.read())
            #infos
            #print(infos)
            #infos = stdout_init.read()
            #print(infos)
            '''
        except Exception as paramiko_err:
            print(paramiko_err)





    """
    cpuInfos = get_cpu_infos()
    print(cpuInfos)

    memInfos = get_mem_infos()
    print(memInfos)

    diskInfos = get_disk_infos()
    print(diskInfos)
    """

 

标签:web,stdout,mem,replace,nginx,read,time,print,disk
From: https://www.cnblogs.com/ruiy/p/17835741.html

相关文章

  • setTimeout可以将字符串当成代码执行,类比eval函数。当遇到setTimeout或者SetInterval,
    请问以下JS代码的输出顺序是?letdate=newDate()setTimeout(()=>{console.log('1')},2000)setTimeout('console.log(2)',1000);setTimeout(function(){console.log('3')},1500);while((newDate()-date)<3000){}A报错B......
  • nginx安装ssl模块
    一、引言当我们的Linux服务器上当中发布了web项目,有时候需要配置一个SSL证书,来使用https,然而我们一开始编译的Nginx的时候并没有把SSL模块一起编译进去.二、如何补装SSL模块既然在安装的时候没有编译ssl,难道把nginx卸载重新安装一次?不不不,我们只需要在原有的基础上添加ssl模块......
  • setTimeout 是浏览器环境提供的,JS 标准没有规定。不是JavaScript的全局函数,是浏览器(宿
    下列哪些函数是JavaScript的全局函数?AencodeURIBparseFloatCsetTimeoutDeval正确答案:ABD答案:A、B、D个人记忆方法:6(编码相关)+2(数据处理)+4(数字相关)+1(特殊)编码相关:escape()、unescape()、encodeURI()、decodeURI()、encodeURIComponent()、decodeURIComponent......
  • 成功实现FaceTime语音,FaceTime视频,FaceTime数据筛选,检测手机号是否开通FaceTime的
    FaceTime是苹果公司iOS和macOS(以前称MacOSX或OSX)内置的一款视频通话软件,通过Wi-Fi或者蜂窝数据接入互联网,在两个装有FaceTime的设备之间实现视频通话。其要求通话双方均具有装有FaceTime的苹果设备,苹果ID以及可接入互联网的3G/4G/5G或者Wi-Fi网络。 一、Windows电脑上部署......
  • wasmedge 轻量&可扩展&可移植的webassembly 运行时
    wasmedge是一个cncf的沙箱项目,提供了一个强大的webassembly运行时包含的特性高性能 利用了llvm进行AOT编译优化云原生的扩展 提供了非阻塞的网络以及webservice能力的rust,c,jssdk,包含了mysql数据库驱动,keyvalue存储,同时包含了ai的推理支持提供了比较完备的js支......
  • 通过时序和上下文对比学习时间序列表征《Time-Series Representation Learning via Te
    现在是2023年11月14日的22:15,肝不动了,要不先回寝室吧,明天把这篇看了,然后把文档写了。OK,明天的ToDoList.现在是2023年11月15日的10:35,继续。论文:Time-SeriesRepresentationLearningviaTemporalandContextualContrasting(IJCAI官网版本PDF)或者是:Time-SeriesRepresenta......
  • web
     定义Servlet的方法:继承  HttpServletservice的作用:根据获取用户请求的方法不同,执行不同的方法浏览器使用get请求方法访问就执行doGet方法,使用post请求方式就执行dopos方法;request是请求对象,记录了客户请求的所有数据接收参数request.getParameter()String......
  • Widows环境下安装Nginx并配置开机自启
    1下载Nginx下载地址:http://nginx.org/en/download.html2启动Nginxnginx的启动方式有两种:一种是直接点击nginx.exe启动,另一种是通过命令行启动2.1直接启动找到nginx目录,双击nginx.exe即可启动2.2命令行启动在nginx目录地址栏输入cmd,进入cmd窗口输入下列命令行nginx.exe或者st......
  • 记录--产品:请给我实现一个在web端截屏的功能!
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助一、故事的开始最近产品又开始整活了,本来是毫无压力的一周,可以小摸一下鱼的,但是突然有一天跟我说要做一个在网页端截屏的功能。作为一个工作多年的前端,早已学会了尽可能避开麻烦的需求,只做增删改查就行!我立马开......
  • Linux系统Keepalive Nginx做前置机配置
     1、软件官网下载https://www.keepalived.org/download.htmlhttp://nginx.org/download/选择软件版本如下[root@ZE-NGXFR01data]#lltotal1960-rw-------1sysadmsysadm927631Nov1510:34keepalived-2.0.10.tar.gz-rw-------1sysadmsysadm1073322Nov1511:01......