Skip to content

Commit

Permalink
PCP: add File Descriptor Meter
Browse files Browse the repository at this point in the history
Related: #990

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
  • Loading branch information
smalinux committed May 4, 2022
1 parent 07fe4d1 commit d6506ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ endif
# --------------------------

pcp_platform_headers = \
FileDescriptorMeter.h \
linux/PressureStallMeter.h \
linux/ZramMeter.h \
linux/ZramStats.h \
Expand All @@ -390,6 +391,7 @@ pcp_platform_headers = \
zfs/ZfsCompressedArcMeter.h

pcp_platform_sources = \
FileDescriptorMeter.c \
linux/PressureStallMeter.c \
linux/ZramMeter.c \
pcp/PCPDynamicColumn.c \
Expand Down
2 changes: 2 additions & 0 deletions pcp/PCPMetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ typedef enum PCPMetric_ {
PCP_ZRAM_CAPACITY, /* zram.capacity */
PCP_ZRAM_ORIGINAL, /* zram.mm_stat.data_size.original */
PCP_ZRAM_COMPRESSED, /* zram.mm_stat.data_size.compressed */
PCP_VFS_FILES_COUNT, /* vfs.files.count */
PCP_VFS_FILES_MAX, /* vfs.files.max */

PCP_PROC_PID, /* proc.psinfo.pid */
PCP_PROC_PPID, /* proc.psinfo.ppid */
Expand Down
15 changes: 15 additions & 0 deletions pcp/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in the source distribution for its full text.
#include "DiskIOMeter.h"
#include "DynamicColumn.h"
#include "DynamicMeter.h"
#include "FileDescriptorMeter.h"
#include "HostnameMeter.h"
#include "LoadAverageMeter.h"
#include "Macros.h"
Expand Down Expand Up @@ -114,6 +115,7 @@ const MeterClass* const Platform_meterTypes[] = {
&DiskIOMeter_class,
&NetworkIOMeter_class,
&SysArchMeter_class,
&FileDescriptorMeter_class,
NULL
};

Expand Down Expand Up @@ -189,6 +191,8 @@ static const char* Platform_metricNames[] = {
[PCP_ZRAM_CAPACITY] = "zram.capacity",
[PCP_ZRAM_ORIGINAL] = "zram.mm_stat.data_size.original",
[PCP_ZRAM_COMPRESSED] = "zram.mm_stat.data_size.compressed",
[PCP_VFS_FILES_COUNT] = "vfs.files.count",
[PCP_VFS_FILES_MAX] = "vfs.files.max",

[PCP_PROC_PID] = "proc.psinfo.pid",
[PCP_PROC_PPID] = "proc.psinfo.ppid",
Expand Down Expand Up @@ -699,6 +703,17 @@ bool Platform_getNetworkIO(NetworkIOData* data) {
return true;
}

void Platform_getFileDescriptors(double* used, double* max) {
*used = NAN;
*max = NAN;

pmAtomValue value;
if (PCPMetric_values(PCP_VFS_FILES_COUNT, &value, 1, PM_TYPE_32) != NULL)
*used = value.l;
if (PCPMetric_values(PCP_VFS_FILES_MAX, &value, 1, PM_TYPE_32) != NULL)
*max = value.l;
}

void Platform_getBattery(double* level, ACPresence* isOnAC) {
*level = NAN;
*isOnAC = AC_ERROR;
Expand Down
2 changes: 2 additions & 0 deletions pcp/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ extern pmOptions opts;

size_t Platform_addMetric(PCPMetric id, const char* name);

void Platform_getFileDescriptors(double* used, double* max);

void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec);

void Platform_gettime_monotonic(uint64_t* msec);
Expand Down

0 comments on commit d6506ad

Please sign in to comment.