def tmonStackMonitor():
	try:
		paramServerList = configparser.getServerList()
		paramESurl =  configparser.getESurl() 
		paramESindexName =  configparser.getESindexName()
		paramEStype = configparser.getEStype()

		tmonLog2 = []
		for i in paramServerList:
			j = i.split()
			check =  threads.getThreadStucksCount( i )[0]
			current_ts =  str(threads.getTimeStamp() )
			if check != "failed":
				hogging_cnt = threads.getThreadStucksCount( i )[1]
				stuck_cnt = threads.getThreadStucksCount( i )[2]
				for z in threads.getThreadStackHash( i ,  threads.getThreadStucksCount( i )[0] , paramESurl , paramESindexName , paramEStype ):
					tmonLog2.append( [ j[0] , j[5] , hogging_cnt , stuck_cnt , z[0] , current_ts] )
			else:
				print "debug: tmonStackMonitor - there is an issue to get attribute value, please check if server is available. \n"
		return tmonLog2
	
	except WLSTException,e:
                # this typically means the server is not active, just ignore
		print "debug: tmonStackMonitor " + str(e)
		pass	
def tmonStackMonitor():
	try:
		paramServerList = configparser.getServerList()
		paramESurl =  configparser.getESurl() 
		paramESindexName =  configparser.getESindexName()
		paramEStype = configparser.getEStype()

		tmonLog2 = []
		for args in paramServerList:
			profile_server = args.split()
			threads_stucks = threads.getThreadStucksCount( args )
			#check =  threads.getThreadStucksCount( i )[0]
			check =  threads_stucks[0]
			current_ts =  str(threads.getTimeStamp() )
			if check != "failed":
				hogging_cnt = threads_stucks[1]
				stuck_cnt = threads_stucks[2]
				thread_list = threads_stucks[0]
				for threads_hash in threads.getThreadStackHash( args ,  thread_list , paramESurl , paramESindexName , paramEStype ):
					tmonLog2.append( [ profile_server[0] , profile_server[5],  threads_hash[0],  threads_hash[2] , threads_hash[3] , current_ts] )
			else:
				print "debug: tmonStackMonitor - there is an issue to get attribute value, please check if server is available. \n"
		return tmonLog2
	
	except WLSTException,e:
                # this typically means the server is not active, just ignore
		print "debug: tmonStackMonitor " + str(e)
		pass	
def tmonMetricsMonitor():
		# parameter from tmon3.0.conf
		paramServerList = configparser.getServerList()
		#paramAdminUser 	= configparser.getAdminUser()
		#paramAdminPass	= configparser.getAdminPass()
		#paramConnectString = configparser.getConnectString()
		tmonLog = []	
	
		# tmonLog variable which has the data to be printed in the log file
		for args in paramServerList:
			try:
				start = datetime.datetime.now()
				profile_server = args.split()
				server_name = profile_server[0]
				app_name = profile_server[5]
				gc_metrics = str(metrics.getGCmetrics( args ) )
				heap_usage =  str(metrics.getJVMmetrics( args )) 
				http_sessions =  str(metrics.getHTTPSessions( args ))
				open_sockets =  str(metrics.getOpenSockets( args ))
				current_ts =  str(metrics.getTimeStamp() )

				check =  threads.getThreadStucksCount( args )[0]

				if check != "failed":
					threads_info =  threads.getThreadStucksCount( args )
					 #[0] threads id list , [1] count threads hogging , [2] count threads stuck , [3] Throughput , [4] ExecuteThreadTotalCount , [5] ExecuteThreadIdleCount
					print "debug: elapsed" + str(threads_info[0])
					hogging_cnt  = threads_info[1]
					stuck_cnt    = threads_info[2] 
					thread_Throughput =  threads_info[3]
					thread_ExecuteThreadTotalCount = threads_info[4]
					thread_ExecuteThreadIdleCount = threads_info[5]
				else:
					print "debug: tmonStackMonitor - there is an issue to get attribute value, please check if server is available. \n"

				if gc_metrics != "failed":
					tmonLog.append( [ server_name , app_name , gc_metrics , heap_usage , http_sessions , open_sockets , hogging_cnt , stuck_cnt , thread_Throughput , thread_ExecuteThreadTotalCount  , thread_ExecuteThreadIdleCount ,  current_ts ])
					#container || app || gc time || gc count || heap usage || http sessions cnt || open sockets cnt || hogging cnt || stuck cnt|| Throughput || ExecuteThreadTotalCount || ExecuteThreadIdleCount || timestamp 
				else:
					print "debug: tmonMetricsMonitor - there is an issue to get attribute value, please check if server is available. \n"
				end = datetime.datetime.now()
				diff = end - start
				print "function (tmonMetricsMonitor) container: " + server_name +  " tooks about: " + str(int(round(diff.microseconds / 1000))) + " to finish."
			except WLSTException,e:
				print "debug: tmonMetricsMonitor " + str(e)