Ana Sayfa » *nix » sysdig: Sistem Seviyesi Analiz ve Sorun Giderme Aracı

sysdig: Sistem Seviyesi Analiz ve Sorun Giderme Aracı


BerbatKötüİdare EderGüzelHarika (Henüz Puan Verilmedi. Oy kullanarak siz de katkı yapabilirsiniz.)
Loading...

Genelde IT altyapılarında meydana gelen problemleri gidermek ve bir daha tekrarlanmayacak şekilde proaktif bir yaklaşımla probleme neden ana faktörleri ortadan kaldırmak  için yapılması gereken ilk şey problemi doğru analiz etmektir. Zira doğru olarak analiz edilen bir problem için üretilen çözümler doğru orantılı olarak kalıcı ve ilgili problemin ya da varyasyonlarının tekrar yaşanmasını engelleyici nitelikte olacaklardır. Hal böyle olunca yani iş, problem analizine geldiğinde bu konudaki başarıyı belirleyici en önemli faktör ise yaklaşımlarınız ve kullandığınız araçlardır.

Bu noktada doğru yaklaşım herzaman için problemin nedenlerini tam olarak anlamaktır. Yani eğer ortada neden kaynaklandığını bilemediğiniz ancak geçici çözümler üretebildiğiniz – ki gerçek hayatta en çok problemli servisi / sunucuyu restart etmeye tekabül eden – bir problem varsa önceliği problemi geçici olarak çözmek yerine nedenlerini anlamaya çalışmak üzere konunun derinlerine inmek ve altyapıyı enine boyuna analiz etmeye vermek en doğru yaklaşım olacaktır.  Problem çözmede en belirleyici ikinci faktör ise, analiz sırasında kullandığınız araçların derine inmek ve inceleme konusundaki ihtiyaçlarınıza cevap verecek şekilde gelişmiş olması gerekliliğidir. İşte bu yazının konusunu oluşturan de tarif ettiğimiz bu ihtiyaçlara harika bir şekilde yanıt veren çok güzel bir uygulamadır.

Nedir ?

Temel olarak hemen tüm majör Linux dağıtımında çalışan ve doğrudan linux kernel’ine dahil olarak tüm sistem çağrılarını ve OS ile ilgili diğer olayları en alt düzeyde yakalayıp analiz edilmesine olanak sağlayan , bu işi yapan strace gibi klasik araçlardan farklı olarak bir çok güzel özellik barındırmaktadır.

Öncelikli olarak kernel seviyesinde processing, network, storage ve memory alt sistemlerinde cereyan eden olayların anlaşılır şekilde ve bütünleşik olarak görüntülenmesine olanak sağlar. Bu, incelemekte olduğunuz platform üzerinde çalışmakta olan uygulamaların sistem seviyesinde ne gibi işlemler yaptığını görüntüleyebilmenize olanak sağlamaktadır ki , sysdig üzerinden elde edilen veri, problem çözmede kullanılabilecek ve genelde log dosyalarından ya da uygulama bağımlı debugging araçlarından elde edilemeyecek türden alt seviye kıymetli bilgi içerir.

Ayrıca, önünüzden geçip giden binlerce satır – ve nispeten anlamsız- system çağrısı ve olayı içerisinde kaybolmamanız için çok güzel de bir filtreleme sistemi barındırmaktadır. Bu şekilde spesifik olarak ilgilendiğiniz alt sistemlerle ilgili çağrıların ve olayların belirttiğiniz kriterlere göre görüntülenmesini sağlayabilirsiniz.

Bir diğer sysdig özelliği ise görüntülenmesini istediğiniz syscall ve event’lerin daha sonra analiz edilmek üzere bir dosyaya yazılmasını sağlayabilmenizdir. Sysdig’in en güzel yanlarından birisi olan bu özellik, rastgele bir zaman diliminde oluşan problemlerin analizi için oldukça kullanışlı bir yöntemdir. Zira bu şekilde ilgili problemin tekrar cereyan etmesini beklemek ve o anda sizin de sistemin başında olmanız zorunluluğu gibi verimsiz bir durumu ortadan kaldırıp uzak sistemlerden topladığınız bu trace dosyaları üzerinde geçmişe yönelik olarak analiz yapabilmenizi olanaklı kılmaktadır. Üstelik trace file denilen bu sysdig dosyalarını MacOS X ya da Windows gibi farklı platformlar üzerinde de analiz edebildiğinizden dolayı illa server side çalışmanıza gerek kalmamaktadır.

Sysdig’in bir diğer güzel özelliği ise “chisels” adını verdikleri ve kurulumla birlikte bir çoğunun öntanımlı olarak geldiği analiz scriptleridir. Bu scriptler toplanan verinin anlamlandırılması için kullanılan Lua dilinde yazılmış scriptlerdir ve sisteminiz hakkında detaylı bilgi edinmek için kullanabileceğiniz ve analiz ihtiyaçlarınıza göre kendi scriptlerinizi geliştirebileceğiniz bir mekanizmadır. Birazdan örnekler bölümünde detaylı olarak değineceğim üzere bu scriptler üzerinden örneğin sadece belirli bir sürece ya da uygulamanın ürettiği trafiği detaylı olarak inceleyebilir, en çok network trafiği üreten portları / süreçleri / bağlantıları görüntüleyebilir, en çok disk I/O’suna neden olan dosyaları / süreçleri bulabilir ya da en çok hata üreten uygulamaları tespit edebilirsiniz. Bu anlamda sysdig, strace, lsof, tcpdump gibi uygulamaların yaptığı işi tek bir çatı altında toplayan gelişmiş bir uygulamadır.

Sysdig Kurulumu

Yazının başında da bahsettiğim gibi sysdig bir listesini biraz sonra vereceğim hemen tüm majör Linux dağıtımı üzerinde çalışıyor, YUM ve APT kullanan dağıtımlar için birer paket deposu da bulunuyor. Bu nedenle desteklediği Debian, Ubuntu, CentOS, RHEL, Fedora, Amazon Linux, Oracle Linux, Linux Mint gibi dağıtımlara doğrudan paket yöneticisi üzerinden kurulabiliyor ve bu işlemi gerçekleştirmek için aşağıdaki komutu vermeniz yeterli oluyor:

# curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | sudo bash

Not: RHEL ya da CentOS 7.0 kullanıyorsanız ve kurulum sırasında EPEL reposu ile ilgili bir hata ile karşılaşırsanız öncesinde EPEL reposunu sisteminize kurmanız gerekebilir. Bu işlem için de aşağıdaki komutu kullanabilirsiniz:

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm

Ayrıca sysdig’i daha önceden toplanmış veriyi analiz etmek üzere MacOS x ve Windows’a kurabiliyorsunuz. Bu kurulumlar için http://www.sysdig.org/install/ adresindeki ilgili bölümlere de bakabilirsiniz.

Sysdig Kullanımı

Girizgah bölümünde uzun uzun değindiğim üzere sysdig ile uygulamalar ve sistem servislerinin arkaplanda gerçekleştirdiği işleri en alt seviyede görüntülemek mümkün.

Temel Kullanım

sysdig’in en primitive kullanımı komut satırından doğrudan sysdig komutunu çalıştırmaktır. Bu komutu verdiğiniz zaman aşağıda bir örneğini görebileceğiniz şekilde strace benzeri bir çıktı alırsınız.

[[email protected] ~]# sysdig
1 15:55:06.872525472 0 systemd-journal (652) < epoll_wait res=1
2 15:55:06.872533123 0 systemd-journal (652) < read res=48 data=6,1648,140659115,-;sysdig_probe: opening ring 0.
3 15:55:06.872544006 0 systemd-journal (652) < uname
4 15:55:06.872576730 0 systemd-journal (652) < ftruncate
5 15:55:06.872579032 0 systemd-journal (652) < epoll_wait res=1
6 15:55:06.872580454 0 systemd-journal (652) < read res=50 data=6,1649,140659118,-;sysdig_probe: starting capture.
7 15:55:06.872583006 0 systemd-journal (652) < uname
8 15:55:06.872593367 0 systemd-journal (652) < ftruncate
9 15:55:06.872599290 0 in:imjournal (820) < poll res=1 fds=6:i1
10 15:55:06.872608436 0 in:imjournal (820) < read res=32 data=................system.journal..
11 15:55:06.872614091 0 in:imjournal (820) < read res=-11(EAGAIN) data=
12 15:55:06.872657022 0 in:imjournal (820) < futex res=1
13 15:55:06.872675397 0 rs:main (821) < futex res=0
14 15:55:06.872677216 0 rs:main (821) < futex res=0

Bu şekilde o an çalışan sistem çağrıları ve event’ler ekrandan akacaktır. Bu çıktıda her bir olay bir satır olacak şekilde görüntülenmektedir ve her bir satırda aşağıda sıralaması verilen bilgiler ekrana basılacaktır:

%evt.num %evt.time %evt.cpu %proc.name (%thread.tid) %evt.dir %evt.type %evt.args

İlgili bilgilerin açıklaması da şu şekildedir:

evt.num:  Event numarası
evt.time: Event tarihi
evt.cpu: Event’in hangi kaç numaralı CPU core üzerinde çalıştığı
proc.name: Süreç ismi.
thread.tid: Thread ID ( tek thread’li süreçler için PID)
evt.dir: Event yönü, giriş eventleri için > ve çıkışlar için <
evt.type: Event tipi, örm: ‘open’, ‘read’, ‘write’
evt.args: event’in aldığı argüman.

Filtreleme Parametreleri

Sysdig’i yukarıda verilen şekilde her sistem olayını görüntüleyecek şekilde kullanmak aynı anda binlerce olayın ekrandan akıp gitmesine ve bu bilgi akışı içerisinde kaybolup gitmenize neden olacaktır; işte strace’den alşık olduğumuz bu verimsiz durumu ortadan kaldırmak için sysdig’in çok gelişmiş bir filtreleme sistemi bulunmaktadır. Kendi değimleri ile samanlıkta iğne aramak için geliştirilmiş bu sistem sayesinde binlerce sistem çağrısını en ince ayrıntısına kadar filtreleyerek spesifik aramalar yapabiliyorsunuz.

Örnek olarak cat komutuna ait aktiviteyi görüntülemek için sysdig’i aşağıdaki şekilde kullanabilirsiniz:

# sysdig proc.name=cat

Bu komutu verip, cat komutu ile bir dosya açarsanız (benim örneğimde cat /etc/passwd) bir kısmı aşağıda gösterilene benzer bir çıktı alırsınız:

30797 18:25:56.750454554 0 cat (2961) < execve res=0 exe=cat args=/etc/passwd. tid=2961(cat) pid=2961(cat) ptid=2945(-bash) cwd=/root fdlimit=1024 pgft_maj=0 pgft_min=64 vm_size=340 vm_rss=4 vm_swap=0 30798 18:25:56.750479532 0 cat (2961) > brk addr=0
30799 18:25:56.750480703 0 cat (2961) < brk res=1826000 vm_size=340 vm_rss=4 vm_swap=0 30800 18:25:56.750502276 0 cat (2961) > mmap addr=0 length=4096 prot=3(PROT_READ|PROT_WRITE) flags=10(MAP_PRIVATE|MAP_ANONYMOUS) fd=4294967295 offset=0
30856 18:25:56.751293911 0 cat (2961) > fstat fd=1(/dev/pts/0)
30857 18:25:56.751297054 0 cat (2961) < fstat res=0 30858 18:25:56.751298025 0 cat (2961) > open
30859 18:25:56.751304773 0 cat (2961) < open fd=3(/etc/passwd) name=/etc/passwd flags=1(O_RDONLY) mode=0
30860 18:25:56.751305461 0 cat (2961) > fstat fd=3(/etc/passwd)
30861 18:25:56.751306152 0 cat (2961) < fstat res=0 30862 18:25:56.751308739 0 cat (2961) > 
30863 18:25:56.751314620 0 cat (2961) < 
30864 18:25:56.751324264 0 cat (2961) > read fd=3(/etc/passwd) size=65536
30865 18:25:56.751330032 0 cat (2961) < read res=993 data=root:x:0:0:root:/root:/bin/bash.bin:x:1:1:bin:/bin:/sbin/nologin.daemon:x:2:2:da 30870 18:25:56.751358095 0 cat (2961) > close fd=3(/etc/passwd)
30871 18:25:56.751359019 0 cat (2961) < close res=0 30872 18:25:56.751376935 0 cat (2961) > close fd=1(/dev/pts/0)
30873 18:25:56.751377727 0 cat (2961) < close res=0 30874 18:25:56.751380328 0 cat (2961) > close fd=2(/dev/pts/0)
30875 18:25:56.751380682 0 cat (2961) < close res=0 30876 18:25:56.751384030 0 cat (2961) > exit_group
30877 18:25:56.751420307 0 cat (2961) > procexit

Görebileceğiniz gibi bu çıktıda, cat komutunun arka planda gerçekleştirdiği tüm işlemler ekrana yansıtılmaktadır.

Sysdig’in fitreleme yapısı standart karşılaştırma operatörlerini ( =, !=, <, <=, >, >= ) ve boolean operatörleri (“and”, “or” ve “not”) desteklediği için filtrelemeyi genişletmek çok kolaydır.

Örnek olarak cat ve vi komutunun aktivitelerini görüntülemek için komutu şu şekilde kullanmak mümkündür:

# sysdig proc.name=cat or proc.name=vi

ya da cat haricindeki tüm diğer süreçlerin açtığı dosyalar görüntülemek için örnek şu şekildedir:

# sysdig proc.name!=cat and evt.type=open

Filtreleme işlemlerinde kullanılan ve class.field denilen aramaların hangi kriterlere göre yapılabileceğini belirleyebileceğiniz yüm seçenekler aşağıdaki komut üzerinden listelenebilmektedir:

# sysdig -l

Bu komutun çıktısı aşağıdaki gibi olacaktır:

----------------------
Field Class: fd

fd.num              the unique number identifying the file descriptor.
fd.type             type of FD. Can be 'file', 'directory', ipv4', 'ipv6', 'uni
                    x', 'pipe', 'event', 'signalfd', 'eventpoll', 'inotify' or
                    'signalfd'.
fd.typechar         type of FD as a single character. Can be 'f' for file, 4 fo
                    r IPv4 socket, 6 for IPv6 socket, 'u' for unix socket, p fo
                    r pipe, 'e' for eventfd, 's' for signalfd, 'l' for eventpol
                    l, 'i' for inotify, 'o' for uknown.
fd.name             FD full name. If the fd is a file, this field contains the
                    full path. If the FD is a socket, this field contain the co
                    nnection tuple.
fd.directory        If the fd is a file, the directory that contains it.
fd.filename         If the fd is a file, the filename without the path.
fd.ip               matches the ip address (client or server) of the fd.
fd.cip              client IP address.
fd.sip              server IP address.
fd.port             (FILTER ONLY) matches the port (client or server) of the fd
                    .
fd.cport            for TCP/UDP FDs, the client port.
fd.sport            for TCP/UDP FDs, server port.
fd.l4proto          the IP protocol of a socket. Can be 'tcp', 'udp', 'icmp' or
                     'raw'.
fd.sockfamily       the socket family for socket events. Can be 'ip' or 'unix'.
fd.is_server        'true' if the process owning this FD is the server endpoint
                     in the connection.

----------------------
Field Class: process

proc.pid            the id of the process generating the event.
proc.exe            the full name (including the path) of the executable genera
                    ting the event.
proc.name           the name (excluding the path) of the executable generating
                    the event.
proc.args           the arguments passed on the command line when starting the
                    process generating the event.
proc.cmdline        full process command line, i.e name + arguments.
proc.cwd            the current working directory of the event.
proc.nchilds        the number of child threads of that the process generating
                    the event currently has.
proc.ppid           the pid of the parent of the process generating the event.
proc.pname          the name (excluding the path) of the parent of the process
                    generating the event.
proc.apid           the pid of one of the process ancestors. E.g. proc.apid[1]
                    returns the parent pid, proc.apid[2] returns the grandparen
                    t pid, and so on. proc.apid[0] is the pid of the current pr
                    ocess. proc.apid without arguments can be used in filters o
                    nly and matches any of the process ancestors, e.g. proc.api
                    d=1234.
proc.aname          the name (excluding the path) of one of the process ancesto
                    rs. E.g. proc.aname[1] returns the parent name, proc.aname[
                    2] returns the grandparent name, and so on. proc.aname[0] i
                    s the name of the current process. proc.aname without argum
                    ents can be used in filters only and matches any of the pro
                    cess ancestors, e.g. proc.aname=bash.
proc.loginshellid   the pid of the oldest shell among the ancestors of the curr
                    ent process, if there is one. This field can be used to sep
                    arate different user sessions, and is useful in conjunction
                     with chisels like spy_user.
proc.duration       number of nanoseconds since the process started.
proc.fdopencount    number of open FDs for the process
proc.fdlimit        maximum number of FDs the process can open.
proc.fdusage        the ratio between open FDs and maximum available FDs for th
                    e process.
proc.vmsize         total virtual memory for the process (as kb).
proc.vmrss          resident non-swapped memory for the process (as kb).
proc.vmswap         swapped memory for the process (as kb).
thread.pfmajor      number of major page faults since thread start.
thread.pfminor      number of minor page faults since thread start.
thread.tid          the id of the thread generating the event.
thread.ismain       'true' if the thread generating the event is the main one i
                    n the process.
thread.exectime     CPU time spent by the last scheduled thread, in nanoseconds
                    . Exported by switch events only.
thread.totexectime  Total CPU time, in nanoseconds since the beginning of the c
                    apture, for the current thread. Exported by switch events o
                    nly.

----------------------
Field Class: evt

evt.num             event number.
evt.time            event timestamp as a time string that includes the nanoseco
                    nd part.
evt.time.s          event timestamp as a time string with no nanoseconds.
evt.datetime        event timestamp as a time string that includes the date.
evt.rawtime         absolute event timestamp, i.e. nanoseconds from epoch.
evt.rawtime.s       integer part of the event timestamp (e.g. seconds since epo
                    ch).
evt.rawtime.ns      fractional part of the absolute event timestamp.
evt.reltime         number of nanoseconds from the beginning of the capture.
evt.reltime.s       number of seconds from the beginning of the capture.
evt.reltime.ns      fractional part (in ns) of the time from the beginning of t
                    he capture.
evt.latency         delta between an exit event and the correspondent enter eve
                    nt.
evt.latency.s       integer part of the event latency delta.
evt.latency.ns      fractional part of the event latency delta.
evt.dir             event direction can be either '>' for enter events or '<' f
                    or exit events.
evt.type            For system call events, this is the name of the system call
                     (e.g. 'open').
evt.cpu             number of the CPU where this event happened.
evt.args            all the event arguments, aggregated into a single string.
evt.arg             (FILTER ONLY) one of the event arguments specified by name
                    or by number. Some events (e.g. return codes or FDs) will b
                    e converted into a text representation when possible. E.g.
                    'resarg.fd' or 'resarg[0]'.
evt.rawarg          (FILTER ONLY) one of the event arguments specified by name.
                     E.g. 'arg.fd'.
evt.info            for most events, this field returns the same value as evt.a
                    rgs. However, for some events (like writes to /dev/log) it
                    provides higher level information coming from decoding the
                    arguments.
evt.buffer          the binary data buffer for events that have one, like read(
                    ), recvfrom(), etc. Use this field in filters with 'contain
                    s' to search into I/O data buffers.
evt.res             event return value, as an error code string (e.g. 'ENOENT')
                    .
evt.rawres          event return value, as a number (e.g. -2). Useful for range
                     comparisons.
evt.failed          'true' for events that returned an error status.
evt.is_io           'true' for events that read or write to FDs, like read(), s
                    end, recvfrom(), etc.
evt.is_io_read      'true' for events that read from FDs, like read(), recv(),
                    recvfrom(), etc.
evt.is_io_write     'true' for events that write to FDs, like write(), send(),
                    etc.
evt.io_dir          'r' for events that read from FDs, like read(); 'w' for eve
                    nts that write to FDs, like write().
evt.is_wait         'true' for events that make the thread wait, e.g. sleep(),
                    select(), poll().
evt.is_syslog       'true' for events that are writes to /dev/log.
evt.count           This filter field always returns 1 and can be used to count
                     events from inside chisels.
evt.around          (FILTER ONLY) Accepts the event if it's around the specifie
                    d time interval. The syntax is evt.around[T]=D, where T is
                    the value returned by %evt.rawtime for the event and D is a
                     delta in milliseconds. For example, evt.around[14049969347
                    93590564]=1000 will return the events with timestamp with o
                    ne second before the timestamp and one second after it, for
                     a total of two seconds of capture.

----------------------
Field Class: user

user.uid            user ID.
user.name           user name.
user.homedir        home directory of the user.
user.shell          user's shell.

----------------------
Field Class: group

group.gid           group ID.
group.name          group name.

----------------------
Field Class: syslog

syslog.facility.str facility as a string.
syslog.facility     facility as a number (0-23).
syslog.severity.str severity as a string. Can have one of these values: emerg,
                    alert, crit, err, warn, notice, info, debug
syslog.severity     severity as a number (0-7).
syslog.message      message sent to syslog.

Yukarıdaki listede görülebileceği üzere tüm subsystem’ler için filtreleme seçenekleri bulunmakta. Filtreleme seçeneklerini kendi ihtiyaçlarınıza göre düzenleyebileceğiniz gibi bazı kullanışlı örnekler ise şu şekildedir:

/var/log dizini altında işlem yapan süreçleri görüntülemek için:

# sysdig fd.directory=/var/log/

sshd süreci haricinde dosyalar üzerinde aktivite gerçekleştiren süreçler ve yaptıkları işlemler:

# sysdig proc.name!=sshd and fd.type=file

Apache ve MySQL süreçlerine ait aktivite:

# sysdig proc.name=apache2 and proc.name=mysqld

Komutların aldığı parametreler üzerinden filtreleme yapmak için proc.args class.filed’i kullanılmaktadır. Örnek olarak parametre olarak www.google.com alan bir uygulamanın hareketlerini izlemek için (örn: ping www.google.com)

# sysdig proc.args=www.google.com

Spesifik bir ip adresi tarafından yapılan bağlantılar sonucu oluşan ve sshd süreci ile alakalı olmayan aktiviteyi incelemek için:

# sysdig fd.ip=192.168.1.2 and proc.name!=sshd

Apache dışındaki süreçler tarafından karşılanan gelen network bağlantılarını incelemek için:

# sysdig evt.type=accept and proc.name!=apache

Root kullanıcısına ait tüm aktivitenin izlenmesi:

# sysdig user.name=root

root grubuna dahil tüm kullanıcıların ürettiği aktiviteyi görüntülemek için:

# sysdig group.name=root

Ana süreci zsh olan ve event tipi execve olan sistem çağrılarını görüntülemek için: (execve uygulama çalıştırma sırasında kullanılan sistem çağrısıdır)

# sysdig evt.type=execve and evt.arg.ptid=zsh

Hata üreten tüm sistem çağrılarını görüntülemek için:

# sysdig “evt.rawarg.fd < 0"

Kullanılabilecek tüm event'leri görüntülemek için aşağıdaki şekilde -L paramertesini kullanabilirsiniz:

# sysdig -L
> syscall(SYSCALLID ID, UINT16 nativeID)
< syscall(SYSCALLID ID) > open()
< open(FD fd, FSPATH name, FLAGS32 flags, UINT32 mode) > close(FD fd)
< close(ERRNO res) > read(FD fd, UINT32 size)
< read(ERRNO res, BYTEBUF data) > write(FD fd, UINT32 size)
< write(ERRNO res, BYTEBUF data) > brk(UINT32 size)
< brk(UINT64 res) > execve()
< execve(ERRNO res, CHARBUF exe, BYTEBUF args, PID tid, PID pid, PID ptid, CHARBUF cwd, UINT64 fdlimit) > clone()
< clone(PID res, CHARBUF exe, BYTEBUF args, PID tid, PID pid, PID ptid, CHARBUF cwd, INT64 fdlimit, FLAGS32 flags, UINT32 uid, UINT32 gid) > procexit()
> socket(FLAGS32 domain, UINT32 type, UINT32 proto)
< socket(FD fd) > bind(FD fd)
< bind(ERRNO res, SOCKADDR addr) > connect(FD fd)
< connect(ERRNO res, SOCKTUPLE tuple) > listen(FD fd, UINT32 backlog)
< listen(ERRNO res) > accept()
< accept(FD fd, SOCKTUPLE tuple, UINT8 queuepct) > send(FD fd, UINT32 size)
< send(ERRNO res, BYTEBUF data) > sendto(FD fd, UINT32 size, SOCKTUPLE tuple)
< sendto(ERRNO res, BYTEBUF data) > recv(FD fd, UINT32 size)
< recv(ERRNO res, BYTEBUF data) > recvfrom(FD fd, UINT32 size)
< recvfrom(ERRNO res, BYTEBUF data, SOCKTUPLE tuple) > shutdown(FD fd, FLAGS8 how)
< shutdown(ERRNO res) > getsockname()
< getsockname() > getpeername()
< getpeername() > socketpair(FLAGS32 domain, UINT32 type, UINT32 proto)
< socketpair(ERRNO res, FD fd1, FD fd2, UINT64 source, UINT64 peer) > setsockopt()
< setsockopt() > getsockopt()
< getsockopt() > sendmsg(FD fd, UINT32 size, SOCKTUPLE tuple)
< sendmsg(ERRNO res, BYTEBUF data) > sendmmsg()
< sendmmsg() > recvmsg(FD fd)
< recvmsg(ERRNO res, UINT32 size, BYTEBUF data, SOCKTUPLE tuple) > recvmmsg()
< recvmmsg() > accept(INT32 flags)
< accept(FD fd, SOCKTUPLE tuple, UINT8 queuepct) > creat()
< creat(FD fd, FSPATH name, UINT32 mode) > pipe()
< pipe(ERRNO res, FD fd1, FD fd2, UINT64 ino) > eventfd(UINT64 initval, FLAGS32 flags)
< eventfd(FD res) > futex(UINT64 addr, FLAGS16 op, UINT64 val)
< futex(ERRNO res) > stat()
< stat(ERRNO res, FSPATH path) > lstat()
< lstat(ERRNO res, FSPATH path) > fstat(FD fd)
< fstat(ERRNO res) > stat64()
< stat64(ERRNO res, FSPATH path) > lstat64()
< lstat64(ERRNO res, FSPATH path) > fstat64(FD fd)
< fstat64(ERRNO res) > epoll_wait(ERRNO maxevents)
< epoll_wait(ERRNO res) > poll(FDLIST fds, INT64 timeout)
< poll(ERRNO res, FDLIST fds) > select()
< select(ERRNO res) > select()
< select(ERRNO res) > lseek(FD fd, UINT64 offset, FLAGS8 whence)
< lseek(ERRNO res) > llseek(FD fd, UINT64 offset, FLAGS8 whence)
< llseek(ERRNO res) > ioctl(FD fd, UINT64 request)
< ioctl(ERRNO res) > getcwd()
< getcwd(ERRNO res, CHARBUF path) > chdir()
< chdir(ERRNO res, CHARBUF path) > fchdir(FD fd)
< fchdir(ERRNO res) > mkdir(FSPATH path, UINT32 mode)
< mkdir(ERRNO res) > rmdir(FSPATH path)
< rmdir(ERRNO res) > openat(FD dirfd, CHARBUF name, FLAGS32 flags, UINT32 mode)
< openat(FD fd) > link(FSPATH oldpath, FSPATH newpath)
< link(ERRNO res) > linkat(FD olddir, CHARBUF oldpath, FD newdir, CHARBUF newpath)
< linkat(ERRNO res) > unlink(FSPATH path)
< unlink(ERRNO res) > unlinkat(FD dirfd, CHARBUF name)
< unlinkat(ERRNO res) > pread(FD fd, UINT32 size, UINT64 pos)
< pread(ERRNO res, BYTEBUF data) > pwrite(FD fd, UINT32 size, UINT64 pos)
< pwrite(ERRNO res, BYTEBUF data) > readv(FD fd)
< readv(ERRNO res, UINT32 size, BYTEBUF data) > writev(FD fd, UINT32 size)
< writev(ERRNO res, BYTEBUF data) > preadv(FD fd, UINT64 pos)
< preadv(ERRNO res, UINT32 size, BYTEBUF data) > pwritev(FD fd, UINT32 size, UINT64 pos)
< pwritev(ERRNO res, BYTEBUF data) > dup(FD fd)
< dup(FD res) > signalfd(FD fd, UINT32 mask, FLAGS8 flags)
< signalfd(FD res) > kill(PID pid, SIGTYPE sig)
< kill(ERRNO res) > tkill(PID tid, SIGTYPE sig)
< tkill(ERRNO res) > tgkill(PID pid, PID tid, SIGTYPE sig)
< tgkill(ERRNO res) > nanosleep(RELTIME interval)
< nanosleep(ERRNO res) > timerfd_create(UINT8 clockid, FLAGS8 flags)
< timerfd_create(FD res) > inotify_init(FLAGS8 flags)
< inotify_init(FD res) > getrlimit(FLAGS8 resource)
< getrlimit(ERRNO res, INT64 cur, INT64 max) > setrlimit(FLAGS8 resource)
< setrlimit(ERRNO res, INT64 cur, INT64 max) > prlimit(PID pid, FLAGS8 resource)
< prlimit(ERRNO res, INT64 newcur, INT64 newmax, INT64 oldcur, INT64 oldmax) > switch(PID next)
> drop(UINT32 ratio)
< drop(UINT32 ratio) > fcntl(FD fd, FLAGS8 cmd)
< fcntl(FD res) > switch(PID next, UINT64 pgft_maj, UINT64 pgft_min, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap)
> execve()
< execve(ERRNO res, CHARBUF exe, BYTEBUF args, PID tid, PID pid, PID ptid, CHARBUF cwd, UINT64 fdlimit, UINT64 pgft_maj, UINT64 pgft_min, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap) > clone()
< clone(PID res, CHARBUF exe, BYTEBUF args, PID tid, PID pid, PID ptid, CHARBUF cwd, INT64 fdlimit, UINT64 pgft_maj, UINT64 pgft_min, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap, FLAGS32 flags, UINT32 uid, UINT32 gid) > brk(UINT64 addr)
< brk(UINT64 res, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap) > mmap(UINT64 addr, UINT64 length, FLAGS32 prot, FLAGS32 flags, FD fd, UINT64 offset)
< mmap(UINT64 res, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap) > mmap2(UINT64 addr, UINT64 length, FLAGS32 prot, FLAGS32 flags, FD fd, UINT64 pgoffset)
< mmap2(UINT64 res, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap) > munmap(UINT64 addr, UINT64 length)
< munmap(ERRNO res, UINT32 vm_size, UINT32 vm_rss, UINT32 vm_swap) > splice(FD fd_in, FD fd_out, UINT64 size, FLAGS32 flags)
< splice(ERRNO res) > ptrace(FLAGS16 request, PID pid)
< ptrace(ERRNO res, DYNAMIC addr, DYNAMIC data)

Çıktı Formatlarını Düzenleme

Filtreleme sonuçlarının daha düzgün görünmesini sağlamak üzere çıktıları customize edebilmekde mümkün. Örnek olarak event tipi chdir (change dir) olan sistem çağrılarını, komutu (cd) çalıştıran kullanıcı ve ilgli dizini görüntülemek üzere formatlı bir şekilde ekrana basmak için şu komut kullanılabilir:

# sysdig -p"user:%user.name dir:%evt.arg.path" evt.type=chdir  

zsh üzerinden gerçekleştirilen tüm komutları, kullanıcı, komut ve komut agrümanını içerecek şekilde ekrana basmak için:

# sysdig -p"%user.name) %proc.name %proc.args" evt.type=execve and evt.arg.ptid=bash

Trace Dosyaları

Trace dosyası, sysdig'in ürettiği sonuçların daha sonra analiz etmek üzere (tcpdump'da vs olduğu gibi) yazıldığı dosyaları ifade etmektedir. Örnek olarak tüm sysdig çıktısını sysdig_ciktisi.scap dosyasına yazılması için komut şu şekilde olacktır:

# sysdig –w sysdig_ciktisi.scap

ya da sadece 100 adet event'in ilgili dosyaya yazılmasını sağlamak için komut şu şekilde olmalıdır:

# sysdig –n 100 –w sysdig_ciktisi.scap

Toplanan sysdig çıktılarının yazıldığı bu dosyayı okuyarak analiz etmek için ise aşağıdaki komut kullanılabilir:

# sysdig –r sysdig_ciktisi.scap

Chisels

Yazının başında bahsettiğim chisels konusu, sysdig üzerinden elde edilen verinin anlamlandırılması üzere kullanılan scriptlere verilen addır ve öntanımlı olarak bir sürü chisel bulunmaktadır. Öncelikle bu chisel'lerin bir listesini -cl parametresi kullanılabilir:

# sysdig -cl

Category: CPU Usage
-------------------
topprocs_cpu        Top processes by CPU usage

Category: Errors
----------------
topfiles_errors     top files by number of errors
topprocs_errors     top processes by number of errors

Category: I/O
-------------
echo_fds            Print the data read and written by processes.
fdbytes_by          I/O bytes, aggregated by an arbitrary filter field
fdcount_by          FD count, aggregated by an arbitrary filter field
iobytes             Sum of I/O bytes on any type of FD
iobytes_file        Sum of file I/O bytes
stderr              Print stderr of processes
stdin               Print stdin of processes
stdout              Print stdout of processes
topfiles_bytes      Top files by R+W bytes
topfiles_time       Top files by time
topprocs_file       Top processes by R+W disk bytes

Category: Logs
--------------
spy_logs            Echo any write made by any process to a log file. Optionall
                    y, export the events around each log message to file.
spy_syslog          Print every message written to syslog. Optionally, export t
                    he events around each syslog message to file.

Category: Misc
--------------
around              Export to file the events around the where the given filter
                     matches.

Category: Net
-------------
iobytes_net         Show total network I/O bytes
spy_ip              Show the data exchanged with the given IP address
spy_port            Show the data exchanged using the given IP port number
topconns            top network connections by total bytes
topports_server     Top TCP/UDP server ports by R+W bytes
topprocs_net        Top processes by network I/O

Category: Performance
---------------------
bottlenecks         Slowest system calls
fileslower          Trace slow file I/O
netlower            Trace slow network I/0
proc_exec_time      Show process execution time
scallslower         Trace slow syscalls
topscalls           Top system calls by number of calls
topscalls_time      Top system calls by time

Category: Security
------------------
list_login_shells   List the login shell IDs
spy_users           Display interactive user activity

Category: System State
----------------------
lsof                List the open file descriptors.

Use the -i flag to get detailed information about a specific chisel

chisel'ler hakkında daha detaylu bilgi almak üzere -i parametresi kullanılabilir. Örnek olarak spy_users isimli chisel'in ne iş yaptığına bakmak için aşağıdaki komut kullanılabilir:

# sysdig -i spy_users

Category: Security
------------------
spy_users           Display interactive user activity

lists every command that users launch interactively (e.g. f
rom bash) and every directory users visit
Args:
[int] max_depth - the maximum depth to show in the hierarch
                    y of processes

Şimdi chisel'ler üzerinden bir kaç örnek yapalım.

En cok CPU kullanımı olan süreçler:

# sysdig -c topprocs_cpu

1 ms'den uzun süren I/O aktivitesi:

# sysdig -c fileslower 1

1 ms'den uzun süren network aktivitesi:

# sysdig -c netlower 1

syscall bazında en çok error üreten süreçler:

# sysdig -c topprocs_errors

Süreçlere ait standart çıktıları ekrana basmak için (filtrelenebilir):

# sysdig -c stdout

Yazma + Okuma anlamında en çok disk I/O'nun yapıldığı dosyalar:

# sysdig -c topfiles_bytes

En çık disk I/O üreten (Read + Write) süreçler:

# sysdig -c topprocs_file

Disk I/O anlamında en çok uzun süre aktivite üreten süreçler:

# sysdig -c topprocs_time

Byte cinsinden toplam I/O miktarı:

# sysdig -c iobytes_file 

Hangi süreçlerin hangi log dosyalarına ne yazdığının ekrana basılması:

# sysdig -c spy_logs

Syslog'a yazılan her mesajın görüntülenmesi:

# sysdig -c spy_syslog

Spesific bir ip'nin ürettiği trafiğin görüntülenmesi (dikkat edeceğiniz üzere chisel'leri filtreleme seçenekleri kullanabiliyoruz):

# sysdig -c spy_ip 1.1.1.1 proc.name!=sshd

Spesifik bir port üzerinde gerçekleşen trafiğin görüntülenmesi:

# sysdig -c spy_port 80

Byte cinsinden en çok trafik üreten bağlantıların listenmesi:

# sysdig -c topconns

En çok trafik üreten portların listelenmesi:

# sysdig -c topports_server

En çok trafik üreten süreçlerin görüntülenmesi:

# sysdig -c topprocs_net

Sistemdeki kullanıcılara ait aktivitenin interaktif olarak izlenmesi:

# sysdig -c spy_users

Örnekleri çoğaltmak mümkün ve daha fazlası için http://www.sysdig.org/wiki/sysdig-examples/ adresine bakabilir ya da kendi ihtiyaçlarınıza göre kendi örneklerini türetebilirsiniz. Sysdig, arka planda cereyan eden olayları göz önüne getiriyor oluşunsan ve bu işi oldukça düzgün yapıyor oluşundan dolayı, gerçekten övgüyü hakkaden bir uygulama. Sizin de işinize yarayacağınu ümit ediyorum.

Kategoriler: *nix,Genel,ipucu |

Bu yazılar da ilginizi çekebilir:


- Locust – Açık Kaynak Kod Load Test Uygulaması
- WAFP – Web Application Finger Printer
- Arping – Link Layer (L2) Pinging
- Yasat ile Sistem Denetimi
- CPU Limit ile Süreçlerin İşlemci Kullanımını Sınırlamak

Yorumlar


  1. emrah | (Eylül 29th, 2014 8:10 pm)

    Çok faydalı bir araçmış, default kurduğum paketler arasına bunu da ekledim. Debian Jessie için bu paket depoda var, doğrudan depodan kurulabiliyor.

    [Cevapla]

  2. Ergin ALTINTAŞ | (Ocak 14th, 2015 6:21 am)

    Makale için teşekkürler. Bana çok faydalı oldu. Bir de birden çok sistemde çalışan sysdig çıktılarını merkezi olarak ayarlayıp, takip edebilecek bir arayüz olsa süper olacakmış.

    Makale de düzgün görünmeyen bir kısım var. “Hata üreten tüm sistem çağrılarını görüntülemek için” örneğinde sanırım küçüktür işaretinden kaynaklanan bir markup sorunu olmuş. İfade sayfada

    sysdig ” evt.rawarg.res

    şeklinde gözüküyor. Belki aynı markup sorunu burada da olur diye aynı ifadeyi küçüktür işaretini okunuşu ile belirterek de yazıyorum: “evt.rawarg.fd KÜÇÜKTÜR 0”. Eğer yan taraftaki ifadede KÜÇÜKTÜR işaretini görüyorsanız aynı markup sorunu yorumlarda olmuyor demektir. İfadenin tam hali: “evt.rawarg.fd < 0"

    [Cevapla]

    Cagri Ersen tarafından yanıtlandı.

    İlginize teşekkür ederim, gerekli düzelmeyi yaptım.

    [Cevapla]

Trackbacks

Yorumda bulunun.