wiki:KrakenLinuxApi

Kraken Linux API

Kraken Linux API wraps linux native API.

Author

API Reference

Last login (wtmp)

Wtmp class reads /var/log/wtmp log file.

WtmpEntry has following properties:

public class WtmpEntry {
	public Type getType();
	public int getPid();
	public String getUser();
	public String getHost();
	public int getSession();
	public Date getDate();
}

Type is categorized like this:

RunLevel, BootTime, NewTime, OldTime, InitProcess, LoginProcess, UserProcess, DeadProcess, Accounting

Usage example:

for (WtmpEntry entry : Wtmp.getEntries()) {
	System.out.println(entry.toString());
}

result:
type=BootTime, date=2009-08-23 16:16:46, pid=0, user=reboot, host=**deleted**
type=RunLevel, date=2009-08-23 16:16:46, pid=51, user=runlevel, host=**deleted**
type=LoginProcess, date=2009-08-23 16:18:29, pid=1708, user=LOGIN, host=
type=UserProcess, date=2009-08-23 16:18:34, pid=1707, user=root, host=
type=UserProcess, date=2009-08-23 16:25:31, pid=1854, user=root, host=110.45.142.190
type=UserProcess, date=2009-08-23 16:32:18, pid=1916, user=root, host=110.45.142.190
type=LoginProcess, date=2009-08-23 16:44:35, pid=6322, user=LOGIN, host=
type=UserProcess, date=2009-08-23 16:56:55, pid=6322, user=root, host=
type=UserProcess, date=2009-08-23 16:57:13, pid=6451, user=8con, host=110.45.142.190
type=DeadProcess, date=2009-08-23 16:57:22, pid=6451, user=, host=
..omitted..

Process

Process.getProcesses() reads /proc/[pid] directories.

Usage example:

for (Process p : Process.getProcesses()) {
	System.out.println(p);
}

result:
[1] init, mem=1964KB
[2] kthreadd, mem=0KB
[3] migration/0, mem=0KB
[4] ksoftirqd/0, mem=0KB
[5] watchdog/0, mem=0KB
[6] migration/1, mem=0KB
[7] ksoftirqd/1, mem=0KB
[8] watchdog/1, mem=0KB
..omitted..

ARP Cache

ArpCache class reads /proc/net/arp and returns arp entries.

ArpEntry has following fields:

public class ArpEntry {
	public String getIp();
	public int getHwType();
	public String getFlags();
	public String getMac();
	public String getMask();
	public String getDevice();
}

Usage example:

for (ArpEntry e : ArpCache.getEntries()) {
	System.out.println(e);
}

result:
device=eth0, ip=110.45.142.130, mac=00:21:5e:4d:ce:f8
device=eth0, ip=110.45.142.129, mac=00:0f:35:6c:f8:00

KernelStat

KernelStat has following members:

public class KernelStat {
	public CpuStat getCpu();
	public List<CpuStat> getCpus();
	public long getPagedIn();
	public long getPagedOut();
	public long getSwapIn();
	public long getSwapOut();
	public long getTotalInterrupts();
	public List<Long> getParticularInterrupts();
	public long getContext();
	public long getBootTime();
	public int getProcesses();
	public int getRunningProcess();
	public int getBlockedProcess();

	public static KernelStat getKernelStat() throws IOException;
}

CpuStat

CpuStat reads /proc/stat and returns cpu statistics.

Usage example:

CpuUsage usage = CpuStat.getCpuUsage();
System.out.println(usage);

result:
idle=94, system=4, user=2

MemoryStat

MemoryStat reads /proc/meminfo file.

Usage example:

MemoryStat mem = MemoryStat.getMemoryStat();
System.out.println(mem);

result:
MemTotal:        2062560 kB
MemFree:          181248 kB
Buffers:          285712 kB
Cached:           589912 kB
SwapCached:         3484 kB
Active:          1131132 kB
Inactive:         634160 kB
Active(anon):     643200 kB
Inactive(anon):   247108 kB
Active(file):     487932 kB
Inactive(file):   387052 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       4112376 kB
SwapFree:        4037532 kB
Dirty:                68 kB
Writeback:             4 kB
AnonPages:        886336 kB
Mapped:            26216 kB
Slab:              82316 kB
SReclaimable:      73136 kB
SUnreclaim:         9180 kB
PageTables:         7376 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     5143656 kB
Committed_AS:    1662492 kB
VmallocTotal:     122880 kB
VmallocUsed:       10012 kB
VmallocChunk:     109172 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       10232 kB
DirectMap2M:      899072 kB

This output is exactly same with cat /proc/meminfo .

NicStat

NicStat reads /proc/net/dev and returns nic statistics.

NicStat has following members:

public class NicStat {
	public String getName();
	public long getRxBytes();
	public long getRxPackets();
	public long getRxErrors();
	public long getRxDrops();
	public long getRxFifo();
	public long getRxFifo();
	public long getRxFrames();
	public long getRxCompressed();
	public long getRxMulticast();

	public long getTxBytes();
	public long getTxPackets();
	public long getTxErrors();
	public long getTxDrops();
	public long getTxFifo();
	public long getTxColls();
	public long getTxCarrier();
	public long getTxCompressed();

	public static List<NicStat> getNicStats() throws IOException;
}

Usage example:

for (NicStat nic : NicStat.getNicStats()) {
	System.out.println(nic);
}

result:
name=lo, rxBytes=3718687677, rxCompressed=0, rxDrops=0, rxErrors=0, rxFifo=0, rxFrames=0, rxMulticast=0, rxPackets=5191486, txBytes=3718687677, txCarrier=0, txColls=0, txCompressed=0, txDrops=0, txErrors=0, txFifo=0, txPackets=5191486
name=eth0, rxBytes=2552935457, rxCompressed=0, rxDrops=0, rxErrors=336875, rxFifo=0, rxFrames=188013, rxMulticast=22962596, rxPackets=703942274, txBytes=1039311310, txCarrier=0, txColls=0, txCompressed=0, txDrops=0, txErrors=0, txFifo=0, txPackets=1049547749
name=eth1, rxBytes=0, rxCompressed=0, rxDrops=0, rxErrors=0, rxFifo=0, rxFrames=0, rxMulticast=0, rxPackets=0, txBytes=0, txCarrier=0, txColls=0, txCompressed=0, txDrops=0, txErrors=0, txFifo=0, txPackets=0
..omitted..

See Also

History

  • 1.0.0 release (2010-12-24)