diff options
author | Benny Baumann <BenBE@geshi.org> | 2023-02-13 22:35:54 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2023-02-19 17:56:50 +0100 |
commit | 377a06db0de3850573f2a8e2c33152cf3483ea61 (patch) | |
tree | b9ad49f01f496caadbe70a16b3cb34674c4d7da7 | |
parent | bdb63a497beeb4b317296ca123c507233a2af889 (diff) |
Implement File Descriptor Meter support for OpenBSD
-rw-r--r-- | openbsd/Platform.c | 26 | ||||
-rw-r--r-- | openbsd/Platform.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 1ce5ba19..71419f8e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -28,6 +28,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "DateMeter.h" #include "DateTimeMeter.h" +#include "FileDescriptorMeter.h" #include "HostnameMeter.h" #include "LoadAverageMeter.h" #include "Macros.h" @@ -125,6 +126,7 @@ const MeterClass* const Platform_meterTypes[] = { &RightCPUs4Meter_class, &LeftCPUs8Meter_class, &RightCPUs8Meter_class, + &FileDescriptorMeter_class, &BlankMeter_class, NULL }; @@ -301,6 +303,30 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { return NULL; } +void Platform_getFileDescriptors(double* used, double* max) { + static const int mib_kern_maxfile[] = { CTL_KERN, KERN_MAXFILES }; + int sysctl_maxfile = 0; + size_t size_maxfile = sizeof(int); + if (sysctl(mib_kern_maxfile, ARRAYSIZE(mib_kern_maxfile), &sysctl_maxfile, &size_maxfile, NULL, 0) < 0) { + *max = NAN; + } else if (size_maxfile != sizeof(int) || sysctl_maxfile < 1) { + *max = NAN; + } else { + *max = sysctl_maxfile; + } + + static const int mib_kern_nfiles[] = { CTL_KERN, KERN_NFILES }; + int sysctl_nfiles = 0; + size_t size_nfiles = sizeof(int); + if (sysctl(mib_kern_nfiles, ARRAYSIZE(mib_kern_nfiles), &sysctl_nfiles, &size_nfiles, NULL, 0) < 0) { + *used = NAN; + } else if (size_nfiles != sizeof(int) || sysctl_nfiles < 0) { + *used = NAN; + } else { + *used = sysctl_nfiles; + } +} + bool Platform_getDiskIO(DiskIOData* data) { // TODO (void)data; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 27d792e0..f357006c 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -59,6 +59,8 @@ char* Platform_getProcessEnv(pid_t pid); FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); +void Platform_getFileDescriptors(double* used, double* max); + bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(NetworkIOData* data); |