Merge ~al3jandrosg/charm-telegraf:LP1976521 into charm-telegraf:master

Proposed by Alejandro Santoyo Gonzalez
Status: Needs review
Proposed branch: ~al3jandrosg/charm-telegraf:LP1976521
Merge into: charm-telegraf:master
Diff against target: 307 lines (+216/-0)
4 files modified
src/config.yaml (+28/-0)
src/reactive/telegraf.py (+144/-0)
src/templates/base_inputs.conf (+12/-0)
src/tests/unit/test_telegraf.py (+32/-0)
Reviewer Review Type Date Requested Status
BootStack Reviewers Pending
BootStack Reviewers Pending
Review via email: mp+460245@code.launchpad.net

Commit message

Adding support for intel_powerstat

This patch adds support for intel_powerstat by:

- fixing the permissions issues when attempting to read
`/sys/devices/virtual/powercap/intel-rapl/`
- adding charm configs: `collect_intel_powerstat_metrics`,
`package_metrics`, `cpu_metrics`

Fixes [LP#1976521](https://bugs.launchpad.net/charm-telegraf/+bug/1976521)

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Alejandro Santoyo Gonzalez (al3jandrosg) wrote :

Lint tests failing but that has nothing to do with the patch:

Lint tests without patch applied:

~/MyData/Projects/charm-telegraf-lp-fork$ make lint
Running lint checks
lint: install_deps> python -I -m pip install black colorama flake8 flake8-colors flake8-docstrings isort pep8-naming pyproject-flake8
lint: commands[0]> pflake8
lint: commands[1]> black --check --diff --color .
--- /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src/tests/unit/test_telegraf.py 2024-02-08 12:03:03.378682+00:00
+++ /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src/tests/unit/test_telegraf.py 2024-02-08 12:08:34.248687+00:00
@@ -1736,12 +1736,11 @@
         mock_nrpe.assert_has_calls(calls)

 class TestGrafanaDashboard:
     @patch("reactive.telegraf.endpoint_from_flag")
- def test_register_grafana_dashboard_n(self, mock_endpoint_from_flag):
- ...
+ def test_register_grafana_dashboard_n(self, mock_endpoint_from_flag): ...

     @patch("reactive.telegraf.render_custom")
     @patch("reactive.telegraf.endpoint_from_flag")
     @patch("reactive.telegraf.hookenv")
     @patch("reactive.telegraf.json")
would reformat /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src/tests/unit/test_telegraf.py

Oh no! 💥 💔 💥
1 file would be reformatted, 15 files would be left unchanged.
lint: exit 1 (0.81 seconds) /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src> black --check --diff --color . pid=2237953
  lint: FAIL code 1 (3.60=setup[2.39]+cmd[0.40,0.81] seconds)
  evaluation failed :( (3.66 seconds)
make: *** [Makefile:75: lint] Error 1

after the patch was applied:

alejandro@alejandropc:~/MyData/Projects/charm-telegraf-lp-fork$ make lint
Running lint checks
lint: commands[0]> pflake8
lint: commands[1]> black --check --diff --color .
--- /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src/tests/unit/test_telegraf.py 2024-02-08 12:12:45.928446+00:00
+++ /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src/tests/unit/test_telegraf.py 2024-02-08 12:14:23.682646+00:00
@@ -1736,12 +1736,11 @@
         mock_nrpe.assert_has_calls(calls)

 class TestGrafanaDashboard:
     @patch("reactive.telegraf.endpoint_from_flag")
- def test_register_grafana_dashboard_n(self, mock_endpoint_from_flag):
- ...
+ def test_register_grafana_dashboard_n(self, mock_endpoint_from_flag): ...

     @patch("reactive.telegraf.render_custom")
     @patch("reactive.telegraf.endpoint_from_flag")
     @patch("reactive.telegraf.hookenv")
     @patch("reactive.telegraf.json")
would reformat /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src/tests/unit/test_telegraf.py

Oh no! 💥 💔 💥
1 file would be reformatted, 15 files would be left unchanged.
lint: exit 1 (0.83 seconds) /home/alejandro/MyData/Projects/charm-telegraf-lp-fork/src> black --check --diff --color . pid=2238896
  lint: FAIL code 1 (1.26=setup[0.03]+cmd[0.41,0.83] seconds)
  evaluation failed :( (1.30 seconds)
make: *** [Makefile:75: lint] Error 1

Revision history for this message
Alejandro Santoyo Gonzalez (al3jandrosg) wrote (last edit ):

Lots of func test issues due to charmcraft problems. Eventually
managed to get that going and the Zaza model deployed
correctly with the below versioning on a Focal host:

sudo apt update; sudo snap refresh lxd --channel=5.0/stable; mkdir -p ~/.local/share/juju
sudo snap install juju --channel=3.1/stable --classic
juju bootstrap localhost controller; juju add-model test

sudo snap install charmcraft --channel=2.0/stable --classic
sudo apt install -y make tox

git clone https://git.launchpad.net/charm-telegraf; cd charm-telegraf
make functional

However, this now fails as neutron-gateway is unable to start
because of the below:

Feb 8 10:37:22 juju-32f109-7 ovs-ctl[9436]: modprobe: FATAL: Module openvswitch not found in directory /lib/modules/5.4.0-169-generic

However, this is not related to the patch (the steps above
fail with the out-of-the-box charm), hence why I submitted
it as is. I did check that the patch was working, i.e.,
permissions changed correctly, charm config options doing
their job.

Revision history for this message
Robert Gildein (rgildein) wrote :

In general, it looks fine to me, but I would really like to see more unit tests,
since we do not have proper func either.

Revision history for this message
Chi Wai CHAN (raychan96) wrote :

It might be related to the environment (lxd cloud) not your patch, because telegraf charm functional test requires openstack related charms, and that may not work well on container. We will try it from our side with VMs. Or if you could use VMs, you can also try it again without waiting for us.

Revision history for this message
Chi Wai CHAN (raychan96) wrote :

I've tested your patch in our environment with VMs, it doesn't have the issue you mentioned in your functional test. https://pastebin.ubuntu.com/p/5CZ79Q3rJ5/ (note you will need an Ubuntu account to view the pastebin).

The charm is in maintenance mode, so you should build and test the charm with the following setup at least (though there might be some other versions still work, I did not test it thoroughly):

```
juju 3.1.7 25751 3.1/stable canonical✓ -
charmcraft 2.0.0 1033 2.0/stable canonical✓ classic
```

and a juju controller at version 3.1.7

Revision history for this message
Alejandro Santoyo Gonzalez (al3jandrosg) wrote :

Using the recommended versioning but the deployment (with the unchanged charm-telegraf repo, no patch added yet) fails as the charm cannot install:

```
charm 3.0.6 712 latest/stable canonical** classic
charmcraft 2.0.0 1033 2.0/stable canonical** classic
juju 3.1.7 25751 3.1/stable canonical** -
```
status:

Unit Workload Agent Machine Public address Ports Message
ubuntu/0* active idle 0 10.5.1.103
  telegraf/0* error idle 10.5.1.103 hook failed: "install"

I'm facing lots of dependency errors. First it complains about:

2024-03-25 15:14:18 WARNING unit.telegraf/0.install logger.go:60 ERROR: Could not find a version that satisfies the requirement setuptools>=42 (from versions: 41.6.0)

I will upload the unit log.

This is unfortunately taking quite a bit of time. Is the automated/repo func testing going to be fixed any time soon?

Revision history for this message
Alejandro Santoyo Gonzalez (al3jandrosg) wrote :
Download full text (3.7 KiB)

2024-03-25 15:17:39 INFO juju.worker.uniter resolver.go:161 awaiting error resolution for "install" hook
2024-03-25 15:21:41 INFO juju.worker.uniter resolver.go:161 awaiting error resolution for "install" hook
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 ERROR: Command errored out with exit status 1:
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 command: /var/lib/juju/agents/unit-telegraf-0/.venv/bin/python /var/lib/juju/agents/unit-telegraf-0/.venv/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-y9wnzkmz/overlay --no-warn-script-location --no-binary :none: --only-binary :none: --no-index --find-links wheelhouse -- 'setuptools>=42' wheel
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 cwd: None
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 Complete output (3 lines):
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 Looking in links: wheelhouse
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 ERROR: Could not find a version that satisfies the requirement setuptools>=42 (from versions: 41.6.0)
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 ERROR: No matching distribution found for setuptools>=42
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 ----------------------------------------
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 ERROR: Command errored out with exit status 1: /var/lib/juju/agents/unit-telegraf-0/.venv/bin/python /var/lib/juju/agents/unit-telegraf-0/.venv/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-y9wnzkmz/overlay --no-warn-script-location --no-binary :none: --only-binary :none: --no-index --find-links wheelhouse -- 'setuptools>=42' wheel Check the logs for full command output.
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 Traceback (most recent call last):
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 File "/var/lib/juju/agents/unit-telegraf-0/charm/hooks/install", line 8, in <module>
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 basic.bootstrap_charm_deps()
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 File "/var/lib/juju/agents/unit-telegraf-0/charm/lib/charms/layer/basic.py", line 226, in bootstrap_charm_deps
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 check_call([pip, 'install', '-U', reinstall_flag, '--no-index',
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 raise CalledProcessError(retcode, cmd)
2024-03-25 15:21:58 WARNING unit.telegraf/0.install logger.go:60 subprocess.CalledProcessError: Command '['/var/lib/juju/agents/unit-telegraf-0/.venv/bin/pip', 'install', '-U', '--force-reinstall', '--no-index', '--no-cache-dir', '-f', 'wheelhouse', 'lockfile==0.12.2', 'immutables==0.19', 'charms.reactive==1.5.2', 'pbr==6.0.0', 'sniffio==1.2.0', 'contextvars==2.4', 'defusedxml==0.5.0', 'six==1....

Read more...

Revision history for this message
Alejandro Santoyo Gonzalez (al3jandrosg) :
Revision history for this message
Eric Chen (eric-chen) wrote (last edit ):

Unfortunately, we currently have no plans to restore the CI server due to the complete loss of our infrastructure. Additionally, this project is in maintenance mode and is likely to be deprecated within the year. All system metrics should be provided with node exporter. I recommend that you also raise your request there.

https://github.com/canonical/grafana-agent-operator/blob/main/src/charm.py#L362

I could find a member to take a look again since it's close to the time of 24.04 release.

Revision history for this message
Chi Wai CHAN (raychan96) wrote :

This is unfortunately caused by external dependency: https://github.com/canonical/layer-basic/issues/223

Unmerged commits

bb7a195... by Alejandro Santoyo Gonzalez

Adding support for intel_powerstat

This patch adds support for intel_powerstat by:

- fixing the permissions issues when attempting to read
`/sys/devices/virtual/powercap/intel-rapl/`
- adding charm configs: `collect_intel_powerstat_metrics`,
`package_metrics`, `cpu_metrics`

Fixes [LP#1976521](https://bugs.launchpad.net/charm-telegraf/+bug/1976521)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/config.yaml b/src/config.yaml
index 282a163..a66b279 100644
--- a/src/config.yaml
+++ b/src/config.yaml
@@ -268,3 +268,31 @@ options:
268 intel-cmt-cat package on ppa:canonical-bootstack/public. Also, Telegraf needs268 intel-cmt-cat package on ppa:canonical-bootstack/public. Also, Telegraf needs
269 to include a patch for https://github.com/influxdata/telegraf/issues/9380, currently269 to include a patch for https://github.com/influxdata/telegraf/issues/9380, currently
270 available in ppa:guoqiao/telegraf.270 available in ppa:guoqiao/telegraf.
271 collect_intel_powerstat_metrics:
272 default: false
273 type: boolean
274 description: >
275 Enable the collection of power statistics on Intel-based platforms using
276 the telegraf intel_powerstat plugin.
277 .
278 There are certain requisites to run this plugin, including having a
279 kernel >= v3.13, for `uncore_frequency` metrics `intel-uncore-frequency`
280 module is required (available since kernel v5.6).
281 .
282 See https://github.com/influxdata/telegraf/blob/master/plugins/inputs/intel_powerstat/README.md
283 package_metrics:
284 default: "current_power_consumption"
285 type: string
286 description: >
287 If set, the comma-separated list of package metrics to be monitored by the
288 plugin.
289
290 ex: "current_power_consumption,current_dram_power_consumption,thermal_design_power"
291 cpu_metrics:
292 default: "cpu_temperature"
293 type: string
294 description: >
295 If set, the comma-separated list of per-CPU metrics to be monitored by the
296 plugin.
297
298 ex: "cpu_frequency,cpu_temperature"
271\ No newline at end of file299\ No newline at end of file
diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py
index eea17e6..3df37a0 100644
--- a/src/reactive/telegraf.py
+++ b/src/reactive/telegraf.py
@@ -116,6 +116,16 @@ RDT_KERNEL_MODULE_NAME = "msr"
116TLS_CERT = pathlib.Path("/etc/telegraf/tls/server.crt")116TLS_CERT = pathlib.Path("/etc/telegraf/tls/server.crt")
117TLS_KEY = pathlib.Path("/etc/telegraf/tls/server.key")117TLS_KEY = pathlib.Path("/etc/telegraf/tls/server.key")
118118
119# constants related to Intel Powerstat metrics support
120POWERSTAT_MINIMUM_KERNEL_VERSION = (3, 13, 0)
121POWERSTAT_KERNEL_VERSION_RESTRICTED_PERMS = (5, 4, 77)
122POWERSTAT_KERNEL_MODULE_NAMES = { # keys are kernel versions, values are module names
123 (4, 0, 0): ["msr", "intel_rapl"],
124 (5, 0, 0): ["rapl", "msr", "intel_rapl_common", "intel_rapl_msr"],
125 (5, 6, 0): ["intel-uncore-frequency"],
126}
127POWERSTAT_ADD_PERMS_PATH = "/sys/devices/virtual/powercap/intel-rapl/"
128
119129
120class InvalidInstallMethodError(Exception):130class InvalidInstallMethodError(Exception):
121 pass131 pass
@@ -129,6 +139,10 @@ class InvalidIntelRDTConfigurationError(Exception):
129 pass139 pass
130140
131141
142class InvalidIntelPowerstatConfigurationError(Exception):
143 pass
144
145
132class Address(Enum):146class Address(Enum):
133 IPV4 = 1147 IPV4 = 1
134 IPV6 = 2148 IPV6 = 2
@@ -140,6 +154,17 @@ def is_intel_rdt_enabled():
140 return config.get("collect_intel_rdt_metrics", False) and is_metal()154 return config.get("collect_intel_rdt_metrics", False) and is_metal()
141155
142156
157def is_intel_powerstat_enabled():
158 config = hookenv.config()
159 if not is_metal():
160 hookenv.log(
161 """WARNING: Intel Powerstat can only be enabled on baremetal.
162 Skipping."""
163 )
164
165 return config.get("collect_intel_powerstat_metrics", False) and is_metal()
166
167
143def write_telegraf_file(path, content):168def write_telegraf_file(path, content):
144 return host.write_file(169 return host.write_file(
145 path,170 path,
@@ -403,6 +428,77 @@ def check_valid_intel_rdt_configuration():
403 return None428 return None
404429
405430
431def check_valid_intel_powerstat_configuration():
432 """
433 Check that the requirements for Intel Powerstat are met.
434
435 Will raise a InvalidIntelPowerstatConfigurationError exception when a
436 validation issue is encountered, otherwise None
437 """
438 current_kernel_version = get_current_kern_ver()
439 if current_kernel_version:
440 # check the minimum kernel version requirement
441 if current_kernel_version < POWERSTAT_MINIMUM_KERNEL_VERSION:
442 raise InvalidIntelPowerstatConfigurationError(
443 "unsupported kernel version: {}, need version higher than {}".format(
444 current_kernel_version, POWERSTAT_MINIMUM_KERNEL_VERSION
445 )
446 )
447
448 # check that the required modules are loaded
449 kernel_version = get_intel_powerstat_kern_ver()
450 if not kernel_version:
451 raise InvalidIntelPowerstatConfigurationError(
452 "Kernel version '{}' is not supported".format(
453 ".".join(map(str, current_kernel_version))
454 )
455 )
456
457 for mod in POWERSTAT_KERNEL_MODULE_NAMES[kernel_version]:
458 if not kernel.is_module_loaded(mod):
459 raise InvalidIntelPowerstatConfigurationError(
460 "required module '{}' is not loaded".format(mod)
461 )
462 else:
463 linux_release = platform.release() # format is like '5.4.0-73-generic'
464 raise InvalidIntelPowerstatConfigurationError(
465 "Incompatible platform.release output: {}".format(linux_release)
466 )
467 return None
468
469
470def get_current_kern_ver():
471 # check that we meet the minimum kernel version
472 linux_release = platform.release() # format is like '5.4.0-73-generic'
473 re_kernel_version = r"^(\d+)\.(\d+)\.(\d+)"
474 match = re.match(re_kernel_version, linux_release)
475
476 if match:
477 return tuple(int(d) for d in match.groups())
478
479 return None
480
481
482def get_intel_powerstat_kern_ver():
483 """
484 Return kernel version.
485
486 Return which kernel version to use as key to parse
487 POWERSTAT_KERNEL_MODULE_NAMES in order to check
488 which modules need to be loaded.
489 """
490 current_kernel_version = get_current_kern_ver()
491 kernel_version = None
492 if current_kernel_version >= (5, 6, 0):
493 kernel_version = (5, 6, 0)
494 elif current_kernel_version >= (5, 0, 0):
495 kernel_version = (5, 0, 0)
496 elif current_kernel_version >= (4, 0, 0):
497 kernel_version = (4, 0, 0)
498
499 return kernel_version
500
501
406def get_cpu_cores():502def get_cpu_cores():
407 """Get the list of available cores for the cpu(s)."""503 """Get the list of available cores for the cpu(s)."""
408 # should return something like ["0-23"]504 # should return something like ["0-23"]
@@ -473,6 +569,15 @@ def get_base_inputs():
473 else:569 else:
474 intel_rdt_cores = None570 intel_rdt_cores = None
475571
572 # handle the Intel Powerstat collection parameters
573 intel_powerstat = is_intel_powerstat_enabled()
574 if intel_powerstat:
575 package_metrics = config["package_metrics"]
576 cpu_metrics = config["cpu_metrics"]
577 else:
578 package_metrics = None
579 cpu_metrics = None
580
476 return {581 return {
477 "extra_options": extra_options["inputs"],582 "extra_options": extra_options["inputs"],
478 "bcache": is_bcache(),583 "bcache": is_bcache(),
@@ -485,6 +590,9 @@ def get_base_inputs():
485 "ipmi_sensor": ipmi_sensor,590 "ipmi_sensor": ipmi_sensor,
486 "intel_rdt": intel_rdt,591 "intel_rdt": intel_rdt,
487 "intel_rdt_cores": intel_rdt_cores,592 "intel_rdt_cores": intel_rdt_cores,
593 "intel_powerstat": intel_powerstat,
594 "package_metrics": package_metrics,
595 "cpu_metrics": cpu_metrics,
488 }596 }
489597
490598
@@ -893,6 +1001,36 @@ def configure_telegraf(): # noqa: C901
893 else:1001 else:
894 remove_sudoers_file(sudoers_filename)1002 remove_sudoers_file(sudoers_filename)
8951003
1004 if is_intel_powerstat_enabled():
1005 hookenv.log("Intel Powerstat enabled, enabling modules and running checks")
1006 # load and persist the required module(s)
1007 kernel_version = get_intel_powerstat_kern_ver()
1008 try:
1009 for mod in POWERSTAT_KERNEL_MODULE_NAMES[kernel_version]:
1010 kernel.modprobe(mod, persist=True)
1011 except subprocess.CalledProcessError:
1012 error_msg = "modprobe {} failed".format(mod)
1013 hookenv.log(error_msg, level=hookenv.ERROR)
1014 hookenv.status_set("blocked", error_msg)
1015 return
1016
1017 try:
1018 check_valid_intel_powerstat_configuration()
1019 except InvalidIntelPowerstatConfigurationError() as e:
1020 # on error we abort configuration and block the charm
1021 error_msg = "Intel Powerstat configuration failed."
1022 hookenv.log(e, level=hookenv.ERROR)
1023 hookenv.status_set("blocked", error_msg)
1024 return
1025
1026 # change the permissions for POWERSTAT_ADD_PERMS_PATH
1027 if kernel_version >= POWERSTAT_KERNEL_VERSION_RESTRICTED_PERMS:
1028 cmd = ["chmod", "-R", "a+rx", POWERSTAT_ADD_PERMS_PATH]
1029 hookenv.log(
1030 "Setting permissions for Powerstat to work: {}".format(" ".join(cmd))
1031 )
1032 subprocess.call(cmd)
1033
896 telegraf_exec_metrics = os.path.join(get_files_dir(), "telegraf_exec_metrics.py")1034 telegraf_exec_metrics = os.path.join(get_files_dir(), "telegraf_exec_metrics.py")
897 cmd = [1035 cmd = [
898 telegraf_exec_metrics,1036 telegraf_exec_metrics,
@@ -1072,6 +1210,12 @@ def handle_config_changes():
1072 else:1210 else:
1073 clear_flag("telegraf.intel_rdt.enabled")1211 clear_flag("telegraf.intel_rdt.enabled")
10741212
1213 # handle the Intel Powerstat metrics collection
1214 if is_intel_powerstat_enabled():
1215 set_flag("telegraf.intel_powerstat.enabled")
1216 else:
1217 clear_flag("telegraf.intel_powerstat.enabled")
1218
1075 clear_flag("telegraf.configured")1219 clear_flag("telegraf.configured")
1076 clear_flag("telegraf.apt.configured")1220 clear_flag("telegraf.apt.configured")
1077 clear_flag("telegraf.snap.configured")1221 clear_flag("telegraf.snap.configured")
diff --git a/src/templates/base_inputs.conf b/src/templates/base_inputs.conf
index 9e178be..117acdd 100644
--- a/src/templates/base_inputs.conf
+++ b/src/templates/base_inputs.conf
@@ -179,6 +179,18 @@ use_sudo = true
179{%- endif %}179{%- endif %}
180{% endif %}180{% endif %}
181181
182{% if "intel_powerstat" not in disabled_plugins %}
183{% if intel_powerstat -%}
184[[inputs.intel_powerstat]]
185{% if package_metrics %}
186package_metrics = {{ package_metrics.split(',') | tojson }}
187{% endif %}
188{% if cpu_metrics %}
189cpu_metrics = {{ cpu_metrics.split(',') | tojson }}
190{% endif %}
191{%- endif %}
192{% endif %}
193
182[[inputs.exec]]194[[inputs.exec]]
183commands = [195commands = [
184 "/usr/bin/awk '{ print $1 }' /proc/sys/fs/file-nr"196 "/usr/bin/awk '{ print $1 }' /proc/sys/fs/file-nr"
diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py
index 2ba2a0e..0493a94 100644
--- a/src/tests/unit/test_telegraf.py
+++ b/src/tests/unit/test_telegraf.py
@@ -2044,6 +2044,38 @@ def test_check_valid_intel_rdt_configuration_pqos(monkeypatch):
2044 telegraf.check_valid_intel_rdt_configuration()2044 telegraf.check_valid_intel_rdt_configuration()
20452045
20462046
2047def test_collect_intel_powerstat_metrics(monkeypatch, config):
2048 monkeypatch.setattr(telegraf, "is_container", lambda: False)
2049 monkeypatch.setattr(telegraf, "is_metal", lambda: True)
2050 config["collect_intel_powerstat_metrics"] = True
2051 config["package_metrics"] = "current_power_consumption,thermal_design_power"
2052 config["cpu_metrics"] = "cpu_frequency"
2053 monkeypatch.setattr(
2054 telegraf, "check_valid_intel_powerstat_configuration", lambda: ""
2055 )
2056 monkeypatch.setattr(kernel, "modprobe", lambda module, persist: "msr")
2057 telegraf.configure_telegraf()
2058
2059 expected = """
2060[[inputs.intel_powerstat]]
2061package_metrics = ["current_power_consumption", "thermal_design_power"]
2062cpu_metrics = ["cpu_frequency"]
2063"""
2064 config_file = base_dir().join("telegraf.conf")
2065 assert expected in config_file.read()
2066
2067
2068def test_check_valid_intel_powerstat_configuration_kernel_version(monkeypatch):
2069 monkeypatch.setattr(telegraf, "is_container", lambda: False)
2070 monkeypatch.setattr(telegraf, "is_metal", lambda: True)
2071 monkeypatch.setattr(platform, "release", lambda: "3.3.0-73-generic")
2072 with pytest.raises(
2073 telegraf.InvalidIntelPowerstatConfigurationError,
2074 match="unsupported kernel version",
2075 ):
2076 telegraf.check_valid_intel_powerstat_configuration()
2077
2078
2047def test_configure_tls(monkeypatch):2079def test_configure_tls(monkeypatch):
2048 tnp_key_location = pathlib.Path("/tmp/fake-key")2080 tnp_key_location = pathlib.Path("/tmp/fake-key")
2049 tmp_cert_location = pathlib.Path("/tmp/fake-crt")2081 tmp_cert_location = pathlib.Path("/tmp/fake-crt")

Subscribers

People subscribed via source and target branches

to all changes: