Skip to content

rpc-extractor: add getmemoryinfo and getaddrmaninfo - #309

Merged
0xB10C merged 2 commits into
peer-observer:masterfrom
GuiSchet:rpc-extractor-getmemoryinfo-getaddrmaninfo
Dec 18, 2025
Merged

0xB10C merged 2 commits into
peer-observer:masterfrom
GuiSchet:rpc-extractor-getmemoryinfo-getaddrmaninfo

Conversation

@GuiSchet

Copy link
Copy Markdown
Contributor

Add RPC extractors for getmemoryinfo and getaddrmaninfo
Implements support for two new Bitcoin Core RPC methods in the rpc-extractor, listed on #199

Changes

  1. getmemoryinfo RPC Support

Extracts memory usage statistics from Bitcoin Core:

  • Protobuf: Added MemoryInfo and LockedMemory messages
  • RPC Extractor: Implemented getmemoryinfo() function with --disable-getmemoryinfo flag
  • Metrics: Added 6 Prometheus metrics for locked memory statistics:
    • rpc_memoryinfo_locked_used
    • rpc_memoryinfo_locked_free
    • rpc_memoryinfo_locked_total
    • rpc_memoryinfo_locked_locked
    • rpc_memoryinfo_locked_chunks_used
    • rpc_memoryinfo_locked_chunks_free
  • Tests: Added integration test test_integration_rpc_getmemoryinfo
  1. getaddrmaninfo RPC Support

Extracts address manager statistics from Bitcoin Core (requires Bitcoin Core v26+):

  • Protobuf: Added AddrManInfo and AddrManInfoNetwork messages
  • RPC Extractor: Implemented getaddrmaninfo() function with --disable-getaddrmaninfo flag
  • Metrics: Added 18 Prometheus metrics for address manager stats across 6 networks (ipv4, ipv6, onion, i2p, cjdns,
    all_networks):
    • rpc_addrmaninfo_{network}_new
    • rpc_addrmaninfo_{network}_tried
    • rpc_addrmaninfo_{network}_total
  • Tests: Added integration test test_integration_rpc_getaddrmaninfo

Modified Files

Protobuf schema:

  • protobuf/rpc_extractor.proto - Added message definitions for both RPCs

Shared library:

  • shared/src/protobuf/rpc_extractor.rs - Implemented Display and From traits

RPC Extractor:

  • extractors/rpc/src/lib.rs - Added both RPC functions and CLI flags
  • extractors/rpc/tests/integration.rs - Added integration tests for both RPCs
  • extractors/rpc/README.md - Updated documentation

Metrics tool:

  • tools/metrics/src/metrics.rs - Added metric definitions (24 new metrics total)
  • tools/metrics/src/lib.rs - Added event handlers for both RPCs

Testing
All tests pass successfully:

  • ✅ 6/6 rpc-extractor integration tests (including 2 new tests)
  • ✅ 46/46 metrics integration tests

Both RPCs can be individually disabled using --disable-getmemoryinfo and --disable-getaddrmaninfo flags.

@GuiSchet

Copy link
Copy Markdown
Contributor Author

I've successfully deployed and tested the new getmemoryinfo and getaddrmaninfo RPC extractors in my testing infrastructure. Both are working correctly and exposing metrics to Prometheus.

Current Metrics from Node

getmemoryinfo (6 metrics):
peerobserver_rpc_memoryinfo_locked_total: 262,144 bytes (256 KB)
peerobserver_rpc_memoryinfo_locked_used: 352 bytes
peerobserver_rpc_memoryinfo_locked_free: 261,792 bytes
peerobserver_rpc_memoryinfo_locked_locked: 262,144 bytes
peerobserver_rpc_memoryinfo_locked_chunks_used: 1
peerobserver_rpc_memoryinfo_locked_chunks_free: 1

getaddrmaninfo (18 metrics):
Total addresses: 65,909

  • New table: 65,136 addresses
  • Tried table: 773 addresses

By network:

  • IPv4: 58,455 total (57,682 new, 773 tried)
  • IPv6: 7,454 total (7,454 new, 0 tried)
  • Onion: 0
  • I2P: 0
  • CJDNS: 0drmaninfo RPCs Working

Comment on lines +104 to +117
// A getmemoryinfo RPC result: Returns information about memory usage.
message MemoryInfo {
required LockedMemory locked = 1; // Information about locked memory manager
}

// Locked memory manager information. Part of getmemoryinfo.
message LockedMemory {
required uint64 used = 1; // Number of bytes used
required uint64 free = 2; // Number of bytes available in current arenas
required uint64 total = 3; // Total number of bytes managed
required uint64 locked = 4; // Amount of bytes that succeeded locking
required uint64 chunks_used = 5; // Number of allocated chunks
required uint64 chunks_free = 6; // Number of unused chunks
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify this, no need for the additional locked step:

Suggested change
// A getmemoryinfo RPC result: Returns information about memory usage.
message MemoryInfo {
required LockedMemory locked = 1; // Information about locked memory manager
}
// Locked memory manager information. Part of getmemoryinfo.
message LockedMemory {
required uint64 used = 1; // Number of bytes used
required uint64 free = 2; // Number of bytes available in current arenas
required uint64 total = 3; // Total number of bytes managed
required uint64 locked = 4; // Amount of bytes that succeeded locking
required uint64 chunks_used = 5; // Number of allocated chunks
required uint64 chunks_free = 6; // Number of unused chunks
}
// A getmemoryinfo RPC result: Returns information about memory usage.
message MemoryInfo {
required uint64 used = 1; // Number of bytes used
required uint64 free = 2; // Number of bytes available in current arenas
required uint64 total = 3; // Total number of bytes managed
required uint64 locked = 4; // Amount of bytes that succeeded locking
required uint64 chunks_used = 5; // Number of allocated chunks
required uint64 chunks_free = 6; // Number of unused chunks
}

Comment thread shared/src/protobuf/rpc_extractor.rs Outdated
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"LockedMemory(used={}B, total={}B, locked={}B)",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"LockedMemory(used={}B, total={}B, locked={}B)",
"MemoryInfo(used={}B, total={}B, locked={}B)",

Comment thread tools/metrics/src/metrics.rs Outdated
Comment on lines +291 to +308
pub rpc_addrmaninfo_ipv4_new: IntGauge,
pub rpc_addrmaninfo_ipv4_tried: IntGauge,
pub rpc_addrmaninfo_ipv4_total: IntGauge,
pub rpc_addrmaninfo_ipv6_new: IntGauge,
pub rpc_addrmaninfo_ipv6_tried: IntGauge,
pub rpc_addrmaninfo_ipv6_total: IntGauge,
pub rpc_addrmaninfo_onion_new: IntGauge,
pub rpc_addrmaninfo_onion_tried: IntGauge,
pub rpc_addrmaninfo_onion_total: IntGauge,
pub rpc_addrmaninfo_i2p_new: IntGauge,
pub rpc_addrmaninfo_i2p_tried: IntGauge,
pub rpc_addrmaninfo_i2p_total: IntGauge,
pub rpc_addrmaninfo_cjdns_new: IntGauge,
pub rpc_addrmaninfo_cjdns_tried: IntGauge,
pub rpc_addrmaninfo_cjdns_total: IntGauge,
pub rpc_addrmaninfo_all_new: IntGauge,
pub rpc_addrmaninfo_all_tried: IntGauge,
pub rpc_addrmaninfo_all_total: IntGauge,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of duplicating this, we should just use a pub rpc_addrmaninfo: IntGaugeVec and have the labels be network (ipv4, ipv6, ...) and type (new, tried, total).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, 'll work on this

@GuiSchet

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @0xB10C! I've implemented all the suggested improvements:

1. Flattened Protobuf Structure

  • Before: MemoryInfo { locked: LockedMemory { fields... } }
  • After: MemoryInfo { fields... } (all fields at top level)
  • Eliminates unnecessary nesting complexity
  • Updated Display format to show "MemoryInfo" instead of "LockedMemory"

2. Optimized Metrics with IntGaugeVec

  • Before: 18 separate IntGauge fields (ipv4_new, ipv4_tried, ipv4_total, etc.)
  • After: Single IntGaugeVec with labels ["network", "type"]
  • Impact:
    • Struct fields: 18 → 1 (-94%)
    • Initialization code: 18 lines → 1 line (-94%)
    • Handler code: 36 lines → 14 lines (-61%)
  • Follows Prometheus best practices for dimensional metrics

3. Updated Tests

  • Modified test_integration_rpc_getmemoryinfo for flattened structure
  • All RPC extractor integration tests passing: 6/6 ✅
  • All metrics integration tests passing: 46/46 ✅

All CI checks passing locally. Ready for review!

@deadmanoz deadmanoz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on minor changes.

Comment thread extractors/rpc/src/lib.rs Resolved
Comment thread extractors/rpc/README.md Resolved
Comment thread extractors/rpc/tests/integration.rs Resolved
@GuiSchet

Copy link
Copy Markdown
Contributor Author

Updated test assertion as requested, thanks both for the feedback!

@0xB10C
0xB10C force-pushed the rpc-extractor-getmemoryinfo-getaddrmaninfo branch from 009142d to d04e396 Compare December 18, 2025 14:48

@0xB10C 0xB10C left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashed the commits and added two metrics tests: test_integration_metrics_rpc_getmemoryinfo and test_integration_metrics_rpc_getaddrmaninfo.

Looks good to me now.

Comment thread extractors/rpc/README.md Outdated
Comment on lines +55 to +66

## Supported RPCs

The `rpc-extractor` currently supports the following Bitcoin Core RPC methods:

- **`getpeerinfo`**: Information about each connected peer
- **`getmempoolinfo`**: Details on the active state of the TX memory pool
- **`uptime`**: Node uptime in seconds
- **`getnettotals`**: Information about network traffic (bytes in/out)
- **`getmemoryinfo`**: Information about memory usage (locked memory statistics)

Each RPC can be individually disabled using the corresponding `--disable-*` flag.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to have, but maybe in a separate PR. Maybe when we close #199.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xB10C

0xB10C commented Dec 18, 2025

Copy link
Copy Markdown
Collaborator
|| Tested/Total Lines:
|| extractors/ebpf/src/error.rs: 0/34
|| extractors/ebpf/src/main.rs: 0/346
|| extractors/ebpf/src/tracing.gen.rs: 0/370
|| extractors/log/src/error.rs: 0/16
|| extractors/log/src/lib.rs: 30/37
|| extractors/log/src/main.rs: 0/7
|| extractors/log/tests/integration.rs: 63/66
|| extractors/p2p/src/error.rs: 7/31
|| extractors/p2p/src/lib.rs: 115/148
|| extractors/p2p/src/main.rs: 0/7
|| extractors/p2p/tests/integration.rs: 107/111
|| extractors/rpc/src/error.rs: 0/36
|| extractors/rpc/src/lib.rs: 77/80
|| extractors/rpc/src/main.rs: 0/7
|| extractors/rpc/tests/integration.rs: 52/54
|| shared/src/log_matchers.rs: 53/53
|| shared/src/metricserver.rs: 25/46
|| shared/src/nats_subjects.rs: 10/10
|| shared/src/protobuf/bitcoin_primitives.rs: 49/147
|| shared/src/protobuf/ebpf_extractor/addrman.rs: 11/27
|| shared/src/protobuf/ebpf_extractor/connection.rs: 10/44
|| shared/src/protobuf/ebpf_extractor/ctypes.rs: 27/146
|| shared/src/protobuf/ebpf_extractor/mempool.rs: 9/49
|| shared/src/protobuf/ebpf_extractor/message.rs: 20/321
|| shared/src/protobuf/ebpf_extractor/mod.rs: 0/7
|| shared/src/protobuf/ebpf_extractor/validation.rs: 9/17
|| shared/src/protobuf/event.rs: 6/6
|| shared/src/protobuf/log_extractor.rs: 10/12
|| shared/src/protobuf/p2p_extractor.rs: 22/29
|| shared/src/protobuf/rpc_extractor.rs: 87/105
|| shared/src/testing/nats_publisher.rs: 8/8
|| shared/src/testing/nats_server.rs: 51/57
|| shared/src/util.rs: 22/23
|| tools/connectivity-check/src/main.rs: 0/198
|| tools/connectivity-check/src/metrics.rs: 0/36
|| tools/logger/src/error.rs: 2/20
|| tools/logger/src/lib.rs: 48/56
|| tools/logger/src/main.rs: 0/7
|| tools/logger/tests/integration.rs: 42/45
|| tools/metrics/src/error.rs: 7/24
|| tools/metrics/src/lib.rs: 534/535
|| tools/metrics/src/main.rs: 0/7
|| tools/metrics/src/metrics.rs: 17/17
|| tools/metrics/src/stat_util.rs: 14/14
|| tools/metrics/tests/integration.rs: 76/80
|| tools/websocket/src/error.rs: 0/24
|| tools/websocket/src/lib.rs: 39/45
|| tools/websocket/src/main.rs: 0/7
|| tools/websocket/tests/integration.rs: 55/66
||
47.11% coverage, 1714/3638 lines covered

@0xB10C
0xB10C merged commit f43c3ce into peer-observer:master Dec 18, 2025
@0xB10C

0xB10C commented Dec 18, 2025

Copy link
Copy Markdown
Collaborator

Again, thank you @GuiSchet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants