-
Notifications
You must be signed in to change notification settings - Fork 814
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
[swap stats] add swap in/out check to checks.d #1549
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from checks import AgentCheck | ||
try: | ||
import psutil | ||
except ImportError: | ||
psutil = None | ||
|
||
B2MB = float(1048576) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like it's not needed anymore :) |
||
|
||
class SystemSwap(AgentCheck): | ||
|
||
def check(self, instance): | ||
if not psutil: | ||
return {} | ||
|
||
swap_mem = psutil.swap_memory() | ||
self.gauge('system.swap.swapped_in', swap_mem.sin / B2MB) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use a rate for these.
By submitting the metric as a rate, you will compute the # of bytes per second swapped in. Also you should submit this value in bytes as per our discussion earlier. |
||
self.gauge('system.swap.swapped_out', swap_mem.sout / B2MB) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import mock | ||
import psutil | ||
|
||
from tests.common import AgentCheckTest | ||
|
||
B2MB = float(1048576) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed |
||
|
||
class _PSUtilSwapStatsMock(object): | ||
def __init__(self, sin, sout): | ||
self.sin = sin | ||
self.sout = sout | ||
|
||
MOCK_PSUTIL_SWAP_STATS = [ | ||
_PSUtilSwapStatsMock(115332743168, 22920884224), | ||
_PSUtilSwapStatsMock(115332743170, 22920884230), | ||
] | ||
|
||
class SystemSwapTestCase(AgentCheckTest): | ||
|
||
CHECK_NAME = 'system_swap' | ||
|
||
@mock.patch('psutil.swap_memory', side_effect=MOCK_PSUTIL_SWAP_STATS) | ||
def test_system_swap(self, mock_swap_stats): | ||
self.run_check({"instances": [{}]}) | ||
self.assertMetric('system.swap.swapped_in', 115332743168 / B2MB) | ||
self.assertMetric('system.swap.swapped_out', 22920884224 / B2MB) | ||
|
||
self.run_check({"instances": [{}]}) | ||
self.assertMetric('system.swap.swapped_in', 115332743170 / B2MB) | ||
self.assertMetric('system.swap.swapped_out', 22920884230 / B2MB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know i told you something different yesterday but after all i think we shouldn't manage the case where psutil is not present.
The only case where it's not present is when someone installs the agent from source on a system that doesn't have a compiler. And if that's the case, the check initialization will fail and report the missing import which is an acceptable behavior.