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

Introduce the DynamicMeter class for runtime extension #669

Merged
merged 7 commits into from
Jul 8, 2021

Conversation

natoscott
Copy link
Member

This commit is based on exploratory work by Sohaib Mohamed.

The end goal is two-fold - to support addition of Meters we
build via configuration files for both the PCP platform and
for scripts ( #526 )

Here, we focus on generic code and the PCP support. A new
class DynamicMeter is introduced - its use the special case
'param' field handling that previously was used only by the
CPUMeter, such that every runtime-configured Meter is given
a unique identifier. Unlike with the CPUMeter this is used
internally only. When reading/writing to htoprc instead of
CPU(N) - where N is an integer param (CPU number) - we use
the string name for each meter. For example, if we have a
configuration for a DynamicMeter for some Redis metrics, we
might read and write "Dynamic(redis)". This identifier is
subsequently matched (back) up to the configuration file so
we're able to re-create arbitrary user configurations.

The PCP platform configuration file format is fairly simple.
We expand configs from several directories, including the
users homedir alongside htoprc (below htop/meters/) and also
/etc/pcp/htop/meters. The format will be described via a
new pcp-htop(5) man page, but its basically ini-style and
each Meter has one or more metric expressions associated, as
well as specifications for labels, color and so on via a dot
separated notation for individual metrics within the Meter.

A few initial sample configuration files are provided below
./pcp/meters that give the general idea. The PCP "derived"
metric specification - see pmRegisterDerived(3) - is used
as the syntax for specifying metrics in PCP DynamicMeters.

AvailableMetersPanel.c Outdated Show resolved Hide resolved
DynamicMeter.c Show resolved Hide resolved
DynamicMeter.c Show resolved Hide resolved
DynamicMeter.c Outdated Show resolved Hide resolved
DynamicMeter.c Outdated Show resolved Hide resolved
DynamicMeter.h Outdated Show resolved Hide resolved
AvailableMetersPanel.c Show resolved Hide resolved
@natoscott natoscott added new feature Completely new feature PCP PCP related issues labels Jun 23, 2021
pcp/PCPDynamicMeter.c Outdated Show resolved Hide resolved
@natoscott natoscott force-pushed the dynamic-meters branch 2 times, most recently from 0c8655e to 452683d Compare June 25, 2021 05:31
Copy link
Member

@BenBE BenBE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local changes pending upload; have fixes for some of those locally already.

DynamicMeter.h Show resolved Hide resolved
pcp/PCPDynamicMeter.c Outdated Show resolved Hide resolved
pcp/PCPDynamicMeter.h Show resolved Hide resolved
pcp/PCPDynamicMeter.c Outdated Show resolved Hide resolved
natoscott and others added 6 commits July 7, 2021 10:59
When manipulating CPUMeters in the AvailableMeterPanel we
use the bottom 16 bits to hold the CPU number.  However,
the bitmask used to extract the CPU number only masks the
lower 8 bits (0xff).
This commit is based on exploratory work by Sohaib Mohamed.
The end goal is two-fold - to support addition of Meters we
build via configuration files for both the PCP platform and
for scripts ( htop-dev#526 )

Here, we focus on generic code and the PCP support.  A new
class DynamicMeter is introduced - it uses the special case
'param' field handling that previously was used only by the
CPUMeter, such that every runtime-configured Meter is given
a unique identifier.  Unlike with the CPUMeter this is used
internally only.  When reading/writing to htoprc instead of
CPU(N) - where N is an integer param (CPU number) - we use
the string name for each meter.  For example, if we have a
configuration for a DynamicMeter for some Redis metrics, we
might read and write "Dynamic(redis)".  This identifier is
subsequently matched (back) up to the configuration file so
we're able to re-create arbitrary user configurations.

The PCP platform configuration file format is fairly simple.
We expand configs from several directories, including the
users homedir alongside htoprc (below htop/meters/) and also
/etc/pcp/htop/meters.  The format will be described via a
new pcp-htop(5) man page, but its basically ini-style and
each Meter has one or more metric expressions associated, as
well as specifications for labels, color and so on via a dot
separated notation for individual metrics within the Meter.

A few initial sample configuration files are provided below
./pcp/meters that give the general idea.  The PCP "derived"
metric specification - see pmRegisterDerived(3) - is used
as the syntax for specifying metrics in PCP DynamicMeters.
Instead use the common NAN pattern to use of the swap
cached value on platforms that do not support it.
@natoscott natoscott force-pushed the dynamic-meters branch 2 times, most recently from 3ab45aa to 6625bbc Compare July 7, 2021 06:59
pcp/PCPDynamicMeter.c Outdated Show resolved Hide resolved
pcp/PCPDynamicMeter.c Outdated Show resolved Hide resolved
pcp/PCPDynamicMeter.c Outdated Show resolved Hide resolved
Several improvements to the way values are displayed in the
PCP platform DynamicMeter implementation:
- handle the initial 'caption' setting as with regular meters,
  this required a new meter callback because we no longer have
  just a single meter caption for the DynamicMeter case
- if no label is provided for a metric in a configuration file
  use the short form metric name as a fallback
- honour the suffix setting in the configuration file
- convert metric values to the canonical units for htop (kbyte
  and seconds), and use Meter_humanUnit when it makes sense to
  do so.

Also improves the handling of fatal string error messages in a
couple of places, thanks to BenBE for the review feedback.
@natoscott natoscott merged commit 01f5b89 into htop-dev:master Jul 8, 2021
@natoscott natoscott deleted the dynamic-meters branch July 8, 2021 06:36
smalinux added a commit to smalinux/htop that referenced this pull request Jul 17, 2021
Merged, see: htop-dev#669

Allowing any metric to be displayed using htop rather than only the hard-coded set.

One of the challenges we have with making pcp and htop work well together, is
that pcp has thousands of metrics.
And we encourage people to add their own metrics, so really its infinite metrics
htop on the other hand has knowledge of a fixed set of metrics, and
it cannot be extended yet without writing new code.

What I did here is a generic Meter for any PCP metric.
- i.e. not the way we're doing it currently, where we write new code each
time we want to add a new Meter into htop.
so, instead of writing code, imagine this...
pcp-htop scans a new direcory /etc/pcp/htop/ at startup for
configuration files (plain text)
These files would specify new Meters - they would contain information
like: pcp metric name, meter name, etc and they would be added into the
existing set of meters that htop knows about, at startup.

So most importantly, users would not have to add code for new Meters anymore.
It also means the tool doesn't become larger and larger forever,
as more and more people write their own Meters for their own critical metrics.
(i.e. less code bloat)
smalinux added a commit to smalinux/htop that referenced this pull request Sep 11, 2022
htop-dev#669)

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 11, 2022
…v#669)

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 11, 2022
…v#669)

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 11, 2022
…v#669)

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 11, 2022
…v#669)

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 11, 2022
…v#669)

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 12, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 12, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 12, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 12, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 13, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 15, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
smalinux added a commit to smalinux/htop that referenced this pull request Sep 15, 2022
Related: htop-dev#200 && htop-dev#669

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Completely new feature PCP PCP related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants