ironmonitor 7.1.0

IronMonitor: hardware monitoring for CPUs, GPUs, NPUs, memory, I/O and network silicon on Linux, Windows and macOS, which reports what it cannot read as well as what it can
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
//! Memory module detail (serial, bank, ranks, form factor), topology analysis, EDAC rows and NUMA detail.

#[allow(unused_imports)]
use super::super::resolve::*;
#[allow(unused_imports)]
use super::super::{Domain as D, Entity, EntityKind as K, Provenance as P, Unit as U};

use crate::memory_topology::{DimmInfo, MemoryTopology};

#[allow(clippy::too_many_arguments)]
fn e(
    add: &mut dyn FnMut(Entity),
    id: &str,
    kind: K,
    unit: Option<U>,
    prov: P,
    nullable: bool,
    description: &str,
) {
    add(Entity::new(
        id,
        D::Memory,
        kind,
        unit,
        prov,
        nullable,
        description,
    ));
}

pub(super) fn declare(add: &mut dyn FnMut(Entity)) {
    // ── Module detail (DimmInfo, from SMBIOS) ───────────────────────────────
    e(add, "memory.dimm.{n}.serial_number", K::Identity, Some(U::Identifier), P::Specification, true,
      "Serial number of the memory module, as its SMBIOS memory device record carries it. Absent for an empty slot.");
    e(
        add,
        "memory.dimm.{n}.bank",
        K::Identity,
        Some(U::Text),
        P::Specification,
        true,
        "Bank label of the module's slot, such as BANK 0, from its SMBIOS memory device record.",
    );
    e(add, "memory.dimm.{n}.ranks", K::Measurement, Some(U::Count), P::Specification, true,
      "Number of ranks on the module, from its SMBIOS memory device record. Absent where the record carries no rank count.");
    e(add, "memory.dimm.{n}.form_factor", K::Identity, Some(U::Text), P::Specification, true,
      "Physical form of the module, such as DIMM, SO-DIMM or On-Package, from its SMBIOS memory device record.");

    // ── Topology analysis (MemoryAnalysis) ──────────────────────────────────
    e(add, "memory.topology.total_slots", K::Measurement, Some(U::Count), P::Specification, true,
      "Number of memory slots the board has, empty ones included, where the firmware lists them. Absent where the reader lists installed modules only.");
    add(Entity::new(
        "memory.topology.populated_slots",
        D::Memory,
        K::Measurement,
        Some(U::Count),
        P::Derived,
        true,
        "Number of DIMM slots the reader established as holding a module, counted from the per-slot populated flags. Unavailable where the slot table cannot be read, as on Linux without root.",
    )
    .derived(&["memory.dimm.{n}.populated"]));
    add(Entity::new(
        "memory.topology.channel_count",
        D::Memory,
        K::Measurement,
        Some(U::Count),
        P::Derived,
        true,
        "Number of memory channels inferred from the DIMM locator names. Absent where no locator names a channel.",
    )
    .derived(&["memory.dimm.{n}.locator"]));
    add(Entity::new(
        "memory.topology.dual_channel",
        D::Memory,
        K::Identity,
        None,
        P::Derived,
        true,
        "Whether the populated modules are spread across two channels, inferred from the DIMM locator names. Absent where the channel count is not established.",
    )
    .derived(&["memory.dimm.{n}.locator"]));
    add(Entity::new(
        "memory.topology.matched_speeds",
        D::Memory,
        K::Identity,
        None,
        P::Derived,
        true,
        "Whether every module reports the same speed, compared across the per-slot speeds. Absent where fewer than two speeds were read.",
    )
    .derived(&["memory.dimm.{n}.speed"]));
    add(Entity::new(
        "memory.topology.matched_capacities",
        D::Memory,
        K::Identity,
        None,
        P::Derived,
        true,
        "Whether every module has the same capacity, compared across the per-slot capacities. Absent where fewer than two capacities were read.",
    )
    .derived(&["memory.dimm.{n}.capacity"]));
    e(
        add,
        "memory.topology.max_capacity_bytes",
        K::Limit,
        Some(U::Bytes),
        P::Specification,
        true,
        concat!(
            "The board's declared maximum memory capacity, from its SMBIOS type 16 ",
            "Physical Memory Array record, summed over the system-memory arrays. It is ",
            "the board's rating, not the installed amount. Absent where the record was ",
            "not read: Linux needs root for dmidecode, and macOS publishes no maximum."
        ),
    );

    // ── EDAC error counters (EdacMonitor) ───────────────────────────────────
    e(
        add,
        "memory.ecc.controller.<none>",
        K::Diagnostic,
        None,
        P::Unavailable,
        true,
        "Present when no EDAC memory controller was enumerated, carrying why.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.mc_name",
        K::Identity,
        Some(U::Identifier),
        P::Measured,
        true,
        "Name of the memory controller driver, as the kernel's EDAC subsystem lists it.",
    );
    e(add, "memory.ecc.controller.{n}.ce_count", K::Measurement, Some(U::Count), P::Measured, true,
      "Correctable errors this memory controller has counted since its last reset, from the EDAC subsystem.");
    e(add, "memory.ecc.controller.{n}.ue_count", K::Measurement, Some(U::Count), P::Measured, true,
      "Uncorrectable errors this memory controller has counted since its last reset, from the EDAC subsystem.");
    e(add, "memory.ecc.controller.{n}.ce_noinfo_count", K::Measurement, Some(U::Count), P::Measured, true,
      "Correctable errors this controller counted without attributing them to a DIMM, from the EDAC subsystem.");
    e(add, "memory.ecc.controller.{n}.ue_noinfo_count", K::Measurement, Some(U::Count), P::Measured, true,
      "Uncorrectable errors this controller counted without attributing them to a DIMM, from the EDAC subsystem.");
    e(
        add,
        "memory.ecc.controller.{n}.seconds_since_reset",
        K::Measurement,
        Some(U::Seconds),
        P::Measured,
        true,
        "Seconds since this controller's error counters were last reset, from the EDAC subsystem.",
    );
    e(add, "memory.ecc.controller.{n}.csrow.<none>", K::Diagnostic, None, P::Unavailable, true,
      "Present when this memory controller lists no csrow, carrying why. A csrow is a rank group that EDAC reports DIMMs through.");
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.label",
        K::Identity,
        Some(U::Text),
        P::Measured,
        true,
        "Label EDAC gives this csrow's DIMM, such as DIMM_A1 or a platform-specific name.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.mem_type",
        K::Identity,
        Some(U::Identifier),
        P::Measured,
        true,
        "Memory type the csrow's DIMM reports to EDAC, such as DDR4 or DDR5.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.size",
        K::Limit,
        Some(U::Bytes),
        P::Measured,
        true,
        "Size of the memory this csrow covers, in bytes, as sysfs reports it.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.ce_count",
        K::Measurement,
        Some(U::Count),
        P::Measured,
        true,
        "Correctable errors counted against this csrow since its last reset.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.ue_count",
        K::Measurement,
        Some(U::Count),
        P::Measured,
        true,
        "Uncorrectable errors counted against this csrow since its last reset.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.location",
        K::Identity,
        Some(U::Text),
        P::Measured,
        true,
        "Channel and slot location of this csrow's DIMM, as EDAC reports it.",
    );
    e(
        add,
        "memory.ecc.controller.{n}.csrow.{m}.grain",
        K::Limit,
        Some(U::Bytes),
        P::Measured,
        true,
        "Error resolution of this csrow in bytes: the smallest span an error can be attributed to.",
    );

    // ── NUMA detail (NumaMonitor) ───────────────────────────────────────────
    e(
        add,
        "memory.numa.{n}.memory_free",
        K::Measurement,
        Some(U::Bytes),
        P::Measured,
        true,
        "Free memory on this NUMA node, in bytes, at the time of the reading.",
    );
    e(
        add,
        "memory.numa.{n}.memory_used",
        K::Measurement,
        Some(U::Bytes),
        P::Measured,
        true,
        "Memory in use on this NUMA node, in bytes, at the time of the reading.",
    );
    e(add, "memory.numa.{n}.hugepages_total", K::Limit, Some(U::Count), P::Measured, true,
      "Huge pages configured on this NUMA node. Absent on platforms that do not report huge pages per node.");
    e(add, "memory.numa.{n}.hugepages_free", K::Measurement, Some(U::Count), P::Measured, true,
      "Huge pages on this NUMA node that are not in use. Absent on platforms that do not report huge pages per node.");
    e(
        add,
        "memory.numa.distance.<none>",
        K::Diagnostic,
        None,
        P::Unavailable,
        true,
        "Present when the platform exposed no NUMA distance matrix, carrying why.",
    );
    e(add, "memory.numa.{n}.distance.{m}", K::Measurement, Some(U::Count), P::Specification, true,
      "Relative cost of memory access from NUMA node n to node m, from the firmware distance table. A node's distance to itself is its local figure.");
}

/// A derived reading when its inputs were read, otherwise unavailable with the reason.
fn push_derived_opt(
    out: &mut Vec<Reading>,
    id: &str,
    value: Option<serde_json::Value>,
    unit: Option<U>,
    why: &str,
) {
    match value {
        Some(v) => out.push(Reading::derived(id, v, unit)),
        None => out.push(Reading::unavailable(id, unit, why)),
    }
}

pub(super) fn resolve(out: &mut Vec<Reading>) {
    // One topology monitor for the DIMM detail and the analysis.
    match crate::memory_topology::MemoryTopologyMonitor::new() {
        Ok(monitor) => {
            let topology = monitor.topology();
            resolve_dimm_detail(out, &topology.dimms);
            resolve_analysis(out, topology);
        }
        Err(e) => {
            let why = format!("memory topology unavailable: {e}");
            for id in [
                "memory.topology.total_slots",
                "memory.topology.populated_slots",
                "memory.topology.channel_count",
                "memory.topology.dual_channel",
                "memory.topology.matched_speeds",
                "memory.topology.matched_capacities",
                "memory.topology.max_capacity_bytes",
            ] {
                let unit = match id {
                    "memory.topology.max_capacity_bytes" => Some(U::Bytes),
                    "memory.topology.dual_channel"
                    | "memory.topology.matched_speeds"
                    | "memory.topology.matched_capacities" => None,
                    _ => Some(U::Count),
                };
                out.push(Reading::unavailable(id, unit, why.clone()));
            }
        }
    }

    resolve_ecc(out);
    resolve_numa(out);
}

fn resolve_dimm_detail(out: &mut Vec<Reading>, dimms: &[DimmInfo]) {
    for (i, dimm) in dimms.iter().enumerate() {
        let base = format!("memory.dimm.{i}");
        let empty = dimm.populated == Some(false);

        push_spec_text(out, format!("{base}.bank"), &dimm.bank);
        push_spec_text(
            out,
            format!("{base}.form_factor"),
            &dimm.form_factor.to_string(),
        );

        if empty {
            for suffix in ["serial_number", "ranks"] {
                out.push(Reading::unavailable(
                    format!("{base}.{suffix}"),
                    if suffix == "ranks" {
                        Some(U::Count)
                    } else {
                        Some(U::Identifier)
                    },
                    "this slot is empty",
                ));
            }
        } else {
            push_spec_text(out, format!("{base}.serial_number"), &dimm.serial_number);
            push_spec_opt(
                out,
                format!("{base}.ranks"),
                dimm.ranks.map(|r| serde_json::json!(r)),
                Some(U::Count),
                "the module's SMBIOS record carried no rank count",
            );
        }
    }
}

fn resolve_analysis(out: &mut Vec<Reading>, topology: &MemoryTopology) {
    let a = &topology.analysis;

    push_spec_opt(
        out,
        "memory.topology.total_slots",
        a.total_slots.map(|n| serde_json::json!(n)),
        Some(U::Count),
        "the reader's source lists installed modules only, so the number of slots was not read",
    );

    if topology.dimms.is_empty() {
        out.push(Reading::unavailable(
            "memory.topology.populated_slots",
            Some(U::Count),
            "the topology reader listed no memory slots",
        ));
    } else {
        out.push(Reading::derived(
            "memory.topology.populated_slots",
            serde_json::json!(a.populated_slots),
            Some(U::Count),
        ));
    }

    push_derived_opt(
        out,
        "memory.topology.channel_count",
        a.channel_count.map(|n| serde_json::json!(n)),
        Some(U::Count),
        "no DIMM locator names a memory channel, so the channel count is not established",
    );
    push_derived_opt(
        out,
        "memory.topology.dual_channel",
        a.dual_channel.map(|b| serde_json::json!(b)),
        None,
        "the channel count was not read, so dual-channel operation is not established",
    );
    push_derived_opt(
        out,
        "memory.topology.matched_speeds",
        a.matched_speeds.map(|b| serde_json::json!(b)),
        None,
        "fewer than two DIMM speeds were read, so there is nothing to match",
    );
    push_derived_opt(
        out,
        "memory.topology.matched_capacities",
        a.matched_capacities.map(|b| serde_json::json!(b)),
        None,
        "fewer than two DIMM capacities were read, so there is nothing to match",
    );

    // Why it is unknown depends on the platform, and says so: a root-only read
    // on Linux, a WMI array with no capacity on Windows, and no such figure on
    // macOS.
    let max_why = if cfg!(target_os = "linux") {
        "the board's maximum is in the SMBIOS type 16 record, which dmidecode reads only as root, and this run did not read it"
    } else if cfg!(target_os = "windows") {
        "no system-memory Win32_PhysicalMemoryArray reported a usable capacity"
    } else {
        "this platform publishes no board maximum capacity"
    };
    push_spec_opt(
        out,
        "memory.topology.max_capacity_bytes",
        a.max_capacity_bytes.map(|b| serde_json::json!(b)),
        Some(U::Bytes),
        max_why,
    );
}

fn resolve_ecc(out: &mut Vec<Reading>) {
    let monitor = match crate::edac::EdacMonitor::new() {
        Ok(m) => m,
        Err(e) => {
            // Windows and macOS have no EDAC interface, so this is the common path.
            out.push(Reading::unavailable(
                "memory.ecc.controller.<none>",
                None,
                format!("no ECC error reporting interface is available here: {e}"),
            ));
            return;
        }
    };

    let controllers = monitor.controllers();
    if controllers.is_empty() {
        out.push(Reading::unavailable(
            "memory.ecc.controller.<none>",
            None,
            "the EDAC interface exists but lists no memory controller",
        ));
        return;
    }

    for c in controllers {
        let base = format!("memory.ecc.controller.{}", c.index);
        push_opt(
            out,
            format!("{base}.mc_name"),
            c.mc_name.as_ref().map(|n| serde_json::json!(n)),
            Some(U::Identifier),
            "this controller's driver name could not be read",
        );
        push_opt(
            out,
            format!("{base}.ce_count"),
            c.ce_count.map(|v| serde_json::json!(v)),
            Some(U::Count),
            "this controller's correctable-error counter could not be read",
        );
        push_opt(
            out,
            format!("{base}.ue_count"),
            c.ue_count.map(|v| serde_json::json!(v)),
            Some(U::Count),
            "this controller's uncorrectable-error counter could not be read",
        );
        push_opt(
            out,
            format!("{base}.ce_noinfo_count"),
            c.ce_noinfo_count.map(|v| serde_json::json!(v)),
            Some(U::Count),
            "this controller's count of unattributed correctable errors could not be read",
        );
        push_opt(
            out,
            format!("{base}.ue_noinfo_count"),
            c.ue_noinfo_count.map(|v| serde_json::json!(v)),
            Some(U::Count),
            "this controller's count of unattributed uncorrectable errors could not be read",
        );
        push_opt(
            out,
            format!("{base}.seconds_since_reset"),
            c.seconds_since_reset.map(|v| serde_json::json!(v)),
            Some(U::Seconds),
            "the controller did not report how long its error counters have run",
        );

        if c.csrows.is_empty() {
            out.push(Reading::unavailable(
                format!("{base}.csrow.<none>"),
                None,
                "this controller lists no csrow, the rank groups EDAC reports DIMMs through",
            ));
        }
        for r in &c.csrows {
            let rb = format!("{base}.csrow.{}", r.index);
            // `None` when EDAC has no label file for this csrow or DIMM. The
            // directory index used to be published here in its place.
            push_opt(
                out,
                format!("{rb}.label"),
                r.label.as_deref().map(|l| serde_json::json!(l)),
                Some(U::Text),
                "EDAC reports no DIMM label for this csrow, and the label file is absent or empty",
            );
            push_id(out, format!("{rb}.mem_type"), &r.mem_type.to_string());
            push_opt(
                out,
                format!("{rb}.size"),
                r.size_mb
                    .and_then(|mb| mb.checked_mul(1024 * 1024))
                    .map(|v| serde_json::json!(v)),
                Some(U::Bytes),
                "sysfs reported no size for this csrow",
            );
            push_opt(
                out,
                format!("{rb}.ce_count"),
                r.ce_count.map(|v| serde_json::json!(v)),
                Some(U::Count),
                "this csrow's correctable-error counter could not be read",
            );
            push_opt(
                out,
                format!("{rb}.ue_count"),
                r.ue_count.map(|v| serde_json::json!(v)),
                Some(U::Count),
                "this csrow's uncorrectable-error counter could not be read",
            );
            push_text(out, format!("{rb}.location"), &r.location);
            push_opt(
                out,
                format!("{rb}.grain"),
                r.grain.map(|v| serde_json::json!(v)),
                Some(U::Bytes),
                "the grain size of this csrow could not be read",
            );
        }
    }
}

fn resolve_numa(out: &mut Vec<Reading>) {
    // On failure the base resolver has already reported the NUMA rows as unavailable.
    let Ok(monitor) = crate::numa::NumaMonitor::new() else {
        return;
    };

    for node in monitor.nodes() {
        let base = format!("memory.numa.{}", node.id);
        push_opt(
            out,
            format!("{base}.memory_free"),
            node.memory_free_bytes.map(|v| serde_json::json!(v)),
            Some(U::Bytes),
            "the platform reported no free memory figure for this node",
        );
        push_opt(
            out,
            format!("{base}.memory_used"),
            node.memory_used_bytes.map(|v| serde_json::json!(v)),
            Some(U::Bytes),
            "the platform reported no used memory figure for this node",
        );
        push_opt(
            out,
            format!("{base}.hugepages_total"),
            node.hugepages_total.map(|v| serde_json::json!(v)),
            Some(U::Count),
            "this platform does not report huge pages per NUMA node",
        );
        push_opt(
            out,
            format!("{base}.hugepages_free"),
            node.hugepages_free.map(|v| serde_json::json!(v)),
            Some(U::Count),
            "this platform does not report huge pages per NUMA node",
        );
    }

    match monitor.distance_matrix() {
        Some(matrix) => {
            for from in 0..matrix.size {
                for to in 0..matrix.size {
                    push_opt(
                        out,
                        format!("memory.numa.{from}.distance.{to}"),
                        matrix.distance(from, to).map(|d| serde_json::json!(d)),
                        Some(U::Count),
                        "the distance matrix has no entry for this pair of nodes",
                    );
                }
            }
        }
        None => out.push(Reading::unavailable(
            "memory.numa.distance.<none>",
            None,
            "the platform exposed no NUMA distance matrix, so inter-node distances were not read",
        )),
    }
}