Package: jk-appmonitoring
jk_appmonitoringIntroductionThis Python module contains components for analyzing the use of system resources by processes. It covers two use cases: a) monitoring other processes and b) monitoring one's own process.Information about this module can be found here:github.orgpypi.python.orgWhy this module?Linux provides a lot of information about processes in the system via the/proc/*file system and other means. However to use this data easily a reasonable API is required. This module provides such an API. Some effort has been made to select appropriate information files and provide information about processes in a way that keeps the I/O and CPU load low.Limitations of this moduleThis module is only usable on Linux.This module can only provide information that is made available through regular system interfaces such as the/proc/*file system.This moduleonlyprovides information. This module is not ment to manage processes, it is only ment for retrieval of information about processes via a simple and well documented API. It therefore is ment not as a standalone application but as a building block within another application.jk_appmonitoring and jk_sysinfoThere is another module you should know about. It's namedjk_sysinfo. Whilejk_sysinfoprovides various information about the local machine and the operating system this module namedjk_appmonitoringprovides information about a single or a set of processes.jk_sysinfois ment for system analysis and monitoring,jk_appmonitoringis ment for individual process analysis and monitoring.How to use this moduleImport this modulePlease include this module into your application using the following code:importjk_appmonitoringCore APIThe core API provides the following functions:dict get_proc_pid_io(int pid, *): Retrieve information about I/O of a process by parsing/proc/<pid>/io.dict get_proc_pid_stat(int pid, *): Retrieve information about process memory usage and priority assignments by parsing/proc/<pid>/stat.dict get_proc_pid_status(int pid, *): Retrieve information about process memory usage and priority assignments by parsing/proc/<pid>/status.dict get_proc_pid_io(int pid, *)For a given process ID this function reads and parses/proc/<pid>/io. From this pseudo-file it will retrieve data and provide it using the following key-value-pairs:KeyData TypeDescriptionio_read_bytesintCount the number of bytes which this process causeed to be fetched from the storage layer. This is accurate for block-backed filesystems.io_write_bytesintCount the number of bytes which this process caused to be sent to the storage layer. (This should accurate for block-backed filesystems as well but there is no explicite information about that in the documentation for/proc/<pid>/io.)dict get_proc_pid_stat(int pid, *)`For a given process ID this function reads and parses/proc/<pid>/stat. From this pseudo-file it will retrieve data and provide it using the following key-value-pairs:KeyData TypeDescriptioncstimefloatAmount of time that this process's waited-for children have been scheduled inkernel mode, measured in absolute number of secondscutimefloatAmount of time that this process's waited-for children have been scheduled inuser mode, measured in absolute number of secondsio_delayacct_blkiofloatAggregated block I/O delays, measured in absolute number of secondsniceintThe nice value (see setpriority(2)), a value in the range 19 (low priority) to -20 (high priority).num_threadsintNumber of threads in this process.pgrpintThe process group ID of the process.pidintThe process ID.ppidintThe PID of the parent of this process.mem_rssintResident Set Size: number of bytes the process has in real memory. This is just the bytes which count toward text, data, or stack space. This does not include bytes which have not been demand-loaded in, or which are swapped out.stimefloatAmount of time that this process has been scheduled inkernel mode, measured in absolute number of secondstty_nrintThe controlling terminal of the process. (The minor device number is contained in the combination of bits 31 to 20 and 7 to 0; the major device number is in bits 15 to 8.)utimefloatAmount of time that this process has been scheduled inuser mode, measured in absolute number of secondsdict get_proc_pid_status(int pid, *)`(TODO)Retrieving information about processes(TODO)Managing Disk Space InformationIf you want to display information about disk space the following set of classes can be used for that purpose:RFileSystemCollection: This manages all file systems available for analysisRFileSystem: This represents a file system available for analysisRDirectory: This represents a directory that is used by some part of an applicationSo the procedure is as follows:First instantiate aRFileSystemCollection,register all file systemsRFileSystemCollectionshould check later, thenregister instances ofRDirectorythat represent a set of directories used by your application.Then invokeupdate()to retrieve more or less recent data (by respecting configurations forRDirectoryto cache values for some time), andthen retrieve the data from theRFileSystemobjects via propertyfilesystemsfrom theRFileSystemCollection.Here is a code example:fsCol=RFileSystemCollection()# register a single file system - or main file systemfsCol.registerFileSystem(RFileSystem("Main","/",bWeakDirRefs=False))# now register various directories for demonstration purposes onlyfsCol.registerDirectory(RDirectory("myuser-home","/home/myuser",60))fsCol.registerDirectory(RDirectory("fileproc","/srv/fileproc",30))# now update the file system usage datafsCol.update()TheRFileSystemobjects will now have generated disk usage information. You can access disk usage objects (represented byRDiskSpacePartobjects) stored at these file system objects.Here is a simple example how to do that:forfsinfsCol.filesystems:print(fs.name)forpartinfs.usages:print("\t"+part.name+"\t"+str(part.diskSpaceUsedPercent))Contact InformationThis work is Open Source. This enables you to use this work for free.Please have in mind this also enables you to contribute. We, the subspecies of software developers, can create great things. But the more collaborate, the more fantastic these things can become. Therefore Feel free to contact the author(s) listed below, either for giving feedback, providing comments, hints, indicate possible collaborations, ideas, improvements. Or maybe for "only" reporting some bugs:Jürgen Knauth:pubsrc@binary-overflow.deLicenseThis software is provided under the following license:Apache Software License 2.0