Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 02dd651

Browse files
author
MF Softworks
committed
[script] implemented network interface cards info
1 parent 1fb6978 commit 02dd651

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

‎.vs/Server-Monitoring-Script/v15/.suo

13.5 KB
Binary file not shown.

‎.vs/VSWorkspaceState.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ExpandedNodes": [
3+
""
4+
],
5+
"PreviewInSolutionExplorer": false
6+
}

‎.vs/slnx.sqlite

76 KB
Binary file not shown.

‎README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ The script will gather information:
1212
- Hostname
1313
- CPU
1414
- Memory
15-
- Network
15+
- Network Usage
16+
- Network Cards
1617
- Hard Drives
1718
- System OS
1819
- System Uptime
@@ -54,6 +55,22 @@ Example:
5455
],
5556
"network_up": 54,
5657
"network_down": 4150,
58+
"network_cards": [
59+
{
60+
"address": "127.0.0.1",
61+
"address6": "::1",
62+
"mac": "",
63+
"name": "Loopback Pseudo-Interface 1",
64+
"netmask": "255.0.0.0"
65+
},
66+
{
67+
"address": "10.15.62.112",
68+
"address6": "fe80::844d:a87:54ea:2100",
69+
"mac": "1C-39-47-A6-4C-5E",
70+
"name": "Ethernet",
71+
"netmask": "255.255.0.0"
72+
}
73+
],
5774
"timestamp" : "2018年10月10日T01:41:21+00:00",
5875
"uuid" : 180331603484325
5976
}

‎monitor.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,51 @@ def main():
2222
print("Disks:")
2323
disks = []
2424
for x in disk_info:
25-
disk = {
26-
"name" : x.device,
27-
"mount_point" : x.mountpoint,
28-
"type" : x.fstype,
29-
"total_size" : psutil.disk_usage(x.mountpoint).total,
30-
"used_size" : psutil.disk_usage(x.mountpoint).used,
31-
"percent_used" : psutil.disk_usage(x.mountpoint).percent
32-
}
33-
34-
disks.append(disk)
35-
36-
print("\tDisk name",disk["name"], "\tMount Point:", disk["mount_point"], "\tType",disk["type"], "\tSize:", disk["total_size"] / 1e+9,"\tUsage:", disk["used_size"] / 1e+9, "\tPercent Used:", disk["percent_used"])
37-
38-
# Network Info
25+
# Try fixes issues with connected 'disk' such as CD-ROMS, Phones, etc.
26+
try:
27+
disk = {
28+
"name" : x.device,
29+
"mount_point" : x.mountpoint,
30+
"type" : x.fstype,
31+
"total_size" : psutil.disk_usage(x.mountpoint).total,
32+
"used_size" : psutil.disk_usage(x.mountpoint).used,
33+
"percent_used" : psutil.disk_usage(x.mountpoint).percent
34+
}
35+
36+
disks.append(disk)
37+
38+
print("\tDisk name",disk["name"], "\tMount Point:", disk["mount_point"], "\tType",disk["type"], "\tSize:", disk["total_size"] / 1e+9,"\tUsage:", disk["used_size"] / 1e+9, "\tPercent Used:", disk["percent_used"])
39+
except:
40+
print("")
41+
42+
# Bandwidth Info
3943
network_stats = get_bandwidth()
4044
print("Network:\n\tTraffic in:",network_stats["traffic_in"] / 1e+6,"\n\tTraffic out:",network_stats["traffic_out"] / 1e+6)
4145

46+
# Network Info
47+
nics = []
48+
print("NICs:")
49+
for name, snic_array in psutil.net_if_addrs().items():
50+
# Create NIC object
51+
nic = {
52+
"name": name,
53+
"mac": "",
54+
"address": "",
55+
"address6": "",
56+
"netmask": ""
57+
}
58+
# Get NiC values
59+
for snic in snic_array:
60+
if snic.family == -1:
61+
nic["mac"] = snic.address
62+
elif snic.family == 2:
63+
nic["address"] = snic.address
64+
nic["netmask"] = snic.netmask
65+
elif snic.family == 23:
66+
nic["address6"] = snic.address
67+
nics.append(nic)
68+
print("\tNIC:",nic["name"], "\tMAC:", nic["mac"], "\tIPv4 Address:",nic["address"], "\tIPv4 Subnet:", nic["netmask"], "\tIPv6 Address:", nic["address6"])
69+
4270
# Platform Info
4371
system = {
4472
"name" : platform.system(),
@@ -68,6 +96,7 @@ def main():
6896
"drives" : disks,
6997
"network_up" : network_stats["traffic_out"],
7098
"network_down" : network_stats["traffic_in"],
99+
"network_cards": nics,
71100
"timestamp" : timestamp
72101
}
73102

@@ -108,7 +137,7 @@ def send_data(data):
108137
try:
109138
# endpoint = monitoring server
110139
endpoint = "http://monitor.localhost.local/api/"
111-
response = requests.post(url = endpoint, params = {"data" : data})
140+
response = requests.post(url = endpoint, data = data)
112141
print("\nPOST:")
113142
print("Response:", response.status_code)
114143
print("Headers:")
@@ -122,7 +151,7 @@ def send_data(data):
122151
print("No JSON content")
123152
break
124153
except requests.exceptions.RequestException as e:
125-
print("\POST Error:\n",e)
154+
print("\nPOST Error:\n",e)
126155
# Sleep 1 minute before retrying
127156
time.sleep(60)
128157
else:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /