Exemple #1
0
        internal static         String[] NativeGet(Sigar sigar)
        {
            Type   type = typeof(NetInterfaceList);
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status =
                sigar_net_interface_list_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            NetInterfaceList ifPtr =
                (NetInterfaceList)Marshal.PtrToStructure(ptr, type);

            String[] iflist = new String[ifPtr.number];

            IntPtr iptr = ifPtr.data;

            for (int i = 0; i < ifPtr.number; i++)
            {
                IntPtr str = Marshal.ReadIntPtr(iptr, i * IntPtr.Size);
                iflist[i] = Marshal.PtrToStringAnsi(str);
            }

            sigar_net_interface_list_destroy(sigar.sigar.Handle, ptr);

            Marshal.FreeHGlobal(ptr);

            return(iflist);
        }
Exemple #2
0
        internal static                Who[] NativeGet(Sigar sigar)
        {
            System.Type   typeFromHandle = typeof(WhoList);
            System.IntPtr intPtr         = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle));
            int           num            = WhoList.sigar_who_list_get(sigar.sigar.Handle, intPtr);

            if (num != 0)
            {
                System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr);
                throw Sigar.FindException(sigar, num);
            }
            WhoList whoList = (WhoList)System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle);

            Who[]         array = new Who[whoList.Number];
            System.IntPtr ptr   = whoList.data;
            int           num2  = System.Runtime.InteropServices.Marshal.SizeOf(array[0]);
            int           num3  = 0;

            while ((long)num3 < (long)((ulong)whoList.Number))
            {
                array[num3] = (Who)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, typeof(Who));
                ptr         = Sigar.incrementIntPtr(ptr, num2);
                num3++;
            }
            WhoList.sigar_who_list_destroy(sigar.sigar.Handle, intPtr);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr);
            return(array);
        }
Exemple #3
0
        internal static string[] NativeGet(Sigar sigar)
        {
            System.Type   typeFromHandle = typeof(NetInterfaceList);
            System.IntPtr intPtr         = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle));
            int           num            = NetInterfaceList.sigar_net_interface_list_get(sigar.sigar.Handle, intPtr);

            if (num != 0)
            {
                System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr);
                throw Sigar.FindException(sigar, num);
            }
            NetInterfaceList netInterfaceList = (NetInterfaceList)System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle);

            string[]      array = new string[netInterfaceList.number];
            System.IntPtr ptr   = netInterfaceList.data;
            int           num2  = 0;

            while ((long)num2 < (long)((ulong)netInterfaceList.number))
            {
                System.IntPtr ptr2 = System.Runtime.InteropServices.Marshal.ReadIntPtr(ptr, num2 * System.IntPtr.Size);
                array[num2] = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr2);
                num2++;
            }
            NetInterfaceList.sigar_net_interface_list_destroy(sigar.sigar.Handle, intPtr);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr);
            return(array);
        }
    public static void Main()
    {
        Sigar sigar = new Sigar();

        foreach (String name in sigar.NetInterfaceList()) {
            output(sigar, name);
        }
    }
Exemple #5
0
        internal static SigarException FindException(Sigar sigar, int errno)
        {
            switch (errno)
            {
            case SIGAR_ENOTIMPL:
                return(new SigarNotImplementedException(sigar, errno));

            default:
                return(new SigarException(sigar, errno));
            }
        }
Exemple #6
0
    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("");
        }
    }
Exemple #7
0
        internal static Cpu NativeGet(Sigar sigar)
        {
            Type type = typeof(Cpu);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_cpu_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            Cpu cpu = (Cpu)Marshal.PtrToStructure(ptr, type);
            Marshal.FreeHGlobal(ptr);

            return cpu;
        }
Exemple #8
0
        internal static Cpu NativeGet(Sigar sigar)
        {
            Type   type = typeof(Cpu);
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_cpu_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            Cpu cpu = (Cpu)Marshal.PtrToStructure(ptr, type);

            Marshal.FreeHGlobal(ptr);

            return(cpu);
        }
Exemple #9
0
        internal static Mem NativeGet(Sigar sigar)
        {
            Type type = typeof(Mem);
            //sigar_mem_t *ptr = malloc(sizeof(*ptr))
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_mem_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            //memcpy(ptr, this, sizeof(this))
            Mem mem = (Mem)Marshal.PtrToStructure(ptr, type);

            Marshal.FreeHGlobal(ptr);
            return(mem);
        }
Exemple #10
0
    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");
    }
Exemple #11
0
        internal static NetInterfaceStat NativeGet(Sigar sigar,
                                                   string name)
        {
            Type   type = typeof(NetInterfaceStat);
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_net_interface_stat_get(sigar.sigar.Handle,
                                                      name, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            NetInterfaceStat ifstat =
                (NetInterfaceStat)Marshal.PtrToStructure(ptr, type);

            Marshal.FreeHGlobal(ptr);

            return(ifstat);
        }
Exemple #12
0
        internal static FileSystemUsage NativeGet(Sigar sigar,
                                                  string dirname)
        {
            Type   type = typeof(FileSystemUsage);
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_file_system_usage_get(sigar.sigar.Handle,
                                                     dirname, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            FileSystemUsage fsusage =
                (FileSystemUsage)Marshal.PtrToStructure(ptr, type);

            Marshal.FreeHGlobal(ptr);

            return(fsusage);
        }
Exemple #13
0
        internal static         FileSystem[] NativeGet(Sigar sigar)
        {
            Type   type = typeof(FileSystemList);
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_file_system_list_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            FileSystemList fsPtr =
                (FileSystemList)Marshal.PtrToStructure(ptr, type);

            FileSystem[] fs = new FileSystem[fsPtr.Number];

            IntPtr fptr = fsPtr.data;
            int    size = Marshal.SizeOf(fs[0]);

            for (int i = 0; i < fsPtr.Number; i++)
            {
                fs[i] =
                    (FileSystem)Marshal.PtrToStructure(fptr,
                                                       typeof(FileSystem));

                //fptr += sizeof(sigar_fs_t);
                fptr = Sigar.incrementIntPtr(fptr, size);
            }

            sigar_file_system_list_destroy(sigar.sigar.Handle, ptr);

            Marshal.FreeHGlobal(ptr);

            return(fs);
        }
Exemple #14
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);
        }
    }
Exemple #15
0
        internal static         CpuInfo[] NativeGet(Sigar sigar)
        {
            Type   type = typeof(CpuInfoList);
            IntPtr ptr  = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_cpu_info_list_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK)
            {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            CpuInfoList infosPtr =
                (CpuInfoList)Marshal.PtrToStructure(ptr, type);

            CpuInfo[] infos = new CpuInfo[infosPtr.Number];

            IntPtr eptr = infosPtr.data;
            int    size = Marshal.SizeOf(infos[0]);

            for (int i = 0; i < infosPtr.Number; i++)
            {
                infos[i] =
                    (CpuInfo)Marshal.PtrToStructure(eptr, typeof(CpuInfo));

                //eptr += sizeof(sigar_cpu_info_t);
                eptr = Sigar.incrementIntPtr(eptr, size);
            }

            sigar_cpu_info_list_destroy(sigar.sigar.Handle, ptr);

            Marshal.FreeHGlobal(ptr);

            return(infos);
        }
Exemple #16
0
        internal static String[] NativeGet(Sigar sigar) {
            Type type = typeof(NetInterfaceList);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status =
                sigar_net_interface_list_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            NetInterfaceList ifPtr =
                (NetInterfaceList)Marshal.PtrToStructure(ptr, type);

            String[] iflist = new String[ifPtr.number];

            IntPtr iptr = ifPtr.data;

            for (int i=0; i<ifPtr.number; i++) {
                IntPtr str = Marshal.ReadIntPtr(iptr, i * IntPtr.Size);
                iflist[i] = Marshal.PtrToStringAnsi(str);
            }

            sigar_net_interface_list_destroy(sigar.sigar.Handle, ptr);

            Marshal.FreeHGlobal(ptr);

            return iflist;
        }
Exemple #17
0
        internal static FileSystemUsage NativeGet(Sigar sigar,
                                                  string dirname) {
            Type type = typeof(FileSystemUsage);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_file_system_usage_get(sigar.sigar.Handle,
                                                     dirname, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            FileSystemUsage fsusage =
                (FileSystemUsage)Marshal.PtrToStructure(ptr, type);

            Marshal.FreeHGlobal(ptr);

            return fsusage;
        }
Exemple #18
0
        internal static FileSystem[] NativeGet(Sigar sigar) {
            Type type = typeof(FileSystemList);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_file_system_list_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            FileSystemList fsPtr =
                (FileSystemList)Marshal.PtrToStructure(ptr, type);

            FileSystem[] fs = new FileSystem[fsPtr.Number];

            IntPtr fptr = fsPtr.data;
            int size = Marshal.SizeOf(fs[0]);

            for (int i=0; i<fsPtr.Number; i++) {
                fs[i] =
                    (FileSystem)Marshal.PtrToStructure(fptr,
                                                       typeof(FileSystem));

                //fptr += sizeof(sigar_fs_t);
                fptr = Sigar.incrementIntPtr(fptr, size);
            }

            sigar_file_system_list_destroy(sigar.sigar.Handle, ptr);

            Marshal.FreeHGlobal(ptr);

            return fs;
        }
Exemple #19
0
        internal static CpuInfo[] NativeGet(Sigar sigar) {
            Type type = typeof(CpuInfoList);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_cpu_info_list_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            CpuInfoList infosPtr =
                (CpuInfoList)Marshal.PtrToStructure(ptr, type);

            CpuInfo[] infos = new CpuInfo[infosPtr.Number];

            IntPtr eptr = infosPtr.data;
            int size = Marshal.SizeOf(infos[0]);

            for (int i=0; i<infosPtr.Number; i++) {
                infos[i] =
                    (CpuInfo)Marshal.PtrToStructure(eptr, typeof(CpuInfo));

                //eptr += sizeof(sigar_cpu_info_t);
                eptr = Sigar.incrementIntPtr(eptr, size);
            }

            sigar_cpu_info_list_destroy(sigar.sigar.Handle, ptr);

            Marshal.FreeHGlobal(ptr);

            return infos;
        }
Exemple #20
0
        internal static Swap NativeGet(Sigar sigar) {
            Type type = typeof(Swap);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_swap_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            Swap swap = (Swap)Marshal.PtrToStructure(ptr, type);
            Marshal.FreeHGlobal(ptr);

            return swap;
        }
Exemple #21
0
        internal static Mem NativeGet(Sigar sigar) {
            Type type = typeof(Mem);
            //sigar_mem_t *ptr = malloc(sizeof(*ptr))
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_mem_get(sigar.sigar.Handle, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            //memcpy(ptr, this, sizeof(this))
            Mem mem = (Mem)Marshal.PtrToStructure(ptr, type);
            Marshal.FreeHGlobal(ptr);
            return mem;
        }
Exemple #22
0
 public SigarException(Sigar sigar, int errno) : base() {
     this.sigar = sigar;
     this.errno = errno;
 }
Exemple #23
0
 internal static SigarException FindException(Sigar sigar, int errno) {
     switch (errno) {
       case SIGAR_ENOTIMPL:
         return new SigarNotImplementedException(sigar, errno);
       default:
         return new SigarException(sigar, errno);
     }
 }
Exemple #24
0
 public SigarException(Sigar sigar, int errno) : base()
 {
     this.sigar = sigar;
     this.errno = errno;
 }
Exemple #25
0
 public SigarNotImplementedException(Sigar sigar, int errno) :
     base(sigar, errno)
 {
 }
Exemple #26
0
        internal static NetInterfaceStat NativeGet(Sigar sigar,
                                                   string name) {
            Type type = typeof(NetInterfaceStat);
            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type));

            int status = sigar_net_interface_stat_get(sigar.sigar.Handle,
                                                      name, ptr);

            if (status != Sigar.OK) {
                Marshal.FreeHGlobal(ptr);
                throw Sigar.FindException(sigar, status);
            }

            NetInterfaceStat ifstat =
                (NetInterfaceStat)Marshal.PtrToStructure(ptr, type);

            Marshal.FreeHGlobal(ptr);

            return ifstat;
        }
Exemple #27
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("");
    }
Exemple #28
0
 public SigarNotImplementedException(Sigar sigar, int errno) :
     base(sigar, errno) { }