コード例 #1
0
    public static void Main()
    {
        Sigar sigar = new Sigar();

        foreach (String name in sigar.NetInterfaceList())
        {
            output(sigar, name);
        }
    }
コード例 #2
0
ファイル: CpuInfo.cs プロジェクト: murisfurder/sigar
    public static void Main()
    {
        Sigar sigar = new Sigar();

        Hyperic.Sigar.CpuInfo[] infos =
            sigar.CpuInfoList();

        System.Console.WriteLine(infos.Length + " total CPUs..");

        foreach (Hyperic.Sigar.CpuInfo info in infos)
        {
            System.Console.WriteLine("Vendor........" + info.Vendor);
            System.Console.WriteLine("Model........." + info.Model);
            System.Console.WriteLine("Mhz..........." + info.Mhz);
            System.Console.WriteLine("");
        }
    }
コード例 #3
0
ファイル: Free.cs プロジェクト: murisfurder/sigar
    public static void Main()
    {
        Sigar sigar = new Sigar();

        Mem  mem  = sigar.Mem();
        Swap swap = sigar.Swap();

        System.Console.WriteLine("\tTotal\tUsed\tFree");

        System.Console.WriteLine("Mem:\t" +
                                 mem.Total / 1024 + "\t" +
                                 mem.Used / 1024 + "\t" +
                                 mem.Free / 1024);

        System.Console.WriteLine("Swap:\t" +
                                 swap.Total / 1024 + "\t" +
                                 swap.Used / 1024 + "\t" +
                                 swap.Free / 1024);

        System.Console.WriteLine("RAM:\t" + mem.Ram + "MB");
    }
コード例 #4
0
    public static void Main()
    {
        Sigar sigar = new Sigar();

        foreach (FileSystem fs in sigar.FileSystemList())
        {
            FileSystemUsage usage;
            long            used, avail, total, pct;

            try {
                usage = sigar.FileSystemUsage(fs.DirName);

                used  = usage.Total - usage.Free;
                avail = usage.Avail;
                total = usage.Total;
                pct   = (long)(usage.UsePercent * 100);
            } catch (SigarException) {
                used = avail = total = pct = 0;
                continue;
            }

            string usePct;
            if (pct == 0)
            {
                usePct = "-";
            }
            else
            {
                usePct = pct + "%";
            }

            System.Console.WriteLine(fs.DevName + "\t" +
                                     FormatSize(total) + "\t" +
                                     FormatSize(used) + "\t" +
                                     FormatSize(avail) + "\t" +
                                     usePct + "\t" +
                                     fs.DirName + "\t" +
                                     fs.SysTypeName + "/" + fs.TypeName);
        }
    }
コード例 #5
0
 private static String FormatSize(long value)
 {
     return(Sigar.FormatSize(value * 1024));
 }
コード例 #6
0
    private static void output(Sigar sigar, String name)
    {
        NetInterfaceConfig ifconfig =
            sigar.NetInterfaceConfig(name);
        long flags = ifconfig.Flags;

        String hwaddr = "";

        if (!Sigar.NULL_HWADDR.Equals(ifconfig.Hwaddr))
        {
            hwaddr = " HWaddr " + ifconfig.Hwaddr;
        }

        println(ifconfig.Name + "\t" +
                "Link encap:" + ifconfig.Type +
                hwaddr);

        String ptp = "";

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

        String bcast = "";

        if ((flags & Sigar.IFF_BROADCAST) > 0)
        {
            bcast = "  Bcast:" + ifconfig.Broadcast;
        }

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

        println("\t" +
                ifconfig.FlagsString() +
                " MTU:" + ifconfig.Mtu +
                "  Metric:" + ifconfig.Metric);
        try {
            NetInterfaceStat ifstat =
                sigar.NetInterfaceStat(name);

            println("\t" +
                    "RX packets:" + ifstat.RxPackets +
                    " errors:" + ifstat.RxErrors +
                    " dropped:" + ifstat.RxDropped +
                    " overruns:" + ifstat.RxOverruns +
                    " frame:" + ifstat.RxFrame);

            println("\t" +
                    "TX packets:" + ifstat.TxPackets +
                    " errors:" + ifstat.TxErrors +
                    " dropped:" + ifstat.TxDropped +
                    " overruns:" + ifstat.TxOverruns +
                    " carrier:" + ifstat.TxCarrier);
            println("\t" + "collisions:" +
                    ifstat.TxCollisions);

            long rxBytes = ifstat.RxBytes;
            long txBytes = ifstat.TxBytes;

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

        println("");
    }