/** * @ingroup shell * * Shell command (netstat). * @param nargs number of arguments in args array * @param args array of arguments * @return OK for success, SYSERR for syntax error */ shellcmd xsh_netstat(int nargs, char *args[]) { int i; /* Output help, if '--help' argument was supplied */ if (nargs == 2 && strcmp(args[1], "--help") == 0) { printf("Usage: %s\n\n", args[0]); printf("Description:\n"); printf("\tDisplays Network Information\n"); printf("Options:\n"); printf("\t--help\tdisplay this help and exit\n"); return OK; } /* Check for correct number of arguments */ if (nargs > 1) { fprintf(stderr, "%s: too many arguments\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return SYSERR; } if (nargs < 1) { fprintf(stderr, "%s: too few arguments\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return SYSERR; } #if NNETIF for (i = 0; i < NNETIF; i++) { netStat(&netiftab[i]); } #else i = 0; netStat(NULL); #endif return OK; }
QString sysInfo::getMinimalStats(){ netStat(); cpuUsage(); memPerc(); bytesTransmitted = getSizeUnit(bytesTransmitted); bytesReceived = getSizeUnit(bytesReceived); //Sende the CPU usage %, the RAM usage %, the amount of transmitted data in the applicable unit, the amount of received data in the applicable unit QString stats = cpuPerc + "%" + "#" + memoryLoad + "%" + "#"+ bytesTransmitted + "#" + bytesReceived; return stats; }
QString sysInfo::getDetailedStats(){ cpuUsage(); memPerc(); netStat(); cpuStats(); getDiskDetails(); osVersion(); listProcesses(); QString stats = ""; bytesTransmitted = getSizeUnit(bytesTransmitted); bytesReceived = getSizeUnit(bytesReceived); //Add the netstat info to the stats string stats = stats + "Data Transmitted," + bytesTransmitted + "#Data Received," + bytesReceived + "#Packets Transmitted," + packetsTransmitted + "#Packets Received," + packetsReceived + "#Errors Transmitting," + transmitErrors + "#Errors Receiving," + receiveErrors; //Add the cpuStats to the stats string stats = stats + "#Number of Processors," + _cpuCount; //Add the OS Version stats = stats + "#Operating System," + osVers; //Add the various logical drive details for(int i = 0; i < filesystems.length(); i++){ QString cap = capacitys.at(i); cap.chop(cap.length() - cap.indexOf(".")); cap = getSizeUnit(cap); QString used = useds.at(i); used = getSizeUnit(used); stats = stats + "#Drive Label," + filesystems.at(i) + ",Total Capacity," + cap+ ",Used Space," + used; } //Add RAM and CPU physMem.chop(physMem.length()- physMem.indexOf(".")); physMem = getSizeUnit(physMem); freePhysMem.chop(freePhysMem.length() - freePhysMem.indexOf(".")); freePhysMem = getSizeUnit(freePhysMem); stats = stats + "#Total RAM,"+physMem+"#Used RAM,"+freePhysMem+"#% RAM in use,"+memoryLoad+"#% CPU in use,"+cpuPerc; //Add the process/task related info stats = stats + "#Amount of Processes active," + procCount; for(int j = 0; j < procIDs.length(); j++){ stats = stats + "#" + procIDs.at(j) + "," + procNames.at(j); } return stats; }