本文整理汇总了Java中org.hyperic.sigar.NetInterfaceConfig类的典型用法代码示例。如果您正苦于以下问题:Java NetInterfaceConfig类的具体用法?Java NetInterfaceConfig怎么用?Java NetInterfaceConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NetInterfaceConfig类属于org.hyperic.sigar包,在下文中一共展示了NetInterfaceConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIfaces
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的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()]);
}
示例2: getIfstats
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的package包/类
public static List<JSON> getIfstats() throws SigarException {
_init();
String[] ifaces = sigar.getNetInterfaceList();
List<JSON> l1 = new ArrayList<JSON>();
for (int i = 0; i < ifaces.length; i++) {
NetInterfaceConfig cfg = sigar.getNetInterfaceConfig(ifaces[i]);
if ((cfg.getFlags() & 1L) <= 0L || X.isSame(cfg.getAddress(), "0.0.0.0")) {
continue;
}
NetInterfaceStat s = sigar.getNetInterfaceStat(ifaces[i]);
l1.add(JSON.create().append("address", cfg.getAddress()).append("name", cfg.getName())
.append("rxbytes", s.getRxBytes()).append("rxdropped", s.getRxDropped())
.append("rxerrors", s.getRxErrors()).append("rxframe", s.getRxFrame())
.append("rxoverrunns", s.getRxOverruns()).append("rxpackets", s.getRxPackets())
.append("speed", s.getSpeed()).append("txbytes", s.getTxBytes())
.append("txcarrier", s.getTxCarrier()).append("txcollisions", s.getTxCollisions())
.append("txdropped", s.getTxDropped()).append("txerrors", s.getTxErrors())
.append("txoverruns", s.getTxOverruns()).append("txpackets", s.getTxPackets()));
}
return l1;
}
示例3: output
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
NetInterfaceConfig config = this.sigar.getNetInterfaceConfig(null);
println("primary interface....." +
config.getName());
println("primary ip address...." +
config.getAddress());
println("primary mac address..." +
config.getHwaddr());
println("primary netmask......." +
config.getNetmask());
org.hyperic.sigar.NetInfo info =
this.sigar.getNetInfo();
println("host name............." +
info.getHostName());
println("domain name..........." +
info.getDomainName());
println("default gateway......." +
info.getDefaultGateway());
println("primary dns..........." +
info.getPrimaryDns());
println("secondary dns........." +
info.getSecondaryDns());
}
示例4: NetworkInterfaces
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的package包/类
NetworkInterfaces(
final UnitConversionService units,
final CachingService caching,
final Sigar sigar,
final AnnotationMBeanExporter server) throws SigarException, JMException {
super();
for(final String iface : ImmutableSet.copyOf(sigar.getNetInterfaceList())) {
final NetInterfaceConfig config = sigar.getNetInterfaceConfig(iface);
final Try.CheckedSupplier<NetInterfaceStat> stats = caching
.cache(() -> sigar.getNetInterfaceStat(iface));
final String name = config.getName();
final NetworkInterfaceMetrics info = SigarNetworkInterfaceMetrics
.builder()
.name(name)
.stats(stats)
.units(units)
.build();
server.registerManagedResource(info, new ObjectName(format(OBJECT_NAME, ObjectName.quote(name))));
}
}
示例5: logAvailableInterfaces
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的package包/类
static void logAvailableInterfaces(SigarProxy sigar) {
log.info("*** Logging available network interfaces ***");
try {
String[] list = sigar.getNetInterfaceList();
for (int n = 0; n < list.length; n++) {
NetInterfaceConfig ifc = sigar.getNetInterfaceConfig(list[n]);
log.info("Network interface: iface=" + ifc.getName() + " addr=" + ifc.getAddress() + " type=" + ifc.getType());
}
} catch (SigarException e) {
log.debug("Can't get network info", e);
}
}
示例6: output
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的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("");
}
示例7: getInfoFromSigar
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的package包/类
private StringBuilder getInfoFromSigar() throws Exception {
StringBuilder sb = new StringBuilder();
Sigar sigar = new Sigar();
sb.append("Fully Qualified Domain Name:\n\t" + sigar.getFQDN().toString());
sb.append("\nSystem uptime:\n\t" + new Double(sigar.getUptime().getUptime()).intValue()
+ " seconds");
sb.append("\nDate:\n\t" + new Date());
sb.append("\nNetwork settings:" + format(sigar.getNetInfo().toString(), 1));
sb.append("\nCPU info:");
CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
for (int i = 0; i < cpuInfoList.length; i++) {
CpuInfo cpuInfo = cpuInfoList[i];
sb.append("\n\tCPU " + i + ": ");
sb.append(format(cpuInfo.toString(), 2));
}
double totalMemory = (new Long(sigar.getMem().getTotal()).doubleValue() / 1024 / 1024 / 1024);
sb.append("\nTotal memory:\n\t"
+ new BigDecimal(totalMemory).setScale(2, BigDecimal.ROUND_DOWN).floatValue() + " GB");
String[] nicList = sigar.getNetInterfaceList();
sb.append("\nNIC info: ");
for (int i = 0; i < nicList.length; i++) {
NetInterfaceConfig nic = sigar.getNetInterfaceConfig(nicList[i]);
sb.append("\n\tNIC " + i + ": ");
sb.append(format(nic.toString(), 2));
}
FileSystem[] fileSystemList = sigar.getFileSystemList();
sb.append("\nFile system info: ");
for (int i = 0; i < fileSystemList.length; i++) {
FileSystem fileSystem = fileSystemList[i];
sb.append("\n\t" + fileSystem.getDevName() + " is a");
if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK) {
sb.append(" local");
} else if (fileSystem.getType() == FileSystem.TYPE_NETWORK) {
sb.append(" network");
} else if (fileSystem.getType() == FileSystem.TYPE_RAM_DISK) {
sb.append(" ram disk");
} else if (fileSystem.getType() == FileSystem.TYPE_SWAP) {
sb.append(" swap");
}
sb.append(" " + fileSystem.getSysTypeName() + ", dir name '" + fileSystem.getDirName()
+ "', options '" + fileSystem.getOptions() + "'");
}
sb.append("\nResource limits:" + format(sigar.getResourceLimit().toString(), "max", 1));
return sb;
}
示例8: registerIPToMonitor
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的package包/类
/**
* @throws InterruptedException
* @throws SigarException
*
*/
public static void registerIPToMonitor(String ip)
{
if (ip != null && !ip.isEmpty())
{
if (enabled)
{
if(SystemCounter.getSigar() == null)
return ;
try
{
for (String ni : SystemCounter.getSigar().getNetInterfaceList())
{
NetInterfaceConfig ifConfig = null;
try
{
ifConfig = SystemCounter.getSigar().getNetInterfaceConfig(ni);
}
catch (SigarException ex)
{
Logger.getLogger(NetworkData.class.getName()).log(Level.SEVERE, null, ex);
}
if (ip != null && ip.equals(ifConfig.getAddress()))
{
synchronized (filteredIP)
{
if (!filteredIP.containsKey(ip))
{
filteredIP.put(ip, ni);
}
}
}
}
}
catch (Throwable exc)
{
enabled = false;
}
}
}
}
示例9: run
import org.hyperic.sigar.NetInterfaceConfig; //导入依赖的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();
}