• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NetFlags类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.hyperic.sigar.NetFlags的典型用法代码示例。如果您正苦于以下问题:Java NetFlags类的具体用法?Java NetFlags怎么用?Java NetFlags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NetFlags类属于org.hyperic.sigar包,在下文中一共展示了NetFlags类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getIfaces

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
public static NetInterfaceConfig[] getIfaces() throws SigarException {
	_init();

	String[] ifaces = sigar.getNetInterfaceList();

	List<NetInterfaceConfig> l1 = new ArrayList<NetInterfaceConfig>();
	for (int i = 0; i < ifaces.length; i++) {
		NetInterfaceConfig cfg = sigar.getNetInterfaceConfig(ifaces[i]);
		if (NetFlags.LOOPBACK_ADDRESS.equals(cfg.getAddress()) || (cfg.getFlags() & NetFlags.IFF_LOOPBACK) != 0
				|| NetFlags.NULL_HWADDR.equals(cfg.getHwaddr())) {
			continue;
		}
		l1.add(cfg);
	}

	return l1.toArray(new NetInterfaceConfig[l1.size()]);
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:18,代码来源:Host.java


示例2: get

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
public SystemMetrics get() {
    try {
        final SystemMetrics.Builder metrics = new SystemMetrics.Builder();

        metrics.cpuPerc(sigar.getCpuPerc());
        metrics.mem(sigar.getMem());
        metrics.tcp(sigar.getTcp());
        metrics.tcpEstablishedCount(getCount(NetFlags.TCP_ESTABLISHED));
        metrics.tcpIdleCount(getCount(NetFlags.TCP_IDLE));
        metrics.tcpCloseCount(getCount(NetFlags.TCP_CLOSE));
        metrics.tcpClosingCount(getCount(NetFlags.TCP_CLOSING));
        metrics.tcpCloseWaitCount(getCount(NetFlags.TCP_CLOSE_WAIT));
        metrics.tcpTimeWaitCount(getCount(NetFlags.TCP_TIME_WAIT));
        metrics.tcpBoundCount(getCount(NetFlags.TCP_BOUND));

        return metrics.build();

    } catch (final SigarException e) {
        LOG.error("Could not get system metrics from Sigar.", e);
        return new SystemMetrics.Builder().build();
    }
}
 
开发者ID:vosmann,项目名称:flechette,代码行数:23,代码来源:SystemMetricsService.java


示例3: formatAddress

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
private String formatAddress(int proto, String ip,
                             long portnum, int max) {
    
    String port = formatPort(proto, portnum);
    String address;

    if (NetFlags.isAnyAddress(ip)) {
        address = "*";
    }
    else if (isNumeric) {
        address = ip;
    }
    else {
        try {
            address = InetAddress.getByName(ip).getHostName();
        } catch (UnknownHostException e) {
            address = ip;
        }
    }

    max -= port.length() + 1;
    if (address.length() > max) {
        address = address.substring(0, max);
    }

    return address + ":" + port; 
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:28,代码来源:Netstat.java


示例4: outputStats

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
private void outputStats(int flags) throws SigarException {
    if ((flags & NetFlags.CONN_TCP) != 0) {
        println("Tcp:");
        try {
            outputTcpStats();
        } catch (SigarException e) {
            println("    " + e);
        }
    }
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:11,代码来源:Netstat.java


示例5: getNetStats

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
public static List<JSON> getNetStats() throws SigarException {
	_init();
	int flags = NetFlags.CONN_CLIENT | NetFlags.CONN_SERVER | NetFlags.CONN_TCP | NetFlags.CONN_UDP
			| NetFlags.CONN_PROTOCOLS;
	NetConnection[] nn = sigar.getNetConnectionList(flags);
	List<JSON> l1 = new ArrayList<JSON>();
	for (NetConnection n : nn) {
		if (n.getRemotePort() == 0 && n.getLocalPort() == 0)
			continue;

		JSON jo = JSON.create().append("remoteaddress", n.getRemoteAddress())
				.append("remoteport", n.getRemotePort()).append("localaddress", n.getLocalAddress())
				.append("localport", n.getLocalPort()).append("recvqueue", n.getReceiveQueue())
				.append("sendqueue", n.getSendQueue()).append("state", n.getState()).append("type", n.getType())
				.append("typename", n.getTypeString());
		if (n.getType() != NetFlags.CONN_UDP) {
			jo.append("statename", n.getStateString());
		}
		try {
			long pid = sigar.getProcPort(n.getType(), n.getLocalPort());
			if (pid != 0) {
				ProcState p = sigar.getProcState(pid);
				if (p != null) {
					jo.append("pid", pid + "/" + p.getName());
				}
			}
		} catch (Exception e) {
			// ignore
			log.warn("get pid error, type=" + n.getType() + ", port=" + n.getLocalPort());
		}
		l1.add(jo);
	}
	return l1;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:35,代码来源:Host.java


示例6: output

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
public void output(String name) throws SigarException {
    NetInterfaceConfig ifconfig =
        this.sigar.getNetInterfaceConfig(name);
    long flags = ifconfig.getFlags();

    String hwaddr = "";
    if (!NetFlags.NULL_HWADDR.equals(ifconfig.getHwaddr())) {
        hwaddr = " HWaddr " + ifconfig.getHwaddr();
    }

    if (!ifconfig.getName().equals(ifconfig.getDescription())) {
        println(ifconfig.getDescription());
    }

    println(ifconfig.getName() + "\t" +
            "Link encap:" + ifconfig.getType() +
            hwaddr);

    String ptp = "";
    if ((flags & NetFlags.IFF_POINTOPOINT) > 0) {
        ptp = "  P-t-P:" + ifconfig.getDestination();
    }

    String bcast = "";
    if ((flags & NetFlags.IFF_BROADCAST) > 0) {
        bcast = "  Bcast:" + ifconfig.getBroadcast();
    }

    println("\t" +
            "inet addr:" + ifconfig.getAddress() + 
            ptp + //unlikely
            bcast +
            "  Mask:" + ifconfig.getNetmask());

    println("\t" +
            NetFlags.getIfFlagsString(flags) +
            " MTU:" + ifconfig.getMtu() +
            "  Metric:" + ifconfig.getMetric());
    try {
        NetInterfaceStat ifstat =
            this.sigar.getNetInterfaceStat(name);

        println("\t" +
                "RX packets:" + ifstat.getRxPackets() +
                " errors:" + ifstat.getRxErrors() +
                " dropped:" + ifstat.getRxDropped() +
                " overruns:" + ifstat.getRxOverruns() +
                " frame:" + ifstat.getRxFrame());

        println("\t" +
                "TX packets:" + ifstat.getTxPackets() +
                " errors:" + ifstat.getTxErrors() +
                " dropped:" + ifstat.getTxDropped() +
                " overruns:" + ifstat.getTxOverruns() +
                " carrier:" + ifstat.getTxCarrier());
        println("\t" + "collisions:" +
                ifstat.getTxCollisions());

        long rxBytes = ifstat.getRxBytes();
        long txBytes = ifstat.getTxBytes();

        println("\t" +
                "RX bytes:" + rxBytes +
                " (" + Sigar.formatSize(rxBytes) + ")" +
                "  " +
                "TX bytes:" + txBytes + 
                " (" + Sigar.formatSize(txBytes) + ")");
    } catch (SigarException e) {
    }

    println("");
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:73,代码来源:Ifconfig.java


示例7: getFlags

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
public static int getFlags(String[] args, int flags) {
    int proto_flags = 0;
    isNumeric = false;
    wantPid = false;
    isStat = false;

    for (int i=0; i<args.length; i++) {
        String arg = args[i];
        int j = 0;

        while (j<arg.length()) {
            switch (arg.charAt(j++)) {
              case '-':
                continue;
              case 'l':
                flags &= ~NetFlags.CONN_CLIENT;
                flags |= NetFlags.CONN_SERVER;
                break;
              case 'a':
                flags |= NetFlags.CONN_SERVER | NetFlags.CONN_CLIENT;
                break;
              case 'n':
                isNumeric = true;
                break;
              case 'p':
                wantPid = true;
                break;
              case 's':
                isStat = true;
                break;
              case 't':
                proto_flags |= NetFlags.CONN_TCP;
                break;
              case 'u':
                proto_flags |= NetFlags.CONN_UDP;
                break;
              case 'w':
                proto_flags |= NetFlags.CONN_RAW;
                break;
              case 'x':
                proto_flags |= NetFlags.CONN_UNIX;
                break;
              default:
                System.err.println("unknown option");
            }
        }
    }

    if (proto_flags != 0) {
        flags &= ~NetFlags.CONN_PROTOCOLS;
        flags |= proto_flags;
    }

    return flags;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:56,代码来源:Netstat.java


示例8: output

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
    //default
    int flags = NetFlags.CONN_CLIENT | NetFlags.CONN_PROTOCOLS;

    if (args.length > 0) {
        flags = getFlags(args, flags);
        if (isStat) {
            outputStats(flags);
            return;
        }
    }

    NetConnection[] connections = this.sigar.getNetConnectionList(flags);
    printf(HEADER);

    for (int i=0; i<connections.length; i++) {
        NetConnection conn = connections[i];
        String proto = conn.getTypeString();
        String state;

        if (conn.getType() == NetFlags.CONN_UDP) {
            state = "";
        }
        else {
            state = conn.getStateString();
        }

        ArrayList items = new ArrayList();
        items.add(proto);
        items.add(formatAddress(conn.getType(),
                                conn.getLocalAddress(),
                                conn.getLocalPort(),
                                LADDR_LEN));
        items.add(formatAddress(conn.getType(),
                                conn.getRemoteAddress(),
                                conn.getRemotePort(),
                                RADDR_LEN));
        items.add(state);

        String process = null;
        if (wantPid &&
            //XXX only works w/ listen ports
            (conn.getState() == NetFlags.TCP_LISTEN))
        {
            try {
                long pid =
                    this.sigar.getProcPort(conn.getType(),
                                           conn.getLocalPort());
                if (pid != 0) { //XXX another bug
                    String name =
                        this.sigar.getProcState(pid).getName();
                    process = pid + "/" + name;
                }
            } catch (SigarException e) {
            }
        }

        if (process == null) {
            process = "";
        }

        items.add(process);

        printf(items);
    }
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:67,代码来源:Netstat.java


示例9: run

import org.hyperic.sigar.NetFlags; //导入依赖的package包/类
@Override
public void run()
{
	if(pid == -1)
	{
		// get current process PID
		pid = sigar.getPid();
	}

	if(interfaceName == null)
	{
		try
		{
			NetInterfaceConfig ifConfig = sigar.getNetInterfaceConfig();
			if(!NetFlags.NULL_HWADDR.equals(ifConfig.getHwaddr()))
			{
				interfaceName = ifConfig.getName();
			}
		} catch(SigarException ex)
		{
			logger.error(ex.getMessage(), ex);
		}
	}

	logger.info("Running monitoring cycle...");
	running = true;
	try
	{
		while(running)
		{
			collectMetrics();

			sleep(period);
		}
	}
	catch(Exception e)
	{
		running = false;
	}
	logger.info("Finished monitoring cycle at " + System.currentTimeMillis());

	writeStatsToFile();
}
 
开发者ID:filipecampos,项目名称:raft_tests,代码行数:44,代码来源:MonitoringThread.java



注:本文中的org.hyperic.sigar.NetFlags类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Instruction51l类代码示例发布时间:2022-05-22
下一篇:
Java GetGroups类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap