File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 1616memory usage.
1717
1818"""
19+ import os
1920
20- from newrelic .common .system_info import physical_memory_used
21+ from newrelic .common .system_info import physical_memory_used , total_physical_memory
2122
2223from newrelic .samplers .decorators import data_source_generator
2324
25+ PID = os .getpid ()
26+
2427
2528@data_source_generator (name = 'Memory Usage' )
2629def memory_usage_data_source ():
27- yield ('Memory/Physical' , physical_memory_used ())
30+ yield ('Memory/Physical/%d' % (PID ), physical_memory_used ())
31+ yield ('Memory/Physical/Utilization/%d' % (PID ), physical_memory_used ()/ total_physical_memory ())
Original file line number Diff line number Diff line change 1+ # Copyright 2010 New Relic, Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ import pytest
16+ import os
17+
18+ from newrelic .samplers .memory_usage import memory_usage_data_source
19+
20+ @pytest .fixture
21+ def data_source ():
22+ sampler = memory_usage_data_source (settings = ())["factory" ](environ = ())
23+ yield sampler
24+
25+ PID = os .getpid ()
26+
27+ EXPECTED_METRICS = (
28+ "Memory/Physical/%d" % PID ,
29+ "Memory/Physical/Utilization/%d" % PID ,
30+ )
31+
32+
33+ def test_gc_metrics_collection (data_source ):
34+ metrics_table = set (m [0 ] for m in (data_source () or ()))
35+
36+ for metric in EXPECTED_METRICS :
37+ assert metric in metrics_table
You can’t perform that action at this time.
0 commit comments