Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need some input for my gui app #69

Open
akshaykmr opened this issue Mar 31, 2016 · 4 comments
Open

Need some input for my gui app #69

akshaykmr opened this issue Mar 31, 2016 · 4 comments

Comments

@akshaykmr
Copy link
Contributor

Edit: here is the repository

Hey there I am currently making a gui app using nethogs at the backend. The idea is to run a light server and use a webview for the desktop app. This way output can also be viewed from the network on a different machine. here are some screenshots
screen shot 2016-03-31 at 7 06 35 pm
The per process graph can also be seen by selecting the process from the list
screen shot 2016-03-31 at 7 07 38 pm

The app is still in very early stages and not released yet but some input would be appreciated.
I am using the nethogs trace mode as data source but the data is not clean as I would like (long process path/ IP adresses etc.) I would appreciate if trace mode listed pid, user device as well, more preferably in a JSON format such that any future changes/additions do not break dependent apps(currently I am parsing output line by line column-wise).

@mbfoss
Copy link
Contributor

mbfoss commented Mar 31, 2016

There is an experiential library feature in nethogs
You need to build the latest master with make then run sudo make install_dev to copy the library and header files to your system.
Then you include libnethogs.h and link to libnethogs and you would be able to receive detailed updates in a C struct.
There is no broad documentation on this feature yet so have a look inside libnethogs.h for how to use the functions.

Basic use:

#include "libnethogs.h"

void onNethogsUpdate(int action, NethogsMonitorRecord const* update)
{
  //updates here
}

int main()
{
  nethogsmonitor_loop(&onNethogsUpdate);
}

Here is an experimental GUI I made using the lib: https://github.com/mbfoss/gnethogs

@raboof
Copy link
Owner

raboof commented Mar 31, 2016

@akshaykmr that looks pretty amazing!

I agree nethogs' output is currently not very nicely machine-consumable. Indeed a JSON stdout stream feature might be a nice addition, though it might not be suitable for all use cases.

@akshaykmr
Copy link
Contributor Author

made some progess.

@d3473r
Copy link

d3473r commented Mar 14, 2019

I want to use libnethogs.h from a python script but I'm not sure how to use the nethogsmonitor_loop correctly, maybe you can help me.

I have defined the following fields following the libnethogs.h

class NethogsMonitorRecord(ctypes.Structure):
    _fields_ = [
        ('record_id', ctypes.c_int), 
        ('name', ctypes.c_char_p), 
        ('pid', ctypes.c_int), 
        ('uid', ctypes.c_uint), 
        ('device_name', ctypes.c_char_p),
        ('sent_bytes', ctypes.c_ulonglong),
        ('recv_bytes', ctypes.c_ulonglong),
        ('sent_kbs', ctypes.c_float),
        ('recv_kbs', ctypes.c_float)]

If I print everything in this class I'm getting strange values:

asciicast

EDIT:

It is working fine not, i had to add argtypes and use a pointer

asciicast

Working code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants