//#include "StdAfx.h" #include "LocalHost.hpp" LocalHost :: LocalHost() { } LocalHost :: LocalHost(presetHandler pHandle, CLIHandler *cHandle, outputHandler *oHandle) : host(pHandle, cHandle, oHandle, HOST_LOCAL) { char hostname[HOST_NAME_MAX_SIZE]; #ifdef WIN32 WSADATA wsadata; WSAStartup(MAKEWORD(2,0), &wsadata); #endif int retCode = gethostname(hostname,sizeof(hostname)); if(retCode) { cout<<"Failed to retrieve the hostname : "<(hostname); m_pOutputHandle->createHostDataHandler(m_pCLIHandle->getOutputFileName(), m_strHostName); string hostDirPath = m_pOutputHandle->getNodeDataDir(); m_pCLIHandle->setNodeDirectory(m_strHostName,hostDirPath); // Seems no need to set this path } LocalHost :: ~LocalHost() { // Delete all the Members } bool LocalHost :: execCommandOnHost( string command, bool bWriteToTemp, ofstream* pFilePtr, vector* vec_strRes, string strFileName) { bool bStatus = true; try { string tmp; string fileName = m_pOutputHandle->getNodeDataDir(); fileName = fileName + "/"; // Need to change the location to temp folder fileName += strFileName; string commToExec = command; commToExec = commToExec + " > "; commToExec = commToExec + fileName; commToExec = commToExec + " 2>"; string strErrFile = "err_res_"; strErrFile += strFileName; #ifdef WIN32 //commToExec = commToExec + " 2>NUL"; commToExec = commToExec + strErrFile; #else //commToExec = commToExec + " 2>/dev/null"; commToExec = commToExec + strErrFile; #endif int nRes = execCommand(commToExec); if(nRes != 0) { // Commented, as this ERROR msg will be displayed in output.data //m_pCommonOutputHandle->writeDataToLogFile(STR_ERROR, m_strHostName, // "Failed to execute execCommand inside execCommandOnHost \n"); //first write the output collected so far GetOutputFromFile(fileName, bWriteToTemp, pFilePtr, vec_strRes); //now write the error msgs GetOutputFromFile(strErrFile, bWriteToTemp, pFilePtr, vec_strRes); bStatus = false; } else { GetOutputFromFile(fileName, bWriteToTemp, pFilePtr, vec_strRes); bStatus = true;; } int status = remove(fileName.c_str()); if(status != 0) { m_pCommonOutputHandle->writeDataToLogFile("ERROR", m_strHostName, "Failed to delete the file inside execCommandOnHost: " + fileName); } status = remove(strErrFile.c_str()); if(status != 0) { m_pCommonOutputHandle->writeDataToLogFile("ERROR", m_strHostName, "Failed to delete the file " + strErrFile); } } catch(std::exception& e) { string tmp = "Exception : Host: execCommandOnHost :"; tmp.append(e.what()); m_pCommonOutputHandle->writeDataToLogFile("ERROR", m_strHostName, tmp); } return bStatus; } /* int LocalHost :: execCommand(string command) { #ifdef WIN32 _flushall(); #endif int nRes = std::system(command.c_str()); return nRes; } */ bool LocalHost :: ExecCommand(string strCommand, connectionHandler *pConnection) { /* string tmpResult = m_pOutputHandle->getNodeDataDir(); tmpResult = tmpResult + "/tmpOracleResult"; strCommand = strCommand + " >"; strCommand += tmpResult; */ int nRes = execCommand(strCommand); //To hide the output to be displayed on the screen /* if(isTempHostFile(tmpResult)) { std::remove(tmpResult.c_str()); } */ return (nRes == 0) ? true: false; } bool LocalHost :: ProcessCommand(string command, bool pWriteToFile, ofstream* pFilePtr, vector* vec_strRSHData, connectionHandler* pConnectionHandle, string fileName, bool bParallelFlag) { string strRes = ""; bool bFlag = true; if(command.compare("date") == 0) { strRes = generateDateString(); if(pFilePtr && pWriteToFile) { (*pFilePtr) << strRes << "\n" << flush; } if(vec_strRSHData) { vec_strRSHData->push_back(strRes); } } else { bFlag = execCommandOnHost(command, pWriteToFile, pFilePtr, vec_strRSHData, fileName); } return bFlag; } string LocalHost :: GetHostOSType() { // Need to perform the action, if we wish to find the OS of the local host string strOutput = ""; #ifdef WIN32 strOutput = "WINDOWS"; #else string strCommand = "uname -s"; vector vec_strRes; execCommandOnHost( strCommand, false, NULL, &vec_strRes); if(vec_strRes.size() != 0) { strOutput = vec_strRes.at(0); boost::algorithm::trim(strOutput); } #endif std::transform(strOutput.begin(), strOutput.end(), strOutput.begin(), (int(*)(int))std::toupper); return strOutput; } void LocalHost :: GenerateSnapFiles() { ofstream tmpOutFile; string strTmp = ""; // Currently the awr_snap and snap_shot files are in the output folder.. // They need to be placed in a temporary folder string strFileName = m_pOutputHandle->getNodeDataDir(); string strPwd = ""; #ifndef WIN32 if(m_bSysDBAFlag) { strTmp = "connect / as sysdba"; } else { strTmp = "connect "; strTmp = strTmp + m_strOracleLogin + " "; } strPwd = "/tmp"; #else strTmp = "connect "; strTmp = strTmp + m_strOracleLogin + " "; strPwd = strFileName; #endif m_strAwrSnapFileName = strPwd + "/awr_snap.sql"; m_strSnapShotFileName = strPwd + "/snap_shot.sql"; // awr_snap.sql tmpOutFile.open(m_strAwrSnapFileName.c_str(), ios::out|ios::binary); if (tmpOutFile.is_open()) { tmpOutFile<<"whenever sqlerror exit 1;"; tmpOutFile<<"\n"; tmpOutFile << strTmp; tmpOutFile<<"\n"; tmpOutFile<<"BEGIN "; tmpOutFile<<"\n"; tmpOutFile<<"DBMS_WORKLOAD_REPOSITORY.create_snapshot();"; tmpOutFile<<"\n"; tmpOutFile<<"END;"; tmpOutFile<<"\n"; tmpOutFile<<"/"; tmpOutFile<<"\n"; tmpOutFile<<" exit;"; tmpOutFile<<"\n"; } tmpOutFile.close(); //snap_shot.sql tmpOutFile.open(m_strSnapShotFileName.c_str(), ios::out|ios::binary); if (tmpOutFile.is_open()) { tmpOutFile<<"whenever sqlerror exit 1;"; tmpOutFile<<"\n"; tmpOutFile << strTmp; tmpOutFile<<"\n"; tmpOutFile<<"select SNAP_ID from dba_hist_snapshot order by SNAP_ID;"; tmpOutFile<<"\n"; tmpOutFile<<" exit;"; tmpOutFile<<"\n"; } tmpOutFile.close(); } void LocalHost :: GenerateAwrReportFile(string strReportName) { string strPwd = ""; string strTmp = ""; string strFileName = m_pOutputHandle->getNodeDataDir(); ofstream tmpOutFile; #ifndef WIN32 if(m_bSysDBAFlag) { strTmp = "connect / as sysdba"; } else { strTmp = "connect "; strTmp = strTmp + m_strOracleLogin + " "; } strPwd = "/tmp"; #else strTmp = "connect "; strTmp = strTmp + m_strOracleLogin + " "; strPwd = strFileName; #endif m_strAwrSnapFileName = strPwd + "/awr_snap.sql"; tmpOutFile.open(m_strAwrSnapFileName.c_str(), ios::out|ios::binary); if (tmpOutFile.is_open()) { tmpOutFile << "whenever sqlerror exit 1;"; tmpOutFile << "\n"; tmpOutFile << strTmp; tmpOutFile << "\n"; tmpOutFile << "define report_type = 'html';"; tmpOutFile << "\n"; tmpOutFile << "define num_days = 1;"; tmpOutFile << "\n"; tmpOutFile << "define begin_snap=" << m_nBeginID; tmpOutFile << "\n"; tmpOutFile << "define end_snap=" << m_nEndID; tmpOutFile << "\n"; tmpOutFile << "define report_name = /tmp/" << strReportName; tmpOutFile << "\n"; tmpOutFile << "@?/rdbms/admin/awrrpt.sql;"; tmpOutFile << "\n"; tmpOutFile << " exit;"; tmpOutFile << "\n"; } tmpOutFile.close(); } bool LocalHost :: RemoveFileFromHost(string strFile) { bool status = true; if(isTempHostFile(strFile)) { status = std::remove(strFile.c_str()); if(status) { m_pCommonOutputHandle->writeDataToLogFile(STR_ERROR, m_strHostName, "Failed to delete Temp file: " + strFile); } } return status; } #ifdef WIN32 void LocalHost :: doWinSystemPerfmon (char *fname) { char command[1024], command1[1024]; LPTSTR NtSysCntrs[] = { "\\System\\% Total User Time", "\\System\\% Total Privileged Time", "\\System\\% Total Processor Time", "\\System\\Total Interrupts/sec", "\\System\\Context Switches/sec", "\\System\\File Read Operations/sec", "\\System\\File Write Operations/sec", "\\System\\File Control Operations/sec", "\\System\\File Read Bytes/sec", "\\System\\File Write Bytes/sec", "\\System\\File Control Bytes/sec", 0 }; LPTSTR Win2kSysCntrs[] = { "\\Processor(_Total)\\% User Time", "\\Processor(_Total)\\% Privileged Time", "\\Processor(_Total)\\% Processor Time", "\\Processor(_Total)\\Interrupts/sec", "\\System\\Context Switches/sec", "\\System\\File Read Operations/sec", "\\System\\File Write Operations/sec", "\\System\\File Control Operations/sec", "\\System\\File Read Bytes/sec", "\\System\\File Write Bytes/sec", "\\System\\File Control Bytes/sec", 0 }; // must update this count each time #define NT_PERF_SYSTEM_COUNTERS 11 int NT_PERF_COUNTERS = NT_PERF_SYSTEM_COUNTERS; int vals[NT_PERF_SYSTEM_COUNTERS]; char cntr_name[][1024] = { " %usr", " %sys", " %cpu", " intr/s", "csw/s", "FRops/s", "FWops/s", "FCops/s", "FR kb/s", "FW kb/s", "FC kb/s", 0 }; LPTSTR *counterList; HQUERY hNtPerfQuery;// NT PDH handle HCOUNTER *pNtCounterArray = NULL; PDH_STATUS pdhStatus; PDH_FMT_COUNTERVALUE fmtValue; int i,j; HQUERY hQuery; OSVERSIONINFO osinfo; int win2k; // first, initialize the pdh query (NtQueryInit) // open the PDH query object pdhStatus = PdhOpenQuery (0, 0, &hQuery); if (pdhStatus != ERROR_SUCCESS) { return; } pNtCounterArray = (HCOUNTER *) GlobalAlloc (GPTR, (sizeof (HCOUNTER) * NT_PERF_COUNTERS)); if (pNtCounterArray == NULL) { return; } // first, figure out which windows we are using :-( osinfo.dwOSVersionInfoSize = sizeof (osinfo); if (!GetVersionEx (&osinfo)) { fprintf (stderr,"Perfmon: Unable to get Windows version %s\n"); goto perfmon_fail; } if (osinfo.dwMajorVersion > 4) win2k=TRUE; else win2k=FALSE; if (win2k) counterList = Win2kSysCntrs; else counterList = NtSysCntrs; // end figure out which windows for (i = 0; i < NT_PERF_COUNTERS; i++) { pdhStatus = PdhAddCounter (hQuery, counterList[i], 0, &pNtCounterArray[i]); if (pdhStatus != ERROR_SUCCESS) { // // the counter didn't get added to the query, probably because // the path wasn't specified correctly or is not present /// printf ("PdhAddCounter returns %#x\n", pdhStatus); printf ("\n\"%s\" is not a valid counter path\n", counterList[i]); pNtCounterArray[i] = NULL; } } // // Get seed value of counters /// pdhStatus = PdhCollectQueryData (hQuery); hNtPerfQuery = hQuery; // end NtQueryInit // printout a key for (i = 0; i < NT_PERF_COUNTERS; i++){ sprintf(command,"echo %s \t== %s >> \"%s\"", cntr_name[i], Win2kSysCntrs[i],fname); execCommand(command); } // printout header sprintf(command1,""); for (i = 0; i < NT_PERF_COUNTERS; i++){ sprintf(command1,"%s\t%-7s",command1, cntr_name[i]); } sprintf(command,"echo %s >> \"%s\"",command1, fname); execCommand(command); // Now, loop through histo_count, sleeping histo_interval for (j=0;j> \"%s\"",command1, fname); execCommand(command); } perfmon_fail: PdhCloseQuery (hQuery); } void LocalHost :: doWinldiskPerfmon (char *fname) { char command[1024], command1[1024]; LPTSTR counterwildcard = "\\LogicalDisk(*)\\*"; LPTSTR countercounter = "\\LogicalDisk(*/*#*)\\Disk Transfers/sec"; // note, LogicalDisk has more counters, these are just the ones // we want to use LPTSTR counterName[] = { "% Disk Time", "% Disk Read Time", "% Disk Write Time", "Avg. Disk Queue Length", "Avg. Disk Read Queue Length", "Avg. Disk Write Queue Length", "Avg. Disk sec/Transfer", "Avg. Disk sec/Read", "Avg. Disk sec/Write", "Disk Transfers/sec", "Disk Reads/sec", "Disk Writes/sec", "Disk Bytes/sec", "Disk Read Bytes/sec", "Disk Write Bytes/sec", "Avg. Disk Bytes/Transfer", "Avg. Disk Bytes/Read", "Avg. Disk Bytes/Write" }; LPTSTR shortName[] = { "%DT", "%DRT", "%DWT", "aQL", "aRQL", "aWQL", "aS/x", "aS/Rd", "aS/Wr", "xfr/s", "r/s", "w/s", "KB/s", "rKB/s", "wKB/s", "aKB/x", "aKB/r", "aKB/w" }; #define NT_PERF_MAX_LDISK 500 #define MAX_LDISK_INSTANCES 100 #define NUM_LDISK_COUNTERS 18 // note, this changes with the above lists int counters=NUM_LDISK_COUNTERS; int NT_PERF_COUNTERS = NT_PERF_MAX_LDISK; //int vals[NT_PERF_MAX_LDISK]; int instances = 0; char instance_name[MAX_LDISK_INSTANCES][100]; double results[MAX_LDISK_INSTANCES][NT_PERF_MAX_LDISK]; LPTSTR ptr; LPTSTR expandedList[500]; char registeredList[500][100]; int registered = 0; HQUERY hNtPerfQuery; // NT PDH handle // HCOUNTER *pNtCounterArray = NULL; HCOUNTER pNtCounterArray[MAX_LDISK_INSTANCES][NUM_LDISK_COUNTERS]; PDH_STATUS pdhStatus; PDH_FMT_COUNTERVALUE fmtValue; int i,j,k, instance; HQUERY hQuery; DWORD bufSize=1000; LPTSTR counterPath=NULL; // first, initialize the pdh query (NtQueryInit) // open the PDH query object pdhStatus = PdhOpenQuery (0, 0, &hQuery); if (pdhStatus != ERROR_SUCCESS) { fprintf(stderr,"Perfmon: pdhopenquery failed\n"); goto ldisk_fail; } //pNtCounterArray = (HCOUNTER *) GlobalAlloc (GPTR, (sizeof (HCOUNTER) * NT_PERF_MAX_LDISK)); counterPath = (char *) GlobalAlloc (GPTR, bufSize); if (counterPath == NULL) { fprintf(stderr,"Perfmon: global alloc failed\n"); goto ldisk_fail; } // expand path name pdhStatus = PdhExpandCounterPath(counterwildcard, counterPath, &bufSize); if (pdhStatus==PDH_MORE_DATA) { bufSize++; GlobalFree(counterPath); counterPath = (LPTSTR ) GlobalAlloc (GPTR, bufSize); if (counterPath == NULL) { fprintf(stderr,"Perfmon: global alloc failed\n"); goto ldisk_fail; } pdhStatus = PdhExpandCounterPath(counterwildcard, counterPath, &bufSize); } // count how many were expanded to. NT_PERF_COUNTERS=0; ptr = (char *)counterPath; while (*ptr) { //fprintf(stderr,"PATH:%s\n",ptr); expandedList[NT_PERF_COUNTERS] = (LPTSTR)ptr; ptr+=strlen(ptr); ptr++; NT_PERF_COUNTERS++; if (NT_PERF_COUNTERS>500) { fprintf(stderr,"Perfmon: Too many logical disks\n"); goto ldisk_fail; } } // now, count the instances by picking one string and // seeing how many times it occurs. build the "instance // name" at the same time instances = 0; for (i = 0; i < NT_PERF_COUNTERS; i++) { int start, end; char tmp_str[100], *tmp_str_ptr; strcpy(tmp_str,expandedList[i]); if (strstr(tmp_str,counterName[0])) { // fish out instance_name. ugly stuff. look for name // inside of () delimiters start = end = -1; for (j=0;j<(int)strlen(expandedList[i]);j++) { if (expandedList[i][j] == '(') start = j+1; if (expandedList[i][j] == ')') end = j; } if (start == -1 || end == -1) { fprintf(stderr,"Perfmon: ldisk instance name not found: %s\n",expandedList[i]); goto ldisk_fail; } tmp_str[end] = '\0'; tmp_str_ptr = &(tmp_str[start]); strcpy(instance_name[instances],tmp_str_ptr); instances++; if (instances > MAX_LDISK_INSTANCES) { fprintf(stderr,"Perfmon: Too many logical disks\n"); goto ldisk_fail; } } } for (i = 0; i < NT_PERF_COUNTERS; i++) { // note, add counter only if it's one we want for (j=0;j> \"%s\"", shortName[i], counterName[i],fname); execCommand(command); } // Now, loop through histo_count, sleeping histo_interval for (j=0;j> \"%s\"",command1, fname); execCommand (command); // now sleep Sleep(m_nHistoInterval*1000); // capture nt stats pdhStatus = PdhCollectQueryData (hNtPerfQuery); if (pdhStatus == ERROR_SUCCESS) { for (i = 0; i < instances; i++) { for (k=0; k < counters; k++) { // get the current value for this counter pdhStatus = PdhGetFormattedCounterValue (pNtCounterArray[i][k], PDH_FMT_DOUBLE, 0, &fmtValue); if (pdhStatus == ERROR_SUCCESS) { results[i][k] = fmtValue.doubleValue; } else { //fprintf (stderr, "%s\n", expandedList[i]); //printf ("Win error: Unable to format pdh: %s\n"); results[i][k] = 0; } } } } else { //fprintf(stderr,"CollectQuery failed\n"); } // fix up some of the variable formats (e.g. convert to mb/s). for (i = 0; i < instances; i++) { for (k = 0; k < counters; k++) { if (strcmp(shortName[k],"KB/s") == 0) results[i][k] /= 1024.; if (strcmp(shortName[k],"rKB/s") == 0) results[i][k] /= 1024.; if (strcmp(shortName[k],"wKB/s") == 0) results[i][k] /= 1024.; if (strcmp(shortName[k],"aKB/x") == 0) results[i][k] /= 1024.; if (strcmp(shortName[k],"aKB/r") == 0) results[i][k] /= 1024.; if (strcmp(shortName[k],"aKB/w") == 0) results[i][k] /= 1024.; } } // output stats to fname for (i = 0; i < instances; i++) { sprintf(command1,"%8s %ds",instance_name[i],j*m_nHistoInterval); for (k=0;k> \"%s\"",command1, fname); execCommand (command); } } ldisk_fail: PdhCloseQuery (hQuery); } #endif void LocalHost :: ProcessParallelData( boost::barrier *parThreadBar, presetMetaData *metaData, string threadId ) { int status; string tmpCommand = (*metaData).getCommand(); string type = (*metaData).getType(); string pFileID = threadId; string tmpFileName = "tmpResult_"; tmpFileName = tmpFileName + threadId; char commandFlag = 'N'; char command[1024]; string data; time_t cmdStartTime; time_t cmdEndTime; time(&cmdStartTime); try { #ifdef WIN32 size_t found = tmpCommand.find("Emulex_HBA_qdepth.reg"); if (found != string::npos) { commandFlag = 'a'; } found = tmpCommand.find("TCP_Params.reg"); if (found!=string::npos) { commandFlag = 'b'; } found = tmpCommand.find("msinfo_1.out"); if (found!=string::npos) { commandFlag = 'c'; } found = tmpCommand.find("msinfo_2.out"); if (found!=string::npos) { commandFlag = 'd'; } found = tmpCommand.find("system_perfmon"); if (found!=string::npos) { commandFlag = 'e'; } found = tmpCommand.find("ldisk_perfmon"); if (found!=string::npos) { commandFlag = 'f'; } //No special command has been found yet that means we will process the command default way switch(commandFlag) { case 'a': { time(&cmdStartTime); //registry values that represent Windows FCP HBA queue depth settings sprintf(command, "regedit /E \"%s\" \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\lpxnds\\Parameters\\Device\\NumberOfRequests\"", tmpFileName.c_str()); execCommand(command); time(&cmdEndTime); break; } case 'b': { time(&cmdStartTime); sprintf(command, "regedit /E \"%s\" \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\"", tmpFileName.c_str()); execCommand(command); time(&cmdEndTime); break; } case 'c': { time(&cmdStartTime); sprintf(command, "cmd /C \"start \"msinfo\" /wait \"%s\" /report \"%s\" /categories +SystemSummary-all\"", MSINFO32,tmpFileName.c_str()); execCommand(command); time(&cmdEndTime); break; } case 'd': { time(&cmdStartTime); sprintf(command, "cmd /C \"start \"msinfo\" /wait \"%s\" /report \"%s\" /categories +ComponentsStorage-all\"", MSINFO32,tmpFileName.c_str()); execCommand(command); time(&cmdEndTime); break; } case 'e': { time(&cmdStartTime); doWinSystemPerfmon(const_cast(tmpFileName.c_str())); time(&cmdEndTime); break; } case 'f': { time(&cmdStartTime); doWinldiskPerfmon( const_cast(tmpFileName.c_str())); time(&cmdEndTime); break; } default: { time(&cmdStartTime); tmpCommand = tmpCommand + " > "; tmpCommand = tmpCommand + tmpFileName; tmpCommand = tmpCommand + " 2>NUL"; execCommand(tmpCommand); time(&cmdEndTime); break; } } boost::mutex::scoped_lock lock(host_move_mutex); string tmpConvFile; string tmpConv; bool fileStatus; switch(commandFlag) { case 'a': { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " + "Emulex_HBA_qdepth.reg" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); //the regedit tool dumps the information into unicode charset so when the data is copied from this temp file to main host data file //It looks ugly and the Latx/Linux doesnt read that data. So we need to convert it to ansi first and then copy. tmpConvFile = tmpFileName + "_a"; tmpConv = "type "; tmpConv = tmpConv + tmpFileName + " > " + tmpConvFile; //Before trying to convert, check the existence of the result file. Sometimes if the regedit doesnt find the value for the required parameters, It doesnt //create the temp result file so conversion would fail fileStatus = isTempHostFile(tmpFileName); if(fileStatus) std::system(tmpConv.c_str()); writeDataToFile( tmpConvFile ); data="\n--- EXE-TIME of : " ; data = data + "Emulex_HBA_qdepth.reg" + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); //writeDataToFile( tmpFileName ); m_pOutputHandle->writeDataToHostFile(data); break; } case 'b': { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= "+"TCP_Params.reg" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); //the regedit tool dumps the information into unicode charset so when the data is copied from this temp file to main host data file //It looks ugly and the Latx/Linux doesnt read that data. So we need to convert it to ansi first and then copy. tmpConvFile = tmpFileName + "_a"; tmpConv = "type "; tmpConv = tmpConv + tmpFileName + " > " + tmpConvFile; fileStatus = isTempHostFile(tmpFileName); if(fileStatus) std::system(tmpConv.c_str()); writeDataToFile( tmpConvFile ); //writeDataToFile( tmpFileName ); data="\n--- EXE-TIME of : "; data = data + "TCP_Params.reg" + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); //writeDataToFile( tmpFileName ); m_pOutputHandle->writeDataToHostFile(data); break; } case 'c': { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= "+"msinfo_1.out" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); //the regedit tool dumps the information into unicode charset so when the data is copied from this temp file to main host data file //It looks ugly and the Latx/Linux doesnt read that data. So we need to convert it to ansi first and then copy. tmpConvFile = tmpFileName + "_a"; tmpConv = "type "; tmpConv = tmpConv + tmpFileName + " > " + tmpConvFile; fileStatus = isTempHostFile(tmpFileName); if(fileStatus) std::system(tmpConv.c_str()); writeDataToFile( tmpConvFile ); //writeDataToFile( tmpFileName ); time(&cmdEndTime); data="\n--- EXE-TIME of : "; data = data + "msinfo_1.out" + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); break; } case 'd': { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " + "msinfo_2.out" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); //the regedit tool dumps the information into unicode charset so when the data is copied from this temp file to main host data file //It looks ugly and the Latx/Linux doesnt read that data. So we need to convert it to ansi first and then copy. tmpConvFile = tmpFileName + "_a"; tmpConv = "type "; tmpConv = tmpConv + tmpFileName + " > " + tmpConvFile; fileStatus = isTempHostFile(tmpFileName); if(fileStatus) std::system(tmpConv.c_str()); writeDataToFile( tmpConvFile ); //writeDataToFile( tmpFileName ); data="\n--- EXE-TIME of : "; data = data + "msinfo_2.out" + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); break; } case 'e': { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= "+ "system_perfmon.out" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); writeDataToFile( tmpFileName.c_str() ); data="\n--- EXE-TIME of : "; data = data + "system_perfmon.out" + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); break; } case 'f': { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " + "ldisk_perfmon.out" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); writeDataToFile( tmpFileName.c_str() ); data="\n--- EXE-TIME of : "; data = data + "ldisk_perfmon.out" + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); break; } default: { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " ; if((*metaData).getShortname().compare("")!=0) data.append((*metaData).getShortname()); else data.append((*metaData).getCommand()); data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); writeDataToFile( tmpFileName.c_str() ); data="\n--- EXE-TIME of : "; data = data + (*metaData).getCommand() + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); break; } } if(isTempHostFile(tmpConvFile)) { std::remove(tmpConvFile.c_str()); } #else size_t found=tmpCommand.find("ifconfig -a"); if (found!=string::npos) { time(&cmdStartTime); //extract interface data for Linux string fileName1 = "tmpResult1"; string fileName2 = "tmpResult2"; ofstream outputFile1; ofstream outputFile2; ifstream inputFile; string command = "/sbin/ifconfig -a |grep eth |awk '{print $1}' > tmpIPConResult"; std::system(command.c_str()); inputFile.open("tmpIPConResult", ios::in); if ( inputFile.is_open() ) { string dataLine; while (! inputFile.eof() ) { getline (inputFile, dataLine); if(dataLine.size() > 1) { string ethCommand = "/sbin/ethtool"; string miitoolCom = "/sbin/mii-tool"; ethCommand = ethCommand + " " + dataLine; ethCommand = ethCommand + " " + " >>tmpResult1"; miitoolCom = miitoolCom + " " + dataLine; miitoolCom = miitoolCom + " " + " >>tmpResult2"; std::system(ethCommand.c_str()); std::system(miitoolCom.c_str()); } } inputFile.close(); } time(&cmdEndTime); } else { time(&cmdStartTime); tmpCommand = tmpCommand + " > "; tmpCommand = tmpCommand + tmpFileName; tmpCommand = tmpCommand + " 2>/dev/null"; execCommand(tmpCommand); time(&cmdEndTime); } //Now lets write it into the host data file boost::mutex::scoped_lock lock(host_move_mutex); string data; found=tmpCommand.find("ifconfig -a"); if (found!=string::npos) { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " + "ethtool" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); writeDataToFile("tmpResult1" ); data="\n--- EXE-TIME of : "; data = data + " ethtool " + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " + "mii-tool" ; data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); writeDataToFile( "tmpResult2" ); data="\n--- EXE-TIME of : "; data = data + " mii-tool " + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); status = remove("tmpResult1"); if(status != 0) { m_pCommonOutputHandle->writeDataToLogFile("ERROR", m_strHostName, "Failed to delete the file tmpResult1 inside processParallelCommand "); } status = remove("tmpResult2"); if(status != 0) { m_pCommonOutputHandle->writeDataToLogFile("ERROR", m_strHostName, "Failed to delete the file tmpResult2 inside processParallelCommand " ); } status = remove("tmpIPConResult"); if(status != 0) { m_pCommonOutputHandle->writeDataToLogFile("ERROR", m_strHostName, "Failed to delete the file tmpIPConResult inside processParallelCommand " ); } } else { data = "=-=-=-=-=-= " + type + " " + m_strHostName + " "; data = data + "POSTSTATS" + " =-=-=-=-=-= " ; if((*metaData).getShortname().compare("")!=0) data.append((*metaData).getShortname()); else data.append((*metaData).getCommand()); data.append("\nPERFSTAT_EPOCH: " + boost::lexical_cast(cmdStartTime)); data.append(perfstat::convert_EPOCH_to_gmtime(cmdStartTime)); data.append("\n\n"); m_pOutputHandle->writeDataToHostFile(data); writeDataToFile( tmpFileName.c_str() ); data="\n--- EXE-TIME of : "; data = data + (*metaData).getCommand() + " : "; data.append(boost::lexical_cast(cmdEndTime - cmdStartTime) + " seconds"); m_pOutputHandle->writeDataToHostFile(data); } #endif if(isTempHostFile(tmpFileName)) { std::remove(tmpFileName.c_str()); } } catch(std::exception& e) { string tmp = "Exception : Host : processParData :"; tmp.append(e.what()); m_pCommonOutputHandle->writeDataToLogFile(STR_ERROR, m_strHostName, tmp); } } string LocalHost :: generateDateString() { time_t rawtime; struct tm * timeinfo; char buffer [80]; string timeStr; time ( &rawtime ); timeinfo = gmtime ( &rawtime ); strftime (buffer,80,"%a %b %d %H:%M:%S GMT %Y",timeinfo); timeStr = buffer; return timeStr; } void LocalHost::writeDataToFile(string fileName) { ifstream inputFile; inputFile.open(fileName.c_str(), ios::out); if (inputFile.is_open()) { string dataLine; while (! inputFile.eof() ) { getline(inputFile, dataLine); m_pOutputHandle->writeDataToHostFile(dataLine); } inputFile.close(); } }