summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2023-02-13 22:42:42 +0100
committercgzones <cgzones@googlemail.com>2023-02-19 17:56:50 +0100
commit62f4628efef67280c7c480dcd5df65867bd4d960 (patch)
treea69be694920bde5dcb24df5103635a9af5fa3e0c
parent3519b383c705de6c41bdec7b87367d5e3c88ec02 (diff)
Implement File Descriptor Meter support for Linux
-rw-r--r--linux/Platform.c20
-rw-r--r--linux/Platform.h2
2 files changed, 22 insertions, 0 deletions
diff --git a/linux/Platform.c b/linux/Platform.c
index 911284e9..005d8316 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -31,6 +31,7 @@ in the source distribution for its full text.
#include "DateMeter.h"
#include "DateTimeMeter.h"
#include "DiskIOMeter.h"
+#include "FileDescriptorMeter.h"
#include "HostnameMeter.h"
#include "HugePageMeter.h"
#include "LoadAverageMeter.h"
@@ -250,6 +251,7 @@ const MeterClass* const Platform_meterTypes[] = {
&SELinuxMeter_class,
&SystemdMeter_class,
&SystemdUserMeter_class,
+ &FileDescriptorMeter_class,
NULL
};
@@ -538,6 +540,24 @@ void Platform_getPressureStall(const char* file, bool some, double* ten, double*
fclose(fd);
}
+void Platform_getFileDescriptors(double* used, double* max) {
+ *used = NAN;
+ *max = 65536;
+
+ FILE* fd = fopen(PROCDIR "/sys/fs/file-nr", "r");
+ if (!fd)
+ return;
+
+ unsigned long long v1, v2, v3;
+ int total = fscanf(fd, "%llu %llu %llu", &v1, &v2, &v3);
+ if (total == 3) {
+ *used = v1;
+ *max = v3;
+ }
+
+ fclose(fd);
+}
+
bool Platform_getDiskIO(DiskIOData* data) {
FILE* fd = fopen(PROCDIR "/diskstats", "r");
if (!fd)
diff --git a/linux/Platform.h b/linux/Platform.h
index f6ac1880..1621d562 100644
--- a/linux/Platform.h
+++ b/linux/Platform.h
@@ -79,6 +79,8 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred);
+void Platform_getFileDescriptors(double* used, double* max);
+
bool Platform_getDiskIO(DiskIOData* data);
bool Platform_getNetworkIO(NetworkIOData* data);

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