日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java中proc是什么意思,在java里头读取/proc/net/dev

發布時間:2023/12/19 java 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java中proc是什么意思,在java里头读取/proc/net/dev 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

直接讀取/proc/net/dev

public class NetStatReader implements MetricsReader {

private static File netstat = new File("/proc/net/dev");

private static final Pattern dline =

//rx //tx

// device_name -bytes packets errs drops fifo frame com mult -bytes packets errs drops fifo frame com mult

Pattern.compile("^ *([A-Za-z]+[0-9]*):\\D*(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+\\d+\\D+\\d+\\D+\\d+\\D+\\d+\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+\\d+\\D+\\d+\\D+\\d+\\D+\\d+.*");

private static final Logger LOG = Logger.getLogger(NetStatReader.class.getName());

@Inject

private Configuration conf;

private String device_regexp = "eth0";

/**

* It creates a wrapper to obtain statistics about a network interface by

* reading information from /proc/net/dev

*

* @param interfaceRegexp a string with a regexp to match with the device to

* control (e.g. "sd[ab]")

*

*

*/

public NetStatReader(String interfaceRegexp) {

LOG.log(Level.INFO, "Sampling interfaces {0}", interfaceRegexp);

this.device_regexp = interfaceRegexp;

checkArgument(netstat.exists(), "/proc/diskstats does not exists");

checkArgument(netstat.canRead(), "/proc/diskstats can not be read");

}

/**

* *

*

* @param interfaceRegexp

* @param processPid to bind the statistics to only one process

* @deprecated it seems to give the same results when looking for a process

* instead of the whole system

*/

@Deprecated

public NetStatReader(String interfaceRegexp, Integer processPid) {

LOG.log(Level.INFO, "Sampling interfaces {0} for process {1}",

new Object[]{interfaceRegexp, processPid});

this.device_regexp = interfaceRegexp;

netstat = new File("proc/" + processPid + "/net/dev");

checkArgument(netstat.exists(), "/proc/diskstats does not exists");

checkArgument(netstat.canRead(), "/proc/diskstats can not be read");

}

public NetStatReader() {

// checkArgument(diskstats.exists(), "/proc/diskstats does not exists");

// checkArgument(diskstats.canRead(), "/proc/diskstats can not be read");

}

@Override

public List call() throws Exception {

Builder b = ImmutableList.builder();

LineReader lr = new LineReader(new FileReader(netstat));

String l;

while ((l = lr.readLine()) != null) {

Matcher m = dline.matcher(l);

if (!m.matches()) {

continue;

}

String iface = m.group(1);

if (iface.matches(device_regexp)) {

b.addAll(Metric.Metric(iface)

.addMetric("rx.bytes", Long.parseLong(m.group(2)))

.addMetric("rx.packets", Long.parseLong(m.group(3)))

.addMetric("rx.errs", Long.parseLong(m.group(4)))

.addMetric("rx.drop", Long.parseLong(m.group(5)))

.addMetric("tx.bytes", Long.parseLong(m.group(6)))

.addMetric("tx.packets", Long.parseLong(m.group(7)))

.addMetric("tx.errs", Long.parseLong(m.group(8)))

.addMetric("tx.drop", Long.parseLong(m.group(9))).getList());

}

}

return b.build();

}

@Override

public void configure() {

if (conf.containsKey("netstat-reader.interfaceregexp")) {

this.device_regexp = conf.getString("netstat-reader.interfaceregexp");

checkArgument(netstat.exists(), "/proc/diskstats does not exists");

checkArgument(netstat.canRead(), "/proc/diskstats can not be read");

}

}

@Override

public void setConf(Configuration c) {

conf = c;

}

@Override

public Configuration getConf() {

return conf;

}

}

doc

總結

以上是生活随笔為你收集整理的Java中proc是什么意思,在java里头读取/proc/net/dev的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。