added stats reporter
This commit is contained in:
		
							parent
							
								
									0da27a78c7
								
							
						
					
					
						commit
						8d372cccfb
					
				
					 7 changed files with 112 additions and 1 deletions
				
			
		|  | @ -41,5 +41,5 @@ class Client: | |||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|             better_sleep(self.pull_delay) | ||||
|             better_sleep(self.poll_delay) | ||||
| 
 | ||||
|  |  | |||
|  | @ -38,6 +38,7 @@ from utils.boxprint import bordered | |||
| from lan import LANManager | ||||
| from lan.server import LANServer | ||||
| from sneakernet import sneakernet_import_thread | ||||
| from onionrstatistics.devreporting import statistics_reporter | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|  | @ -172,6 +173,8 @@ def daemon(): | |||
|         LANManager(shared_state).start() | ||||
|     if config.get('transports.sneakernet', True): | ||||
|         Thread(target=sneakernet_import_thread, daemon=True).start() | ||||
| 
 | ||||
|     Thread(target=statistics_reporter, args=[shared_state], daemon=True).start() | ||||
|     communicator.startCommunicator(shared_state) | ||||
| 
 | ||||
|     clean_ephemeral_services() | ||||
|  |  | |||
							
								
								
									
										26
									
								
								src/onionrstatistics/devreporting/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/onionrstatistics/devreporting/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| import config | ||||
| from utils.bettersleep import better_sleep | ||||
| from utils.gettransports import get as get_transports | ||||
| from onionrutils import basicrequests | ||||
| from onionrutils import epoch | ||||
| 
 | ||||
| import json | ||||
| 
 | ||||
| def statistics_reporter(shared_state): | ||||
|     server = config.get('statistics.server', '') | ||||
|     if not config.get('statistics.i_dont_want_privacy', False) or \ | ||||
|         not server: return | ||||
| 
 | ||||
|     def compile_data(): | ||||
|         return { | ||||
|             'time': epoch.get_epoch(), | ||||
|             'adders': get_transports(), | ||||
|             'peers': shared_state.get_by_string('OnionrCommunicatorDaemon').onlinePeers | ||||
|             } | ||||
| 
 | ||||
|     while True: | ||||
|         better_sleep(5) | ||||
|         data = compile_data() | ||||
|         basicrequests.do_post_request( | ||||
|             f'http://{server}/sendstats/' + get_transports()[0], | ||||
|             data=json.dumps(data)) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue