|
21 | 21 | from newrelic.api.background_task import background_task |
22 | 22 | from newrelic.api.transaction import set_background_task |
23 | 23 |
|
| 24 | +from newrelic.common import system_info |
| 25 | + |
24 | 26 | DB_SETTINGS = memcached_settings()[0] |
25 | 27 |
|
26 | 28 | MEMCACHED_HOST = DB_SETTINGS["host"] |
27 | 29 | MEMCACHED_PORT = DB_SETTINGS["port"] |
28 | 30 | MEMCACHED_NAMESPACE = DB_SETTINGS["namespace"] |
29 | | - |
30 | 31 | MEMCACHED_ADDR = (MEMCACHED_HOST, int(MEMCACHED_PORT)) |
| 32 | +INSTANCE_METRIC_HOST = system_info.gethostname() if MEMCACHED_HOST == "127.0.0.1" else MEMCACHED_HOST |
| 33 | +INSTANCE_METRIC_NAME = f"Datastore/instance/Memcached/{INSTANCE_METRIC_HOST}/{MEMCACHED_PORT}" |
| 34 | + |
31 | 35 |
|
32 | 36 | _test_bt_set_get_delete_scoped_metrics = [ |
33 | 37 | ("Datastore/operation/Memcached/set", 1), |
|
43 | 47 | ("Datastore/operation/Memcached/set", 1), |
44 | 48 | ("Datastore/operation/Memcached/get", 1), |
45 | 49 | ("Datastore/operation/Memcached/delete", 1), |
46 | | - (f"Datastore/instance/Memcached/{MEMCACHED_HOST}/{MEMCACHED_PORT}", 3), |
| 50 | + (INSTANCE_METRIC_NAME, 3), |
47 | 51 | ] |
48 | 52 |
|
49 | 53 |
|
@@ -81,7 +85,7 @@ def test_bt_set_get_delete(): |
81 | 85 | ("Datastore/operation/Memcached/set", 1), |
82 | 86 | ("Datastore/operation/Memcached/get", 1), |
83 | 87 | ("Datastore/operation/Memcached/delete", 1), |
84 | | - (f"Datastore/instance/Memcached/{MEMCACHED_HOST}/{MEMCACHED_PORT}", 3), |
| 88 | + (INSTANCE_METRIC_NAME, 3), |
85 | 89 | ] |
86 | 90 |
|
87 | 91 |
|
|
0 commit comments