Skip to content

Commit ae2257d

Browse files
fix: match counter names by suffix for preset filtering
PerfMon returns full paths (\\host\Object\Counter) but presets filter by bare name (Counter). Now uses endsWith matching.
1 parent c9c675c commit ae2257d

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/tools/counter-tools.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export async function handleCounterTool(name: string, args: Record<string, unkno
125125
if (name === "counter_snapshot") {
126126
const { object, counters: filterCounters } = resolvePreset(args);
127127
const values = await perfmonCollectCounterData(creds, perfmonHost, object, args.timeoutMs as number | undefined);
128-
const filtered = filterCounters ? values.filter(v => filterCounters.includes(v.name)) : values;
128+
const filtered = filterCounters
129+
? values.filter(v => filterCounters.some(fc => v.name === fc || v.name.endsWith(`\\${fc}`)))
130+
: values;
129131
return jsonResponse({ object, host: perfmonHost, counters: filtered });
130132
}
131133

src/types/perfmon-types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,16 @@ export const COUNTER_PRESETS: Record<string, { object: string; counters?: string
7272
system: { object: "Processor" },
7373
};
7474

75+
/** Extract bare counter name from full PerfMon path (e.g., \\\\host\\Object\\Counter → Counter) */
76+
export function bareCounterName(name: string): string {
77+
const lastSlash = name.lastIndexOf("\\");
78+
return lastSlash >= 0 ? name.slice(lastSlash + 1) : name;
79+
}
80+
7581
export function classifyCounter(name: string): CounterType {
76-
if (GAUGE_COUNTERS.has(name)) return "gauge";
77-
if (MONOTONIC_COUNTERS.has(name)) return "counter";
82+
const bare = bareCounterName(name);
83+
if (GAUGE_COUNTERS.has(bare)) return "gauge";
84+
if (MONOTONIC_COUNTERS.has(bare)) return "counter";
7885
return "unknown";
7986
}
8087

0 commit comments

Comments
 (0)