Compare commits

..

27 Commits

Author SHA1 Message Date
2b713c3dd4 更新 src/os/linux/linux_sigar.c 2024-09-27 17:10:00 +08:00
Konstantin Makarchev
af03ded75f 2.0.11 2024-09-10 14:52:40 +03:00
Kostya M
00760eebda
Merge pull request #16 from wollistik/fix_build_issue
Fixing build issue on newer linux and also issues with newer Ruby
2024-09-10 14:49:54 +03:00
Wolfgang Wedelich-John
8b887b2380 Fixing build issue on newer linux and alos issue with newer Ruby 2024-09-10 12:58:09 +02:00
Konstantin Makarchev
9f918d1ae9 2.0.10 2021-10-31 05:29:09 +03:00
Konstantin Makarchev
49a9aeeff5 remove nfsstat methods on osx, because seems it not used, this should fix #11
TODO: return is back, if fix would be finded
2021-10-30 21:02:07 +03:00
Konstantin Makarchev
04754bdf48 fix 2021-06-28 12:24:24 +03:00
Konstantin Makarchev
9691f4bbf7 2.0.9 2021-06-28 12:17:33 +03:00
Konstantin Makarchev
b78b558fb7 fixed #10, apply path from https://svnweb.freebsd.org/ports/head/devel/sigar/files/patch-src_os_darwin_darwin__sigar.c?r1=438996&r2=544794 2021-06-28 11:59:40 +03:00
Konstantin Makarchev
01df5b7739 fix readme 2020-10-05 23:32:01 +03:00
Konstantin Makarchev
d521805a2d 2.0.8 2020-10-05 23:30:16 +03:00
Konstantin Makarchev
7898cebf27 2.0.7 2020-10-02 18:46:51 +03:00
Kostya M
68ba944840
Merge pull request #9 from yxhuvud/fix-compile-macos
Fix compilation on macos.
2020-10-02 18:42:01 +03:00
Linus Sellberg
ad39547629 Fix compilation on macos. 2020-10-02 14:55:03 +02:00
Konstantin Makarchev
c5f71e36b7 2.0.6 2019-01-18 09:31:25 +03:00
Konstantin Makarchev
ad4ff7f83f fix readme 2019-01-18 09:31:17 +03:00
Konstantin Makarchev
2bb67fa1bf apply freebsd12 compilation patch (#6)
https://svnweb.freebsd.org/ports/head/devel/sigar/files/patch-src_os_darwin_darwin__sigar.c?revision=438996&view=markup
2019-01-18 09:21:16 +03:00
Konstantin Makarchev
4aeac4dfe8 fix doc 2018-12-02 22:39:58 +03:00
Konstantin Makarchev
2c5dd8b674 2.0.5 2018-12-02 22:36:19 +03:00
Kostya M
d88f2121b8
Merge pull request #4 from jcoyne/patch-1
Fix compilation with musl libc
2018-12-02 22:33:16 +03:00
Natanael Copa
621764c13d only enable the GNU libc strerror_r on GNU libc
We don't want use the non-standard GNU libc variant of strerror_r on
musl libc, or any libc other than GNU.
2018-11-30 22:34:24 -06:00
Natanael Copa
cd07923dd2 fix compilation with musl libc
the HZ define is not exposed by musl libc.
2018-11-30 22:33:49 -06:00
Konstantin Makarchev
0d4fe42927 fix 2018-06-28 22:21:59 +03:00
Konstantin Makarchev
369e5b093e fix 2018-06-28 22:20:17 +03:00
Konstantin Makarchev
9f05d47620 fix doc 2018-06-28 22:19:23 +03:00
Konstantin Makarchev
9b60875c06 fix 2018-06-28 22:17:45 +03:00
Konstantin Makarchev
163745ad5d doc 2018-06-10 07:55:25 +03:00
9 changed files with 186 additions and 81 deletions

View File

@ -1,23 +1,41 @@
# System Information Gatherer And Reporter.
Fork of hyperic/sigar with some fixes. Support only ruby binding.
Fork of hyperic/sigar with some fixes. Support only ruby binding. Part of [Eye gem](https://github.com/kostya/eye).
## Fixed:
[2.0.0]
### [2.0.11] 10-09-2024
* Fixing build issue on newer linux and also issues with newer Ruby [#16](https://github.com/kostya/sigar/pull/16)([commit](https://github.com/kostya/sigar/pull/16/commits/8b887b2380c4aadea82402904d9c1131bbb9c521))
### [2.0.10] 31-10-2021
* Fix compilation on MacOS 11.3.1 [#11](https://github.com/kostya/sigar/issues/11)([commit](https://github.com/kostya/sigar/commit/49a9aeeff54e97ac6f41d464c30ff6c8adf4bcf4))
### [2.0.9] 28-06-2021
* Fix compilation on FreeBSD 13 [#10](https://github.com/kostya/sigar/issues/10)([commit](https://github.com/kostya/sigar/commit/b78b558fb756a75dc7d6cbf704423be3c7098ae5))
### [2.0.8] 02-10-2020
* Fix compilation on MacOS [#8](https://github.com/kostya/sigar/issues/8)([commit](https://github.com/kostya/sigar/pull/9/commits/ad39547629fa328e115f7d7bc3c7c358247d1961))
### [2.0.6] 18-01-2019
* Fix compilation on FreeBSD 12 [#6](https://github.com/kostya/sigar/issues/6)([commit](https://github.com/kostya/sigar/commit/2bb67fa1bf6f6f0ddc2626cf028bcc0e4a8cb377))
### [2.0.5] 02-12-2018
* Fix compilation with musl libc [#4](https://github.com/kostya/sigar/pull/4)([commit](https://github.com/kostya/sigar/pull/4/commits/cd07923dd2ed34aca353dfd182f2f85c13853fd9))
### [2.0.4] 10-06-2018
* fix compilation with glibc 2.26, major/minor functions [#2](https://github.com/kostya/sigar/issues/2)([commit](https://github.com/kostya/sigar/commit/a2c67588d0f686e0007dadcaf0e4bbb35c0e1e83))
### [2.0.2] 30-05-2018
* Remove obsolete rpc usage (fix compilation fail with glibc 2.27) [#213](https://github.com/kostya/eye/issues/213)([commit](https://github.com/kostya/sigar/commit/a971b9e8e1443fdf236c5ffa199c1994c05fcd4b))
### [2.0.1] 10-04-2018
* FreeBSD: don't use v_cache_min/max [#68](https://github.com/hyperic/sigar/pull/68)([commit](https://github.com/kostya/sigar/commit/800076db97bcacb1ba90805d740b4f9a5a1d3cca))
### [2.0.0] 22-01-2018
* sigfaulted logger, [#28](https://github.com/hyperic/sigar/pull/28)([commit](https://github.com/kostya/sigar/commit/c2a1af))
* bug undefined symbol: sigar_skip_token, [#60](https://github.com/hyperic/sigar/pull/60)([commit](https://github.com/kostya/sigar/commit/dfe8fe))
* bug detection boot_time on linux (now it works like gnu ps, and fix some issues with process start_time) ([commit](https://github.com/kostya/sigar/commit/660259))
[2.0.1]
* FreeBSD: don't use v_cache_min/max [#68](https://github.com/hyperic/sigar/pull/68)([commit](https://github.com/kostya/sigar/commit/800076db97bcacb1ba90805d740b4f9a5a1d3cca))
[2.0.2]
* Remove obsolete rpc usage (fix compilation fail with glibc 2.27) ([commit](https://github.com/kostya/sigar/commit/a971b9e8e1443fdf236c5ffa199c1994c05fcd4b))
[2.0.4]
* fix compilation with glibc 2.26, major/minor functions ([commit](https://github.com/kostya/sigar/commit/a2c67588d0f686e0007dadcaf0e4bbb35c0e1e83))
## Installation:

View File

@ -27,7 +27,6 @@ spec = Gem::Specification.new do |s|
s.email = props['project.email']
s.homepage = props['project.homepage']
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extensions = 'bindings/ruby/extconf.rb'
s.files =
%w(LICENSE NOTICE README.md Rakefile version.properties) +
@ -52,15 +51,15 @@ end
desc 'Build sigar extension'
task :build do
in_ext()
unless File.exists? "Makefile"
unless File.exist? "Makefile"
unless system("ruby extconf.rb")
STDERR.puts "Failed to configure"
break
next
end
end
unless system(MAKE)
STDERR.puts 'Failed to ' + MAKE
break
next
end
end
@ -76,13 +75,13 @@ end
desc 'Clean sigar extension'
task :clean do
in_ext()
system(MAKE + ' clean') if File.exists? "Makefile"
system(MAKE + ' clean') if File.exist? "Makefile"
end
desc 'Dist Clean sigar extension'
task :distclean do
in_ext()
system(MAKE + ' distclean') if File.exists? "Makefile"
system(MAKE + ' distclean') if File.exist? "Makefile"
end
desc 'Run sigar examples (test)'

View File

@ -24,6 +24,7 @@
#endif
#include <errno.h>
#include <ctype.h>
#include "sigar.h"
#include "sigar_fileinfo.h"
#include "sigar_format.h"

View File

@ -4,7 +4,7 @@
Gem::Specification.new do |s|
s.name = "kostya-sigar"
s.version = "2.0.2"
s.version = "2.0.11"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]

View File

@ -123,6 +123,69 @@
#endif
#if defined(SIGAR_FREEBSD5)
#if __FreeBSD_version >= 1200028
#define VMMETER_TYPE uint64_t
#else
#define VMMETER_TYPE u_int
#endif
struct __vmmeter {
VMMETER_TYPE v_vm_faults;
VMMETER_TYPE v_io_faults;
VMMETER_TYPE v_cow_faults;
VMMETER_TYPE v_cow_optim;
VMMETER_TYPE v_zfod;
VMMETER_TYPE v_ozfod;
VMMETER_TYPE v_swapin;
VMMETER_TYPE v_swapout;
VMMETER_TYPE v_swappgsin;
VMMETER_TYPE v_swappgsout;
VMMETER_TYPE v_vnodein;
VMMETER_TYPE v_vnodeout;
VMMETER_TYPE v_vnodepgsin;
VMMETER_TYPE v_vnodepgsout;
VMMETER_TYPE v_intrans;
VMMETER_TYPE v_reactivated;
VMMETER_TYPE v_pdwakeups;
VMMETER_TYPE v_pdpages;
VMMETER_TYPE v_pdshortfalls;
VMMETER_TYPE v_dfree;
VMMETER_TYPE v_pfree;
VMMETER_TYPE v_tfree;
VMMETER_TYPE v_forks;
VMMETER_TYPE v_vforks;
VMMETER_TYPE v_rforks;
VMMETER_TYPE v_kthreads;
VMMETER_TYPE v_forkpages;
VMMETER_TYPE v_vforkpages;
VMMETER_TYPE v_rforkpages;
VMMETER_TYPE v_kthreadpages;
VMMETER_TYPE v_swtch;
VMMETER_TYPE v_syscall;
VMMETER_TYPE v_trap;
VMMETER_TYPE v_intr;
VMMETER_TYPE v_soft;
u_int v_page_size;
u_int v_page_count;
u_int v_free_reserved;
u_int v_free_target;
u_int v_free_min;
u_int v_free_count;
u_int v_wire_count;
u_int v_active_count;
u_int v_inactive_target;
u_int v_inactive_count;
u_int v_laundry_count;
u_int v_pageout_free_min;
u_int v_interrupt_free_min;
u_int v_free_severe;
#if (__FreeBSD_version < 1200016)
u_int v_cache_count;
#endif
#if (__FreeBSD_version < 1100079)
u_int v_cache_min;
u_int v_cache_max;
#endif
};
#define KI_FD ki_fd
#define KI_PID ki_pid
@ -342,24 +405,21 @@ static int sigar_vmstat(sigar_t *sigar, vm_statistics_data_t *vmstat)
}
}
#elif defined(__FreeBSD__)
static int sigar_vmstat(sigar_t *sigar, struct vmmeter *vmstat)
static int sigar_vmstat(sigar_t *sigar, struct __vmmeter *vmstat)
{
int status;
size_t size = sizeof(unsigned int);
status = kread(sigar, vmstat, sizeof(*vmstat),
sigar->koffsets[KOFFSET_VMMETER]);
if (status == SIGAR_OK) {
return SIGAR_OK;
}
size_t size;
SIGAR_ZERO(vmstat);
/* derived from src/usr.bin/vmstat/vmstat.c */
/* only collect the ones we actually use */
#define GET_VM_STATS(cat, name, used) \
if (used) sysctlbyname("vm.stats." #cat "." #name, &vmstat->name, &size, NULL, 0)
#define GET_VM_STATS(cat, name, used) do { \
if (used) { \
size = sizeof(vmstat->name); \
sysctlbyname("vm.stats." #cat "." #name, &vmstat->name, \
&size, NULL, 0); \
} \
} while (0)
/* sys */
GET_VM_STATS(sys, v_swtch, 0);
@ -399,10 +459,12 @@ static int sigar_vmstat(sigar_t *sigar, struct vmmeter *vmstat)
GET_VM_STATS(vm, v_active_count, 0);
GET_VM_STATS(vm, v_inactive_target, 0);
GET_VM_STATS(vm, v_inactive_count, 1);
#if (__FreeBSD_version < 1200016 )
GET_VM_STATS(vm, v_cache_count, 1);
#if (__FreeBSD_version < 1100079)
GET_VM_STATS(vm, v_cache_min, 0);
GET_VM_STATS(vm, v_cache_max, 0);
#endif
#if (__FreeBSD_version < 1100079 )
GET_VM_STATS(vm, v_cache_min, 0);
GET_VM_STATS(vm, v_cache_max, 0);
#endif
GET_VM_STATS(vm, v_pageout_free_min, 0);
GET_VM_STATS(vm, v_interrupt_free_min, 0);
@ -442,7 +504,7 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
unsigned long mem_total;
#endif
#if defined(__FreeBSD__)
struct vmmeter vmstat;
struct __vmmeter vmstat;
#elif defined(__OpenBSD__) || defined(__NetBSD__)
struct uvmexp vmstat;
#endif
@ -481,7 +543,11 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
kern *= sigar->pagesize;
#elif defined(__FreeBSD__)
if ((status = sigar_vmstat(sigar, &vmstat)) == SIGAR_OK) {
#if (__FreeBSD_version < 1200016 )
kern = vmstat.v_cache_count + vmstat.v_inactive_count;
#else
kern = vmstat.v_inactive_count;
#endif
kern *= sigar->pagesize;
mem->free = vmstat.v_free_count;
mem->free *= sigar->pagesize;
@ -691,7 +757,7 @@ int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
swap->page_out = vmstat.pageouts;
#elif defined(__FreeBSD__)
struct kvm_swap kswap[1];
struct vmmeter vmstat;
struct __vmmeter vmstat;
if (getswapinfo_sysctl(kswap, 1) != SIGAR_OK) {
if (!sigar->kmem) {
@ -1899,7 +1965,7 @@ int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
free(ofiles);
#else
/* seems the same as the above */
procfd->total = filed.fd_lastfile;
procfd->total = filed.fd_nfiles;
#endif
return SIGAR_OK;
@ -3057,8 +3123,13 @@ static int net_connection_get(sigar_net_connection_walker_t *walker, int proto)
int type, istcp = 0;
char *buf;
const char *mibvar;
#if defined(__FreeBSD__) && (__FreeBSD_version >= 1200026)
struct xtcpcb *tp = NULL;
struct xinpcb *inp;
#else
struct tcpcb *tp = NULL;
struct inpcb *inp;
#endif
struct xinpgen *xig, *oxig;
struct xsocket *so;
size_t len;
@ -3096,6 +3167,15 @@ static int net_connection_get(sigar_net_connection_walker_t *walker, int proto)
xig->xig_len > sizeof(struct xinpgen);
xig = (struct xinpgen *)((char *)xig + xig->xig_len))
{
#if defined(__FreeBSD__) && (__FreeBSD_version >= 1200026)
if (istcp) {
tp = (struct xtcpcb *)xig;
inp = &tp->xt_inp;
} else {
inp = (struct xinpcb *)xig;
}
so = &inp->xi_socket;
#else
if (istcp) {
struct xtcpcb *cb = (struct xtcpcb *)xig;
tp = &cb->xt_tp;
@ -3107,6 +3187,7 @@ static int net_connection_get(sigar_net_connection_walker_t *walker, int proto)
inp = &cb->xi_inp;
so = &cb->xi_socket;
}
#endif
if (so->xso_protocol != proto) {
continue;
@ -3229,20 +3310,20 @@ sigar_tcp_get(sigar_t *sigar,
return SIGAR_OK;
}
#ifndef SIGAR_FREEBSD5_NFSSTAT
static int get_nfsstats(struct nfsstats *stats)
{
size_t len = sizeof(*stats);
int mib[] = { CTL_VFS, 2, NFS_NFSSTATS };
// #ifndef SIGAR_FREEBSD5_NFSSTAT
// static int get_nfsstats(struct nfsstats *stats)
// {
// size_t len = sizeof(*stats);
// int mib[] = { CTL_VFS, 2, NFS_NFSSTATS };
if (sysctl(mib, NMIB(mib), stats, &len, NULL, 0) < 0) {
return errno;
}
else {
return SIGAR_OK;
}
}
#endif
// if (sysctl(mib, NMIB(mib), stats, &len, NULL, 0) < 0) {
// return errno;
// }
// else {
// return SIGAR_OK;
// }
// }
// #endif
#if defined(__OpenBSD__)
typedef uint64_t rpc_cnt_t;
@ -3291,25 +3372,25 @@ int sigar_nfs_server_v2_get(sigar_t *sigar,
int sigar_nfs_client_v3_get(sigar_t *sigar,
sigar_nfs_client_v3_t *nfs)
{
#ifdef SIGAR_FREEBSD5_NFSSTAT
struct nfsstats stats;
size_t size = sizeof(stats);
// #ifdef SIGAR_FREEBSD5_NFSSTAT
// struct nfsstats stats;
// size_t size = sizeof(stats);
if (sysctlbyname("vfs.nfs.nfsstats", &stats, &size, NULL, 0) == -1) {
return errno;
}
// if (sysctlbyname("vfs.nfs.nfsstats", &stats, &size, NULL, 0) == -1) {
// return errno;
// }
map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.rpccnt[0]);
#else
int status;
struct nfsstats stats;
// map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.rpccnt[0]);
// #else
// int status;
// struct nfsstats stats;
if ((status = get_nfsstats(&stats)) != SIGAR_OK) {
return status;
}
// if ((status = get_nfsstats(&stats)) != SIGAR_OK) {
// return status;
// }
map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.rpccnt[0]);
#endif
// map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.rpccnt[0]);
// #endif
return SIGAR_OK;
}
@ -3317,25 +3398,25 @@ int sigar_nfs_client_v3_get(sigar_t *sigar,
int sigar_nfs_server_v3_get(sigar_t *sigar,
sigar_nfs_server_v3_t *nfs)
{
#ifdef SIGAR_FREEBSD5_NFSSTAT
struct nfsrvstats stats;
size_t size = sizeof(stats);
// #ifdef SIGAR_FREEBSD5_NFSSTAT
// struct nfsrvstats stats;
// size_t size = sizeof(stats);
if (sysctlbyname("vfs.nfsrv.nfsrvstats", &stats, &size, NULL, 0) == -1) {
return errno;
}
// if (sysctlbyname("vfs.nfsrv.nfsrvstats", &stats, &size, NULL, 0) == -1) {
// return errno;
// }
map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.srvrpccnt[0]);
#else
int status;
struct nfsstats stats;
// map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.srvrpccnt[0]);
// #else
// int status;
// struct nfsstats stats;
if ((status = get_nfsstats(&stats)) != SIGAR_OK) {
return status;
}
// if ((status = get_nfsstats(&stats)) != SIGAR_OK) {
// return status;
// }
map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.srvrpccnt[0]);
#endif
// map_nfs_stats((sigar_nfs_v3_t *)nfs, &stats.srvrpccnt[0]);
// #endif
return SIGAR_OK;
}

View File

@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <sys/times.h>
#include <sys/utsname.h>
#include <sys/sysmacros.h>
#include "sigar.h"
#include "sigar_private.h"
@ -50,6 +51,10 @@
#define PROC_PARTITIONS PROC_FS_ROOT "partitions"
#define PROC_DISKSTATS PROC_FS_ROOT "diskstats"
#ifndef HZ
#define HZ 100
#endif
/*
* /proc/self/stat fields:
* 1 - pid

View File

@ -70,7 +70,7 @@ struct sigar_t {
};
#define HAVE_STRERROR_R
#ifndef __USE_XOPEN2K
#if !defined(__USE_XOPEN2K) && defined(__GLIBC__)
/* use gnu version of strerror_r */
#define HAVE_STRERROR_R_GLIBC
#endif

View File

@ -30,6 +30,7 @@
#include <dirent.h>
#include <sys/stat.h>
#include <sys/time.h>
SIGAR_INLINE char *sigar_uitoa(char *buf, unsigned int n, int *len)
{

View File

@ -1,7 +1,7 @@
copyright.year=2004-2011
version.major=2
version.minor=0
version.maint=4
version.maint=11
version.build=0
project.name=kostya-sigar
project.author=Doug MacEachern