mirror of
				https://github.com/Telecominfraproject/wlan-cloud-loadsim.git
				synced 2025-10-31 02:27:57 +00:00 
			
		
		
		
	Change from start to offset
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ PROJECT = owls | ||||
| PROJECT_DESCRIPTION = OpenWiFi Load Simulator (OWLS) | ||||
| PROJECT_VERSION = 0.1.0 | ||||
|  | ||||
| DEPS = lager gpb jiffy cowlib ranch gun cowboy rec2json uuid yamerl | ||||
| DEPS = lager gpb jiffy cowlib ranch gun cowboy rec2json uuid yamerl jsx | ||||
|  | ||||
| ERLC_OPTS += -I deps/gpb/include | ||||
| ERLC_OPTS += +'{parse_transform, lager_transform}' | ||||
|   | ||||
| @@ -19,6 +19,29 @@ | ||||
| 	report = #{} :: #{} | ||||
| 	}). | ||||
|  | ||||
| -record( stat_os_report, { | ||||
| 	cpu_avg1 :: number(), | ||||
| 	cpu_avg5 :: number(), | ||||
| 	cpu_avg15:: number(), | ||||
| 	number_of_processes :: number(), | ||||
| 	sysmem_high_watermark :: number(), | ||||
| 	procmem_high_watermark :: number(), | ||||
| 	cpu_utilization :: number(), | ||||
| 	mem_check_interval :: number(), | ||||
| 	mem_helper_timeout :: number(), | ||||
| 	disk_check_interval :: number(), | ||||
| 	memory_data = [] :: [ { atom(), number()} ], | ||||
| 	number_of_cpus :: number(), | ||||
| 	kernel_utilization :: number(), | ||||
| 	nice_user :: number(), | ||||
| 	user :: number(), | ||||
| 	idle :: number(), | ||||
| 	disk_almost_full_threshold :: number(), | ||||
| 	disk_details :: [{string(),number()}], | ||||
| 	system_memory_data :: [{ atom() , number() }], | ||||
| 	cpu_details :: [ [ { string(), number() }]] | ||||
| }). | ||||
|  | ||||
| -type stat_report() :: #stat_report{}. | ||||
|  | ||||
| -export_type([stat_report/0]). | ||||
|   | ||||
| @@ -80,10 +80,10 @@ full_start(State)-> | ||||
| -spec run_client(Socket::ssl:sslsocket(),CS::#client_state{}) -> #client_state{}. | ||||
| run_client(Socket,CS)-> | ||||
| 	%% "/ap/sim1-1-000050_SIM1000050/opensync" | ||||
| 	RealSerial = case string:tokens(binary_to_list(CS#client_state.topics),"/") of | ||||
| 		             [_,Serial,_] -> list_to_binary(Serial); | ||||
| 								 _ -> CS#client_state.details#client_info.serial | ||||
| 	             end, | ||||
| 	%%RealSerial = case string:tokens(binary_to_list(CS#client_state.topics),"/") of | ||||
| 	%%	             [_,Serial,_] -> list_to_binary(Serial); | ||||
| 	%%							 _ -> CS#client_state.details#client_info.serial | ||||
| 	%%            end, | ||||
|  | ||||
| 	C = #mqtt_connect_variable_header{ | ||||
| 		protocol_version = ?MQTT_PROTOCOL_VERSION_3_11, | ||||
| @@ -93,7 +93,7 @@ run_client(Socket,CS)-> | ||||
| 		will_qos_flag = 0, | ||||
| 		will_flag = 0 , | ||||
| 		clean_start_flag = 1, | ||||
| 		client_identifier = RealSerial, | ||||
| 		client_identifier = CS#client_state.details#client_info.serial, | ||||
| 		keep_alive = 180	}, | ||||
| 	M = #mqtt_msg{ variable_header = C}, | ||||
| 	ConnectMessage = mqtt_message:encode(M), | ||||
|   | ||||
| @@ -12,6 +12,7 @@ | ||||
| -include("../include/common.hrl"). | ||||
| -include("../include/inventory.hrl"). | ||||
| -include("../include/sim_commands.hrl"). | ||||
| -include("../include/statistics.hrl"). | ||||
|  | ||||
| -compile({parse_transform, lager_transform}). | ||||
| -dialyzer(no_match). | ||||
| @@ -30,7 +31,7 @@ | ||||
| 	set_configuration/1,reset_configuration/1, | ||||
| 	get_configuration/0,set_configuration/2,get_configuration/1, | ||||
| 	update_stats/3,send_os_stats/0, | ||||
| 	start/2,restart/2,pause/2,cancel/2,stop/2]). | ||||
| 	start/2,restart/2,pause/2,cancel/2,stop/2,create_os_stats_report/0]). | ||||
|  | ||||
| %% gen_server callbacks | ||||
| -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, | ||||
| @@ -299,15 +300,44 @@ try_connecting(NodeName,State)-> | ||||
| 			end | ||||
| 	end. | ||||
|  | ||||
| volumes_to_tuples([],A)-> | ||||
| 	A; | ||||
| volumes_to_tuples([{Name,Size,_}|T],A)-> | ||||
| 	volumes_to_tuples(T,[{Name,Size}|A]). | ||||
|  | ||||
| cpu_details_to_tuples([],A)-> | ||||
| 	A; | ||||
| cpu_details_to_tuples([{Cpu,Busy,Idle,_}|T],A)-> | ||||
| 	cpu_details_to_tuples(T,[[{"CPU",Cpu},{"Busy",Busy},{"Idle",Idle}]|A]). | ||||
|  | ||||
| create_os_stats_report() -> | ||||
| 	CpuSup = #{ avg1 => cpu_sup:avg1() , avg5 => cpu_sup:avg5(), avg15 => cpu_sup:avg15(), | ||||
| 	            nprocs => cpu_sup:nprocs(), util => cpu_sup:util(), detailed => cpu_sup:util([detailed]), per_cpu => cpu_sup:util([per_cpu])}, | ||||
| 	DiskSup = #{ disk_data => disksup:get_disk_data(), check_interval => disksup:get_check_interval(), | ||||
| 	             almost_full_threshold => disksup:get_almost_full_threshold()}, | ||||
| 	MemSup = #{ check_interval => memsup:get_check_interval(), procmem_high_watermark => memsup:get_procmem_high_watermark(), | ||||
| 	            sysmem_high_watermark => memsup:get_sysmem_high_watermark(), memory_data => memsup:get_memory_data(), | ||||
| 	            helper_timeout => memsup:get_helper_timeout(), system_memory_data => memsup:get_system_memory_data()}, | ||||
| 	#{ cpu_sup => CpuSup,disk_sup => DiskSup, memsup => MemSup}. | ||||
| 	{X1,X2,{_,X3}} = memsup:get_memory_data(), | ||||
| 	MemoryData = [ {total,X1}, {allocated,X2},{biggest,X3}], | ||||
| 	{ Cpus, DetailCpu, NonBusy, _ } = cpu_sup:util([detailed]), | ||||
|  | ||||
| 	Report = #stat_os_report{ | ||||
| 		cpu_avg1 = 		cpu_sup:avg1(), | ||||
| 		cpu_avg5 = 		cpu_sup:avg5(), | ||||
| 		cpu_avg15= 		cpu_sup:avg15(), | ||||
| 		number_of_processes = cpu_sup:nprocs(), | ||||
| 		sysmem_high_watermark = memsup:get_sysmem_high_watermark(), | ||||
| 		procmem_high_watermark = memsup:get_procmem_high_watermark(), | ||||
| 		mem_check_interval = memsup:get_check_interval(), | ||||
| 		mem_helper_timeout = memsup:get_helper_timeout(), | ||||
| 		disk_check_interval = disksup:get_check_interval(), | ||||
| 		system_memory_data = memsup:get_system_memory_data(), | ||||
| 		memory_data = MemoryData, | ||||
| 		cpu_utilization = cpu_sup:util(), | ||||
| 		number_of_cpus = length(Cpus), | ||||
| 		kernel_utilization = proplists:get_value(kernel,DetailCpu,0.0), | ||||
| 		nice_user = proplists:get_value(nice_user,DetailCpu,0.0), | ||||
| 		user = proplists:get_value(user,DetailCpu,0.0), | ||||
| 		idle = proplists:get_value(idle,NonBusy,0.0), | ||||
| 		disk_almost_full_threshold = disksup:get_almost_full_threshold(), | ||||
| 		disk_details = volumes_to_tuples(disksup:get_disk_data(),[]), | ||||
| 		cpu_details = cpu_details_to_tuples(cpu_sup:util([per_cpu]),[]) | ||||
| 	}, | ||||
| 	Report. | ||||
|  | ||||
| safe_execute(undefined,_F,_A)-> | ||||
| 	ok; | ||||
|   | ||||
							
								
								
									
										21
									
								
								src/stat_os_report.erl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/stat_os_report.erl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| %%%------------------------------------------------------------------- | ||||
| %%% @author stephb | ||||
| %%% @copyright (C) 2020, Arilia Wireless Inc. | ||||
| %%% @doc | ||||
| %%% | ||||
| %%% @end | ||||
| %%% Created : 10. Dec 2020 11:28 a.m. | ||||
| %%%------------------------------------------------------------------- | ||||
| -module(stat_os_report). | ||||
| -author("stephb"). | ||||
|  | ||||
| -include("../include/statistics.hrl"). | ||||
|  | ||||
| -compile([{parse_transform, rec2json}]). | ||||
|  | ||||
| %% | ||||
| %%  Place holder for all functions generated by rec2json for record processor in/out | ||||
| %% | ||||
|  | ||||
| %% API | ||||
| -export([]). | ||||
| @@ -130,4 +130,18 @@ add_new_report(Node,Type,Report)-> | ||||
| 												                                       type = Type, | ||||
| 												                                       report = Report }) | ||||
| 	                    end ), | ||||
| 	try | ||||
| 		JSON = case Type of | ||||
| 			       os_details -> | ||||
| 				       jiffy:encode(stat_os_report:to_json(Report)); | ||||
| 						 _ -> | ||||
| 							 jiffy:encode(Report) | ||||
| 		       end, | ||||
| 		web_socket_handler:send_frame( JSON ), | ||||
| 		io:format("Good report: ~p~n",[Type]) | ||||
| 	catch | ||||
| 		_:_ -> | ||||
| 			io:format("FAILED REPORT: ~p~n",[Report]), | ||||
| 			ok | ||||
| 	end, | ||||
| 	ok. | ||||
|   | ||||
| @@ -282,4 +282,3 @@ search_replace(InFile,OutFile,Elements)-> | ||||
| 	{ ok , InData } = file:read_file(safe_list(InFile)), | ||||
| 	NewData = replace_data(binary_to_list(InData),Elements), | ||||
| 	file:write_file(safe_list(OutFile),list_to_binary(NewData)). | ||||
|  | ||||
|   | ||||
| @@ -21,6 +21,8 @@ | ||||
| 		| {stop, ws_state()}. | ||||
| -type ws_state() :: any(). | ||||
|  | ||||
| -record( conn_state, { pid, keep_alive :: timer:tref() }). | ||||
|  | ||||
| -spec init( Req :: cowboy_req:req(), State ::ws_state() ) -> { cowboy_websocket, cowboy_req:req(), State::ws_state() }. | ||||
| init(Req, State) -> | ||||
| 	%% io:format("Web socket init.~p..~n",[self()]), | ||||
| @@ -31,8 +33,9 @@ websocket_init(State)-> | ||||
| 	Pids = persistent_term:get(web_socket_pids,sets:new()), | ||||
| 	NewPids = sets:add_element(self(),Pids), | ||||
| 	persistent_term:put(web_socket_pids,NewPids), | ||||
| 	{ok,TRef} = timer:send_interval(5000,ping), | ||||
| 	%% io:format("Web socket starting. ~p..~n",[self()]), | ||||
| 	{ok,State}. | ||||
| 	{ok,State#conn_state{ pid = self(), keep_alive = TRef }}. | ||||
|  | ||||
| -spec websocket_handle(InFrame :: in_frame(),State::ws_state())-> call_result(). | ||||
| websocket_handle(InFrame,State)-> | ||||
| @@ -43,6 +46,9 @@ websocket_handle(InFrame,State)-> | ||||
| websocket_info({frame,Format,Data},State)-> | ||||
| 	%% io:format("Web socket message.~p..2~n",[self()]), | ||||
| 	{reply,{Format,Data},State}; | ||||
| websocket_info(ping,State)-> | ||||
| 	%% io:format("Web socket message.~p..2~n",[self()]), | ||||
| 	{reply,ping,State}; | ||||
| websocket_info(_Info,State)-> | ||||
| 	%% io:format("Web socket starting: ~p..3.~n",[self()]), | ||||
| 	{ok,State}. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stephane Bourque
					Stephane Bourque