From 630115fcec561fe8f8c6227286b3010ab76b5cb0 Mon Sep 17 00:00:00 2001 From: shudi Date: Mon, 25 May 2020 19:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8config=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E5=B0=86=E4=B8=80=E4=BA=9B=E5=8F=82=E6=95=B0=E6=94=BE?= =?UTF-8?q?=E5=9C=A8=E4=BD=BF=E7=94=A8=E6=97=B6=E4=BC=A0=E5=85=A5=EF=BC=9B?= =?UTF-8?q?=E5=9C=A8snmp=E7=9A=84=E7=9B=B8=E5=85=B3=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E5=8A=A0=E5=85=A5=E6=9F=A5=E7=9C=8Bmem=5Ffre?= =?UTF-8?q?e=20=E5=92=8Cmem=5Fusage=E7=99=BE=E5=88=86=E6=AF=94=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qyt_devnet/qyt_cisco_cmd.py | 7 ++----- qyt_devnet/qyt_cisco_snmp.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/qyt_devnet/qyt_cisco_cmd.py b/qyt_devnet/qyt_cisco_cmd.py index d900548..b271a7b 100644 --- a/qyt_devnet/qyt_cisco_cmd.py +++ b/qyt_devnet/qyt_cisco_cmd.py @@ -43,11 +43,8 @@ def show(self, show_cmds): finally: self.client.close() - def config(self, config_cmds): + def config(self, config_cmds, enable='Cisc0123', verbose=True, wait_time=2): try: - enable = 'Cisc0123' - wait_time = 2 - verbose = True chan = self.client.invoke_shell() chan.send('term len 0\n') time.sleep(1) @@ -77,6 +74,6 @@ def config(self, config_cmds): password = 'Cisc0123' client1 = QYTCiscoSSH(hostname=r1, username=username, password=password) # print(client1.show_run()) - cmds = ['show ver', 'show ip int br', ''] + cmds = ['show ver', 'configure terminal', 'router ospf 1', 'network 1.1.1.1 0.0.0.0 area 0', ''] # print(client1.show(cmds)) client1.config(cmds) diff --git a/qyt_devnet/qyt_cisco_snmp.py b/qyt_devnet/qyt_cisco_snmp.py index b76b492..1814c56 100644 --- a/qyt_devnet/qyt_cisco_snmp.py +++ b/qyt_devnet/qyt_cisco_snmp.py @@ -25,9 +25,15 @@ def location(self): def cpu_usage(self): return int(snmpv2_get(self.ip, self.ro, "1.3.6.1.4.1.9.9.109.1.1.1.1.3.7", port=self.port)[1]) - def mem_usage(self): + def mem_usage_used(self): return int(snmpv2_get(self.ip, self.ro, "1.3.6.1.4.1.9.9.109.1.1.1.1.12.7", port=self.port)[1]) + def mem_usage_free(self): + return int(snmpv2_get(self.ip, self.ro, "1.3.6.1.4.1.9.9.109.1.1.1.1.13.7", port=self.port)[1]) + + def mem_usage_percent(self): + return int(self.mem_usage_used()) / (int(self.mem_usage_used()) + int(self.mem_usage_free())) * 100 + def get_ifs(self): return [if_name[1] for if_name in snmpv2_getnext(self.ip, self.ro, "1.3.6.1.2.1.2.2.1.2", port=161)] @@ -53,8 +59,12 @@ def get_if_out_bytes(self): print(snmp_client.location()) # CPU利用率 print(snmp_client.cpu_usage()) - # 内存利用率 - print(snmp_client.mem_usage()) + # 内存使用 + print(snmp_client.mem_usage_used()) + # 内存空闲 + print(snmp_client.mem_usage_free()) + # 内存使用率 + print('{:.1f}'.format(snmp_client.mem_usage_percent())) # 接口清单 print(snmp_client.get_ifs()) # 接口速率