1- import socket , psutil , requests , time , json , platform
1+ import socket , time , json , datetime , platform , psutil , requests
22
33def main ():
44 # Hostname Info
@@ -49,10 +49,12 @@ def main():
4949 "version" : platform .release ()
5050 }
5151 print (system ["name" ],system ["version" ])
52-
52+
53+ # Time Info
54+ timestamp = datetime .datetime .utcnow ().strftime ("%Y-%m-%d %H:%M:%S" )
5355
5456 ## Set Machine Info
55- machine_info = {
57+ machine = {
5658 "hostname" : hostname ,
5759 "system" : system ,
5860 "cpu_count" : cpu_count ,
@@ -62,10 +64,14 @@ def main():
6264 "memory_used_percent" : memory_used_percent ,
6365 "drives" : disks ,
6466 "network_up" : network_stats ["traffic_out" ],
65- "network_down" : network_stats ["traffic_in" ]
67+ "network_down" : network_stats ["traffic_in" ],
68+ "timestamp" : timestamp
6669 }
6770
68- data = json .dumps (machine_info )
71+ data = json .dumps (machine )
72+ print ("\n Data:" )
73+ print (data )
74+
6975 post_data (data )
7076
7177def get_bandwidth ():
@@ -94,15 +100,17 @@ def get_bandwidth():
94100 return network
95101
96102def post_data (data ):
97- ## POST data
98103 try :
99- endpoint = "https://your-monitoring-server.com"
100- r = requests .post (url = endpoint , data = data )
101- print (r )
104+ endpoint = "http://monitor.localhost.local/api/"
105+ response = requests .get (url = endpoint , params = {"data" : data })
106+ print ("\n GET:" )
107+ print ("Response:" , response .status_code )
108+ print ("Headers:" , response .headers )
109+ print ("Content:\n " , response .json ())
102110 except requests .exceptions .RequestException as e :
103- print ("\n POST Error:\n " ,e )
111+ print ("\n GET Error:\n " ,e )
104112
105113while True :
106114 main ()
107115 print ("-----------------------------------------------------------------" )
108- time .sleep (5 )
116+ time .sleep (3 )
0 commit comments