Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pcp-meminfo: initial commit of PCP implementation of meminfo #1769

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/rpm/pcp.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@ basic_manifest | grep -E -e 'pmiostat|pmrep|dstat|htop|pcp2csv' \
-e 'pcp-atop|pcp-dmcache|pcp-dstat|pcp-free|pcp-htop' \
-e 'pcp-ipcs|pcp-iostat|pcp-lvmcache|pcp-mpstat' \
-e 'pcp-numastat|pcp-pidstat|pcp-shping|pcp-tapestat' \
-e 'pcp-uptime|pcp-verify|pcp-ss|pcp-ps' | \
-e 'pcp-uptime|pcp-verify|pcp-ss|pcp-ps|pcp-meminfo' | \
cull 'selinux|pmlogconf|pmieconf|pmrepconf' >pcp-system-tools-files
basic_manifest | keep 'sar2pcp' >pcp-import-sar2pcp-files
basic_manifest | keep 'iostat2pcp' >pcp-import-iostat2pcp-files
Expand Down
2 changes: 1 addition & 1 deletion build/rpm/redhat.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ basic_manifest | grep -E -e 'pmiostat|pmrep|dstat|htop|pcp2csv' \
-e 'pcp-atop|pcp-dmcache|pcp-dstat|pcp-free|pcp-htop' \
-e 'pcp-ipcs|pcp-iostat|pcp-lvmcache|pcp-mpstat' \
-e 'pcp-numastat|pcp-pidstat|pcp-shping|pcp-tapestat' \
-e 'pcp-uptime|pcp-verify|pcp-ss|pcp-ps' | \
-e 'pcp-uptime|pcp-verify|pcp-ss|pcp-ps|pcp-meminfo' | \
cull 'selinux|pmlogconf|pmieconf|pmrepconf' >pcp-system-tools-files

basic_manifest | keep 'sar2pcp' >pcp-import-sar2pcp-files
Expand Down
1 change: 1 addition & 0 deletions src/pcp/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SUBDIRS = \
iostat \
ipcs \
mpstat \
meminfo \
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
numastat \
pidstat \
ps \
Expand Down
44 changes: 44 additions & 0 deletions src/pcp/meminfo/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Copyright (c) 2023 Oracle and/or its affiliates.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#

TOPDIR = ../../..
include $(TOPDIR)/src/include/builddefs

TARGET = pcp-meminfo
SCRIPT = $(TARGET).py
MAN_SECTION = 1
MAN_PAGES = $(TARGET).$(MAN_SECTION)
MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION)

default: $(SCRIPT) $(MAN_PAGES)

include $(BUILDRULES)

install: default
ifeq "$(HAVE_PYTHON)" "true"
$(INSTALL) -m 755 $(SCRIPT) $(PCP_BINADM_DIR)/$(TARGET)
@$(INSTALL_MAN)
endif

default_pcp : default

install_pcp : install

check:: $(SCRIPT)
$(PYLINT) $^

check :: $(MAN_PAGES)
$(MANLINT) $^

77 changes: 77 additions & 0 deletions src/pcp/meminfo/pcp-meminfo.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'\"! tbl | mmdoc
'\"macro stdmacro
.\"
.\" Copyright (c) 2023 Oracle and/or its affiliates.
.\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
.\"
.\" This program is free software; you can redistribute it and/or modify it
.\" under the terms of the GNU General Public License as published by the
.\" Free Software Foundation; either version 2 of the License, or (at your
.\" option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful, but
.\" WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
.\" or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
.\" for more details.
.\"
.TH PCP-MEMINFO 1 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pcp-meminfo\f1 \- Report statistics for System Memory.
.SH SYNOPSIS
\f3pcp\f1
[\f2pcp\ options\f1]
\f3meminfo\f1
[\f3\-s\f1 \f2samples\f1]
[\f3\-a\f1 \f2archive\f1]
[\f3\-S\f1 \f2start_time\f1]
[\f3\-T\f1 \f2end_time\f1]
.SH DESCRIPTION
The
.B pcp-meminfo
command is used for viewing the different kinds of stats related to memory.
Using various options it helps a user to analyze useful information related to
the memory availability.
This information includes total memory, memory available, shared memory, etc.
By default
.B pcp-meminfo
reports live data for the local host.
.SH OPTIONS
.TP
\fB\-a\fP, \fB\-\-archive\fP
Fetch /proc/meminfo for a specified archive file
.TP
\fB\-s\fP, \fB\-\-samples\fP
Get the meminfo for specified number of samples count
.TP
\fB\-S\fP, \fB\-\-START TIME\fP
Filter the samples from the archive from the given time
.TP
\fB\-T\fP, \fB\-\-END TIME\fP
Filter the samples from the archive till the given time
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version number and exit.
.TP
\fB\-?\fR, \fB\-\-help\fR
Display usage message and exit.
.SH NOTES
.B pcp-meminfo
collects information from
.BR /proc/meminfo
and aims to be command line and output compatible with it.
.SH PCP ENVIRONMENT
Environment variables with the prefix \fBPCP_\fP are used to parameterize
the file and directory names used by PCP.
On each installation, the
file \fI/etc/pcp.conf\fP contains the local values for these variables.
The \fB$PCP_CONF\fP variable may be used to specify an alternative
configuration file, as described in \fBpcp.conf\fP(5).
.PP
For environment variables affecting PCP tools, see \fBpmGetOptions\fP(3).
.SH SEE ALSO
.BR PCPIntro (1),
.BR pcp (1),
.BR pmParseInterval (3)
and
.BR environ (7).

211 changes: 211 additions & 0 deletions src/pcp/meminfo/pcp-meminfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
#!/usr/bin/env pmpython
#
# Copyright (c) 2023 Oracle and/or its affiliates.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# pylint: disable=bad-whitespace,too-many-arguments,too-many-lines, bad-continuation
# pylint: disable=redefined-outer-name,unnecessary-lambda
#

import sys
import time
from pcp import pmapi
from pcp import pmcc
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
from cpmapi import PM_CONTEXT_ARCHIVE

METRICS = ["mem.physmem",
"mem.util.free",
"mem.util.available",
"mem.util.bufmem",
"mem.util.cached"
"mem.util.swapCached",
"mem.util.active",
"mem.util.inactive",
"mem.util.active_anon",
"mem.util.inactive_anon",
"mem.util.active_file",
"mem.util.inactive_file",
"mem.util.unevictable",
"mem.util.mlocked",
"mem.util.swapTotal",
"mem.util.swapFree",
"mem.util.dirty",
"mem.util.writeback",
"mem.util.anonpages",
"mem.util.mapped",
"mem.util.shared",
"mem.util.slab",
"mem.util.slabReclaimable",
"mem.util.slabUnreclaimable",
"mem.util.kernelStack",
"mem.util.pageTables",
"mem.util.NFS_Unstable",
"mem.util.bounce",
"mem.vmstat.nr_writeback_temp",
"mem.util.commitLimit",
"mem.util.committed_AS",
"mem.util.vmallocTotal",
"mem.util.vmallocUsed",
"mem.util.vmallocChunk",
"mem.util.corrupthardware",
"mem.util.anonhugepages",
"mem.vmstat.nr_shmem_hugepages",
"mem.vmstat.nr_shmem_pmdmapped",
"mem.zoneinfo.nr_free_cma",
"mem.util.hugepagesTotal",
"mem.util.hugepagesFree",
"mem.util.hugepagesRsvd",
"mem.util.hugepagesSurp",
"hinv.hugepagesize",
"mem.util.directMap4k",
"mem.util.directMap2M",
"mem.util.directMap1G"]

METRICS_DESC = ["MemTotal",
"MemFree",
"MemAvailable",
"Buffers",
"Cached",
"SwapCached",
"Active",
"Inactive",
"Active(anon)",
"Inactive(anon)",
"Active(file)",
"Inactive(file)",
"Unevictable",
"Mlocked",
"SwapTotal",
"SwapFree",
"Dirty",
"Writeback",
"AnonPages",
"Mapped",
"Shmem",
"Slab",
"SReclaimable",
"SUnreclaim",
"KernelStack",
"PageTables",
"NFS_Unstable",
"Bounce",
"WritebackTmp",
"CommitLimit",
"Committed_AS",
"VmallocTotal",
"VmallocUsed",
"VmallocChunk",
"HardwareCorrupted",
"AnonHugePages",
"ShmemHugePages",
"ShmemPmdMapped",
"CmaFree",
"HugePages_Total_NO_kb",
"HugePages_Free_NO_kb",
"HugePages_Rsvd_NO_kb",
"HugePages_Surp_NO_kb",
"Hugepagesize",
"DirectMap4k",
"DirectMap2M",
"DirectMap1G"]

class MeminfoReport(pmcc.MetricGroupPrinter):

def getMetricName(self, idx):
metric_name = ""
units = ""
if METRICS_DESC[idx][-6:] == "_NO_kb":
metric_name = METRICS_DESC[idx][:-6]
else:
metric_name = METRICS_DESC[idx]
units = "kB"
return metric_name, units

def report(self, manager):
group = manager["meminfo"]
t_s = group.contextCache.pmLocaltime(int(group.timestamp))
time_string = time.strftime(MeminfoOptions.timefmt, t_s.struct_time())
print(time_string)

if MeminfoOptions.samples == 0 and MeminfoOptions.context is PM_CONTEXT_ARCHIVE:
MeminfoOptions.samples = sys.maxsize

idx = 0
for metric in METRICS:
try:
val = group[metric].netValues[0][2]
except IndexError:
metric_name, units = self.getMetricName(idx)
print(F"{metric_name:17} : NA")

idx += 1
continue

metric_name, units = self.getMetricName(idx)
print(F"{metric_name:17} : {val} {units}")

idx += 1
print()

MeminfoOptions.samples -= 1

if MeminfoOptions.samples <= 0:
sys.exit(0)

class MeminfoOptions(pmapi.pmOptions):
context = None
timefmt = "%H:%M:%S"
samples = 0

def __init__(self):
pmapi.pmOptions.__init__(self, "a:s:S:T:z:P:A:R:t:T:x:")
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
self.pmSetLongOption("archive", 1, "a", "FILENAME","Fetch /proc/meminfo for a specified archive file")
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
self.pmSetLongOption("samples", 1, "s", "count","Get the meminfo for specified number of samples count")
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
self.pmSetLongOption("start_time", 1, "S", "TIME","Filter the samples from the archive from the given time")
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
self.pmSetLongOption("end_time", 1, "T", "TIME","Filter the samples from the archive till the given time")
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
self.pmSetOptionCallback(self.options)
self.pmSetOverrideCallback(self.override)
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
self.pmSetLongOptionHelp()

def override(self, opt):
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved
if opt == 's':
return 1
return 0

def options(self,opt,optarg,index):
if opt == 's':
MeminfoOptions.samples = int(optarg)
mohith-kumar-thummaluru marked this conversation as resolved.
Show resolved Hide resolved

if __name__ == '__main__':
try:
opts = MeminfoOptions()
mngr = pmcc.MetricGroupManager.builder(opts,sys.argv)
MeminfoOptions.context = mngr.type

missing = mngr.checkMissingMetrics(METRICS)
if missing is not None:
sys.stderr.write(F"Error:Metric is {missing} missing\n")
sys.exit(1)

mngr["meminfo"] = METRICS
mngr.printer = MeminfoReport()
sts = mngr.run()
sys.exit(sts)

except pmapi.pmErr as error:
sys.stderr.write(F"{error.progname()} {error.message()}")
except pmapi.pmUsageErr as usage:
usage.message()
sys.exit(1)
except KeyboardInterrupt:
pass
Loading