Git Product home page Git Product logo

pasta's Introduction

pasta

Build Status

process fork/exec/exit monitoring tool(go implementation of forkstat)

pasta is a programm that logs process fork, exec, exit, crashdump, comm activity It is very useful for monitoring process behaviour and to track down processes

pasta uses the CN_PROC of Linux Netlink Connector to gather process activity pasta may miss events if the system is overly busy Netlink Connector requires root privilege. pasta same as forkstat(http://kernel.ubuntu.com/~cking/forkstat/)

Install

compiler

$ cd $GOPATH
$ go get github.com/jjh2kiss/pasta
$ cd ./src/github/jjh2kiss/pasta
$ go build
$ go install
$ sudo pasta

binary

$ cd $GOPATH
$ git clone [email protected]:jjh2kiss/pasta.git
$ cd ./src/github/jjh2kiss/pasta/bin
$ sudo cp ./pasta /usr/local/bin
$ sudo pasta

pasta command line options:

  • -d, --dirstrip strip off the directory path from the process name
  • -D value, --duration value specify run duration in seconds (default: 0)
  • -e value, --event value select which events to monitor(default: all)
  • -s, --shortname show short process name information
  • -S, --statistics show event statistics at end of the run
  • -q, --quiet run quietly and enable -S option
  • --help, -h show help
  • --version, -v print the version

Examples:

monitoring all process event

sudo ./pasta -S
Time                Event  PID   Info Duration Process
2016/10/27 14:13:24 fork  1366 parent          sudo ./pasta -S
2016/10/27 14:13:24 fork  1373 child           ./pasta -S
2016/10/27 14:13:24 fork  1366 parent          sudo ./pasta -S
2016/10/27 14:13:24 fork  1374 child           ./pasta -S
2016/10/27 14:13:34 fork  2030 parent          /usr/lib/unity-settings-daemon/unity-settings-daemon
2016/10/27 14:13:34 fork  1375 child           /usr/lib/unity-settings-daemon/unity-settings-daemon
2016/10/27 14:13:34 fork  1375 parent          /usr/lib/unity-settings-daemon/unity-settings-daemon
2016/10/27 14:13:34 fork  1376 child           /usr/lib/unity-settings-daemon/unity-settings-daemon
2016/10/27 14:13:34 exit  1375      0    0.005 /usr/lib/unity-settings-daemon/unity-settings-daemon
2016/10/27 14:13:34 exec  1376                 /usr/bin/perl -w /usr/bin/x-terminal-emulator
2016/10/27 14:13:34 exec  1376                 /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 fork  1813 parent          /sbin/upstart --user
2016/10/27 14:13:34 fork  1377 child           /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 comm  1377                 /usr/bin/python3 /usr/bin/gnome-terminal -> gmain
2016/10/27 14:13:34 fork  1376 parent          /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 fork  1378 child           /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 exec  1378                 /usr/bin/gnome-terminal.real
2016/10/27 14:13:34 fork  1376 parent          /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 fork  1379 child           /usr/bin/gnome-terminal.real
2016/10/27 14:13:34 comm  1379                 /usr/bin/gnome-terminal.real -> dconf worker
2016/10/27 14:13:34 fork  1376 parent          /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 fork  1380 child           /usr/bin/gnome-terminal.real
2016/10/27 14:13:34 fork  1376 parent          /usr/bin/python3 /usr/bin/gnome-terminal
2016/10/27 14:13:34 fork  1381 child           /usr/bin/gnome-terminal.real
2016/10/27 14:13:34 comm  1381                 /usr/bin/gnome-terminal.real -> gdbus
2016/10/27 14:13:34 comm  1380                 /usr/bin/gnome-terminal.real -> gmain
2016/10/27 14:13:34 fork 24790 parent          /usr/lib/gnome-terminal/gnome-terminal-server
2016/10/27 14:13:34 fork  1382 child           /usr/lib/gnome-terminal/gnome-terminal-server
2016/10/27 14:13:34 exec  1382                 bash
2016/10/27 14:13:34 fork  1382 parent          bash
2016/10/27 14:13:34 fork  1383 child           bash

monitoring coredump event

sudo ./pasta -e coredump -e exec -e exit | grep segfault
2016/10/27 14:49:41 exec  2707                 ./segfault
2016/10/27 14:49:43 core  2707                 ./segfault
2016/10/27 14:49:43 exit  2707    139    2.089 ./segfault

pasta's People

Contributors

jjh2kiss avatar

Stargazers

Yukiko Babikian avatar Guo Jiaming avatar  avatar spoock avatar  avatar chennqqi avatar  avatar kyungkoo avatar  avatar Eunwoo Cho avatar MinJae Kwon (Miti) avatar Kim SeungSu avatar jikoon kong avatar

Watchers

James Cloos avatar  avatar

pasta's Issues

Binary 파일 추가

compiler가 없는 환경을 위해 컴파일된 바이너리를 추가한다.

travis ci 연동

travis ci 사용시 아래 패키지 설치하는 구문 추가

  • github.com/urfave/cli

Have you considered / are you interested in one or two additional features?

Hey there, cool project. I'm a big fan of the "original" forkstat but I love to see C stuff ported to golang

I'm curious if you have any interest in adding one or two specific features, or if you strongly prefer to remain as a 1:1 / clone of the C version and avoid "creeping featurism", as they say - or put another way, "random features some weird dude will use, but nobody else" ;)

I have two very specific things in mind that I've already implemented in the C version of forkstat out of necessity - though the implementation was very hastily thrown together and not something I consider done (hard-coded lists of patterns rather than CLI options, only actually basic substring matching rather than using a regex implementation, etc. The matching also needs a bit of review to ensure the filter has as fast of a patch as possible, to remediate the race conditions that I encounter regularly in the vanilla forkstat (more on that below, see the item labeled number 2)

Anyway, the two features are closely related: custom granular noise filtering, implemented roughly as:

  • A configuration file or CLI option to blacklist or whitelist the comm value. This could be regex or something a little simpler, but either way, string pattern matching and fast path out of processing the event if it doesn't match
  • A configuration file or CLI option to blacklist or whitelist based upon being a descendant of a certain PPID (immediate parent, or grandparent, great grandparent, etc.) For example, you could specify that you're only interested in children of pid 12345, which may be some process that spawns a lot of threads or forks that you have some interest in

I do a lot of fiddling with embedded systems/proprietary software and having those features helps a LOT to observe system-wide behavior; but because when monitoring execs, EVERY exec system call is processed, you end up with two problems:

  1. A lot of noise, especially for the devices that do silly things like popen("cat /proc/meminfo") every second rather than just reading /proc/meminfo - yes, this is real example that I've seen multiple times, along with variations (df -h, du, uptime - just dumb decisions...) ... anyway
  2. The occasional race condition, where you don't get the info on the process before it exits; since the event only includes the PID, you probably recall from writing this that you have to then read info from /proc/<pid>/*. Especially with IoT devices that may have a single core and a lot of very quickly completing commands, you end up not being able to even retrieve the comm info before it's gone, because the process exited

For dealing with noise, you can of course use grep -P <regex> or grep -Pv <regex> to filter what you don't need, but it doesn't help with item 2 (losing the race to pull the metadata from /proc/<pid>/, because the relatively expensive path of retrieving the /proc/<pid>/ info will of course still happen, even for the processes that will ultimately be filtered out by grep

Ultimately I may end up finishing and cleaning up the C fork I have, but had to ask what you thought

I'll be perfectly honest, I'm not very strong with golang- my C is much, much better. I've only contributed a few bug-fixes and features to a half dozen golang projects, and it was slow for me, and I missed a lot of golang idioms/patterns. I would do my best to contribute PRs if you were interested, but between my weakness with golang and the time I have available, I don't want to overpromise

Thanks again!

EDIT: Probably should ask if you're still alive / if the repo is still maintained - just realized it's 7 years old (!!!)

pstat main 작성

Netlink Connector 타입증 CN_PROC를 이용해 프로세스 이벤트 정보를 수집하고 출력하는 기능을 개발한다.

누적 통계 구조 정의

forkstat 은 아래와 같이 처리함

type struct Stats { name string count [EVENT_MAX]uint64 total uint64 }

다른 형태도 고려해보고 진행 .

System ClockTick(HZ)가져오는 함수 작성

Linux 시스템에서 사용하는 ClockTick를 가져오는 함수를 작성한다.
/proc/*에서 제공하는 대부분의 정보가 ClockTick단위이므로 ClockTick로 나눠야 초단위 값을 가져올 수 있다.

Process 구조체 정의

아래 정보는 필수임
type Process struct { pid int cmdline string kernel_thread bool start_time Time }

필수 정보를 포함하는 구조체 정의 하시오~~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.