From 377a06db0de3850573f2a8e2c33152cf3483ea61 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 13 Feb 2023 22:35:54 +0100 Subject: Implement File Descriptor Meter support for OpenBSD --- openbsd/Platform.c | 26 ++++++++++++++++++++++++++ openbsd/Platform.h | 2 ++ 2 files changed, 28 insertions(+) (limited to 'openbsd') 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); -- cgit v1.2.3