summaryrefslogtreecommitdiffstats
path: root/openbsd/Platform.c
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2023-02-13 22:35:54 +0100
committercgzones <cgzones@googlemail.com>2023-02-19 17:56:50 +0100
commit377a06db0de3850573f2a8e2c33152cf3483ea61 (patch)
treeb9ad49f01f496caadbe70a16b3cb34674c4d7da7 /openbsd/Platform.c
parentbdb63a497beeb4b317296ca123c507233a2af889 (diff)
Implement File Descriptor Meter support for OpenBSD
Diffstat (limited to 'openbsd/Platform.c')
-rw-r--r--openbsd/Platform.c26
1 files changed, 26 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;

© 2014-2024 Faster IT GmbH | imprint | privacy policy