Skip to content

Commit

Permalink
New specs var_log_pcp_openmetrics_log (#3596)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohit Kumar <[email protected]>
  • Loading branch information
mohitkumarrh authored Nov 22, 2022
1 parent ffeb412 commit 04ddde3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/pcp_openmetrics_log.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.pcp_openmetrics_log
:members:
:show-inheritance:
32 changes: 32 additions & 0 deletions insights/parsers/pcp_openmetrics_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
PcpOpenmetricsLog - file ``/var/log/pcp/pmcd/openmetrics.log``
--------------------------------------------------------------
"""
from insights.specs import Specs
from insights import LogFileOutput, parser


@parser(Specs.pcp_openmetrics_log)
class PcpOpenmetricsLog(LogFileOutput):
"""
Parse the ``/var/log/pcp/pmcd/openmetrics.log`` log file.
.. note::
Please refer to its super-class :class:`insights.core.LogFileOutput`
Sample input::
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 55% {:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 95% {:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store };:
Examples:
>>> "Error: cannot parse/store" in log
True
>>> len(log.get('pmdaopenmetrics')) == 5
True
"""
pass
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ class Specs(SpecSet):
password_auth = RegistryPoint()
pci_rport_target_disk_paths = RegistryPoint()
pcp_metrics = RegistryPoint()
pcp_openmetrics_log = RegistryPoint(filterable=True)
pcs_config = RegistryPoint()
pcs_quorum_status = RegistryPoint()
pcs_status = RegistryPoint()
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class DefaultSpecs(Specs):
password_auth = simple_file("/etc/pam.d/password-auth")
pci_rport_target_disk_paths = simple_command("/usr/bin/find /sys/devices/ -maxdepth 10 -mindepth 9 -name stat -type f")
pcp_metrics = simple_command("/usr/bin/curl -s http://127.0.0.1:44322/metrics --connect-timeout 5", deps=[pcp_enabled])
pcp_openmetrics_log = simple_file("/var/log/pcp/pmcd/openmetrics.log")
pcs_quorum_status = simple_command("/usr/sbin/pcs quorum status")
pcs_status = simple_command("/usr/sbin/pcs status")
php_ini = first_file(["/etc/opt/rh/php73/php.ini", "/etc/opt/rh/php72/php.ini", "/etc/php.ini"])
Expand Down
26 changes: 26 additions & 0 deletions insights/tests/parsers/test_pcp_openmetrics_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import doctest
from insights.parsers import pcp_openmetrics_log
from insights.tests import context_wrap


PCP_OPENMETRICS_LOG = """
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 55% {:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store 95% {:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store }:
[Mon Jul 11 07:59:32] pmdaopenmetrics(1733) Error: cannot parse/store };:
""".strip()


def test_pcp_openmetrics_log():
log = pcp_openmetrics_log.PcpOpenmetricsLog(context_wrap(PCP_OPENMETRICS_LOG))
assert "Error: cannot parse/store" in log
assert len(log.get('pmdaopenmetrics')) == 5


def test_documentation():
failed_count, tests = doctest.testmod(
pcp_openmetrics_log,
globs={'log': pcp_openmetrics_log.PcpOpenmetricsLog(context_wrap(PCP_OPENMETRICS_LOG))}
)
assert failed_count == 0

0 comments on commit 04ddde3

Please sign in to comment.