Class ResourceGraph
Default implementation of IResourceGraph.
public sealed class ResourceGraph : IResourceGraph
- Inheritance
-
ResourceGraph
- Implements
- Inherited Members
Remarks
The resource graph walks the tree to collect snapshots and maintains a reference to the previous snapshot for throughput rate computation.
Performance: Snapshot collection costs ~50ns per node. For 100 nodes, that's ~5μs total. The MetricWriter is pooled to avoid allocations on the hot path.
Constructors
ResourceGraph(IResourceRegistry)
Creates a new resource graph backed by the specified registry.
public ResourceGraph(IResourceRegistry registry)
Parameters
registryIResourceRegistryThe resource registry providing the tree structure.
Properties
Root
The root of the resource tree.
public IResource Root { get; }
Property Value
Methods
FindByPath(string)
Find a resource by path.
public IResource FindByPath(string path)
Parameters
pathstringSlash-separated path (e.g., "Storage/PageCache"). Does not include "Root" prefix.
Returns
- IResource
The resource, or null if not found.
FindByType(ResourceType)
Find all resources of a specific type.
public IEnumerable<IResource> FindByType(ResourceType type)
Parameters
typeResourceTypeThe resource type to find.
Returns
- IEnumerable<IResource>
All resources of the specified type.
GetSnapshot()
Walk the entire tree, read all IMetricSource nodes, return immutable snapshot. Throughput rates are auto-computed from the previous snapshot.
public ResourceSnapshot GetSnapshot()
Returns
- ResourceSnapshot
Snapshot containing all metric values at approximately this instant.
Remarks
Cost: ~50ns per node × number of nodes. Typically 50-100 nodes = 2.5-5 μs.
The graph internally tracks the previous snapshot for rate computation. First snapshot has Rates = null.
GetSnapshot(IResource)
Read metrics for a single subtree only.
public ResourceSnapshot GetSnapshot(IResource subtreeRoot)
Parameters
subtreeRootIResourceThe root of the subtree to snapshot.
Returns
- ResourceSnapshot
Snapshot containing only nodes under subtreeRoot.
Remarks
Use when you know which subsystem to inspect. Faster than full snapshot.
Note: Rates are computed only for nodes in the subtree.
ResetAllPeaks()
Reset all peak/high-water mark values across all IMetricSource nodes.
public void ResetAllPeaks()
Remarks
Walks the tree and calls ResetPeaks() on each metric source.
Use after alert acknowledgment, periodic reset, or on operator request. This is a separate operation from snapshot collection (snapshots are read-only).