monitord 0.18.0

monitord ... know how happy your systemd is! 😊
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>monitord - know how happy your systemd is!</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;600&display=swap" rel="stylesheet">
  <style>
    /* Color variables matching systemd.io */
    :root {
      --sd-brand-black: hsl(270, 19%, 13%);
      --sd-brand-green: hsl(145, 66%, 51%);
      --sd-brand-white: #fff;

      --sd-black: hsl(270, 7%, 13%);
      --sd-green: hsl(145, 66%, 43%);
      --sd-gray-extralight: hsl(30, 10%, 96%);
      --sd-gray-light: hsl(30, 10%, 92%);
      --sd-gray: hsl(30, 10%, 85%);
      --sd-gray-dark: hsl(257, 23%, 20%);
      --sd-gray-extradark: hsl(257, 23%, 16%);

      --sd-font-weight-normal: 400;
      --sd-font-weight-bold: 600;

      /* Light mode */
      --sd-foreground-color: var(--sd-gray-extradark);
      --sd-background-color: var(--sd-gray-extralight);
      --sd-link-color: var(--sd-green);
      --sd-link-font-weight: var(--sd-font-weight-bold);
    }

    @media (prefers-color-scheme: dark) {
      :root {
        color-scheme: dark;
        --sd-foreground-color: var(--sd-gray);
        --sd-background-color: var(--sd-black);
        --sd-link-color: var(--sd-brand-green);
        --sd-link-font-weight: var(--sd-font-weight-normal);
      }
    }

    /* Typography */
    * {
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
    }
    html, body {
      margin: 0;
      padding: 0;
      font-size: 1rem;
      font-family: "Heebo", sans-serif;
      font-weight: 400;
      line-height: 1.6;
    }
    body {
      color: var(--sd-foreground-color);
      background-color: var(--sd-background-color);
    }

    /* Layout */
    .container {
      width: 80%;
      max-width: 720px;
      margin: 0 auto;
      text-align: center;
    }

    /* Logo */
    .page-logo {
      display: block;
      padding: 5rem 0 3rem;
      color: var(--sd-foreground-color);
    }
    .page-logo > svg {
      display: block;
      width: 16em;
      height: auto;
      margin: 0 auto;
    }

    /* Heading */
    h1 {
      text-align: center;
      font-size: 1.87rem;
      font-weight: 400;
      font-style: normal;
      margin: 0 0 2rem;
      line-height: 1.25;
    }
    @media screen and (min-width: 650px) {
      h1 {
        font-size: 2.375em;
      }
    }

    /* Horizontal rule */
    hr {
      margin: 3rem auto 4rem;
      width: 40%;
      opacity: 40%;
    }

    /* Links */
    a {
      font-weight: var(--sd-link-font-weight);
      text-decoration: none;
      color: var(--sd-link-color);
      cursor: pointer;
    }
    a:hover {
      text-decoration: underline;
    }

    /* Link list */
    ul {
      list-style: disc;
      display: inline-block;
      text-align: left;
      padding-left: 1.5em;
      margin: 0;
    }
    li {
      margin: 0.25em 0;
      font-size: 1.1rem;
    }

    /* README content */
    .readme-content {
      text-align: left;
      margin-top: 2rem;
    }
    .readme-content h2 {
      font-size: 1.25rem;
      margin-top: 2.5em;
    }
    .readme-content h3 {
      font-size: 1.15rem;
    }
    .readme-content h4 {
      font-size: 1.05rem;
    }
    .readme-content p {
      margin: 0.75em 0;
    }
    .readme-content ul, .readme-content ol {
      display: block;
      padding-left: 2em;
      margin: 0.75em 0;
    }
    .readme-content li {
      font-size: 1rem;
    }
    .readme-content pre {
      padding: 1em;
      border-radius: 5px;
      overflow-x: auto;
      background-color: var(--sd-highlight-bg, rgba(255, 255, 255, 1));
    }
    .readme-content code {
      font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
      font-size: 0.875rem;
    }
    .readme-content p code,
    .readme-content li code {
      padding: 2px 6px;
      border-radius: 3px;
      background-color: var(--sd-highlight-inline-bg, rgba(0, 0, 0, 0.07));
    }
    .readme-content pre code {
      padding: 0;
      background-color: transparent;
    }
    .readme-content strong {
      font-weight: 600;
    }

    @media (prefers-color-scheme: light) {
      .readme-content pre {
        background-color: rgba(255, 255, 255, 1);
      }
      .readme-content p code,
      .readme-content li code {
        background-color: rgba(0, 0, 0, 0.07);
      }
    }
    @media (prefers-color-scheme: dark) {
      .readme-content pre {
        background-color: rgba(0, 0, 0, 0.6);
      }
      .readme-content p code,
      .readme-content li code {
        background-color: rgba(255, 255, 255, 0.1);
      }
    }

    /* Footer */
    footer {
      text-align: center;
      padding: 3em 0 3em;
      font-size: 1em;
      margin-top: 4rem;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="page-logo">
      <svg role="img" aria-label="monitord logo" width="800" height="200" viewBox="0 0 800 200" xmlns="http://www.w3.org/2000/svg">
        <path fill="currentColor" d="M 34 40 L 50 40 C 51.104568 40 52 40.895432 52 42 L 52 158 C 52 159.104568 51.104568 160 50 160 L 34 160 C 32.895432 160 32 159.104568 32 158 L 32 42 C 32 40.895432 32.895432 40 34 40 Z"/>
        <path fill="currentColor" d="M 34 40 L 65 40 C 66.104568 40 67 40.895432 67 42 L 67 58 C 67 59.104568 66.104568 60 65 60 L 34 60 C 32.895432 60 32 59.104568 32 58 L 32 42 C 32 40.895432 32.895432 40 34 40 Z"/>
        <path fill="currentColor" d="M 34 140 L 65 140 C 66.104568 140 67 140.895432 67 142 L 67 158 C 67 159.104568 66.104568 160 65 160 L 34 160 C 32.895432 160 32 159.104568 32 158 L 32 142 C 32 140.895432 32.895432 140 34 140 Z"/>
        <text x="87" y="130" font-family="Helvetica" font-size="68" fill="#30d158">1</text>
        <path fill="#ff453a" stroke="#ff453a" stroke-width="6" d="M 173 85 C 173 94.941124 164.941132 103 155 103 C 145.058868 103 137 94.941124 137 85 C 137 75.058876 145.058868 67 155 67 C 164.941132 67 173 75.058876 173 85 Z"/>
        <path fill="#000000" stroke="#ff453a" stroke-width="8" stroke-linecap="round" d="M 168 98 L 185 115"/>
        <path fill="currentColor" d="M 220 40 L 236 40 C 237.104568 40 238 40.895432 238 42 L 238 158 C 238 159.104568 237.104568 160 236 160 L 220 160 C 218.895432 160 218 159.104568 218 158 L 218 42 C 218 40.895432 218.895432 40 220 40 Z"/>
        <path fill="currentColor" d="M 205 40 L 236 40 C 237.104568 40 238 40.895432 238 42 L 238 58 C 238 59.104568 237.104568 60 236 60 L 205 60 C 203.895432 60 203 59.104568 203 58 L 203 42 C 203 40.895432 203.895432 40 205 40 Z"/>
        <path fill="currentColor" d="M 205 140 L 236 140 C 237.104568 140 238 140.895432 238 142 L 238 158 C 238 159.104568 237.104568 160 236 160 L 205 160 C 203.895432 160 203 159.104568 203 158 L 203 142 C 203 140.895432 203.895432 140 205 140 Z"/>
        <text x="279" y="132" font-family="Helvetica" font-size="72" fill="currentColor">monitord</text>
      </svg>
    </div>

    <h1>monitord ... know how happy your systemd is! <span role="img" aria-label="smiling face">😊</span></h1>

    <hr>

    <ul>
      <li><a href="https://github.com/cooperlees/monitord">GitHub</a></li>
      <li><a href="https://crates.io/crates/monitord">monitord on crates.io</a></li>
      <li><a href="https://crates.io/crates/monitord-exporter">monitord-exporter on crates.io</a></li>
      <li><a href="monitord/index.html">Rust Docs</a></li>
    </ul>

    <hr>

    <div class="readme-content">
      <p>We offer the following run modes:</p>
<ul>
<li>systemd-timer (legacy cron would work too)</li>
<li>Refer to monitord.timer and monitord.service unit files</li>
<li>Ensure no <code>daemon:</code> mode options are set in <code>monitord.conf</code></li>
<li>daemon mode</li>
<li>Enable daemon mode in configuration file</li>
<li>Stats will be written to stdout every <code>daemon_stats_refresh_secs</code></li>
</ul>
<p>Open to more formats / run methods ... Open an issue to discuss. Depends on the dependencies basically.</p>
<p><code>monitord</code> is a config driven binary. We plan to keep CLI arguments to a minimum.</p>
<p><strong>INFO</strong> level logging is enabled to stderr by default. Use <code>-l LEVEL</code> to increase or decrease logging.</p>
<h2>Install</h2>
<p>Install via cargo or use as a dependency in your <code>Cargo.toml</code>.</p>
<ul>
<li><code>cargo install monitord</code></li>
<li>Create (copy from repo) a <code>monitord.conf</code></li>
<li>Defaults to looking for it at /etc/monitord.conf</li>
<li><code>monitord --help</code></li>
</ul>
<pre><code class="language-console">crl-linux:monitord cooper$ monitord --help
monitord: Know how happy your systemd is! 😊

Usage: monitord [OPTIONS]

Options:
  -c, --config &lt;CONFIG&gt;
          Location of your monitord config

          [default: /etc/monitord.conf]

  -l, --log-level &lt;LOG_LEVEL&gt;
          Adjust the console log-level

          [default: Info]
          [possible values: error, warn, info, debug, trace]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version
</code></pre>
<h3>Config</h3>
<p>monitord can have the different components monitored. To enable / disabled set the
following in our monitord.conf. This file is <a href="https://en.wikipedia.org/wiki/INI_file">ini format</a>
to match systemd unit files.</p>
<pre><code class="language-ini"># Pure ini - no yes/no for bools

[monitord]
# Set a custom dbus address to connect to
# OPTIONAL: If not set, we default to the Unix socket below
dbus_address = unix:path=/run/dbus/system_bus_socket
# Timeout in seconds for dbus connection/collections
# OPTIONAL: default is 30 seconds
dbus_timeout = 30
# Run as a daemon or 1 time
daemon = false
# Time to refresh systemd stats in seconds
# Daemon mode only
daemon_stats_refresh_secs = 60
# Prefix flat-json key with this value
# The value automatically gets a '.' appended (so don't put here)
key_prefix = monitord
# cron/systemd timer output format
# Supported: json, json-flat, json-pretty
output_format = json

# Grab as much stats from DBus GetStats call
# we can from running dbus daemon
# More tested on dbus-broker daemon
[dbus]
# Summary counters - both dbus-broker + dbus-daemon
enabled = false
# dbus.user.* metrics: user stats as reported by dbus-broker
user_stats = false
# dbus.oeer.* metrics: peer stats as reported by dbus-broker
peer_stats = false
# dbus.cgroup.* stats is an aggregation of peer_stats by cgroup
# by dbus-broker
cgroup_stats = false

# Grab networkd stats from files + networkctl
[networkd]
enabled = true
link_state_dir = /run/systemd/netif/links

# Enable grabbing PID 1 stats via procfs
[pid1]
enabled = true

# Services to grab extra stats for
# .service is important as that's what DBus returns from `list_units`
[services]
foo.service

[timers]
enabled = true

[timers.allowlist]
foo.timer

[timers.blocklist]
bar.timer

# Grab unit status counts via dbus
[units]
enabled = true
state_stats = true

# Filter what services you want collect state stats for
# If both lists are configured blocklist is preferred
# If neither exist all units state will generate counters
[units.state_stats.allowlist]
foo.service

[units.state_stats.blocklist]
bar.service

# machines config
[machines]
enabled = true

# Same rules apply as state_stats lists above
[machines.allowlist]
foo

[machines.blocklist]
bar

# Boot blame metrics - shows the N slowest units at boot
# Similar to `systemd-analyze blame`
# Disabled by default
[boot]
enabled = false
# Number of slowest units to report
num_slowest_units = 5

# Optional: only include specific units in boot blame (if empty, all units are checked)
# Same rules apply as state_stats lists above
[boot.allowlist]
# slow-startup.service

# Optional: exclude specific units from boot blame
[boot.blocklist]
# noisy-but-expected.service

# Unit verification using systemd-analyze verify
# Disabled by default as it can be slow on large systems
[verify]
enabled = false

# Optional: only verify specific units (if empty, all units are checked)
[verify.allowlist]
# example.service
# example.timer

# Optional: skip verification for specific units
[verify.blocklist]
# noisy.service
# broken.timer
</code></pre>
<h2>Machines support</h2>
<p>From version <code>&gt;=0.11</code> monitord supports obtaining the same set of key from
systemd 'machines' (i.e. <code>machinectl --list</code>).</p>
<p>The keys are the same format as below in <code>json_flat</code> output but are prefixed with
the <code>machine</code> keyword and machine name. For example:</p>
<pre><code class="language-json"># $KEY_PREFIX.machine.$MACHINE_NAME
{
  ...
  &quot;monitord.machine.foo.pid1.fd_count&quot;: 69,
  ...
}
</code></pre>
<h2>Output Formats</h2>
<h3>json</h3>
<p>Normal <code>serde_json</code> non pretty JSON. All on one line. Most compact format.</p>
<h3>json-flat</h3>
<p>Move all key value pairs to the top level and . notate compononets + sub values.
Is semi pretty too + custom. All unittested ...</p>
<pre><code class="language-json">{
  &quot;boot.blame.dnf5-automatic.service&quot;: 204.159,
  &quot;boot.blame.cpe_chef.service&quot;: 103.05,
  &quot;boot.blame.sys-module-fuse.device&quot;: 16.21,
  &quot;boot.blame.dev-ttyS0.device&quot;: 15.809,
  &quot;boot.blame.systemd-networkd-wait-online.service&quot;: 1.674,
  &quot;dbus.active_connections&quot;: 10,
  &quot;dbus.bus_names&quot;: 16,
  &quot;dbus.incomplete_connections&quot;: 0,
  &quot;dbus.match_rules&quot;: 26,
  &quot;dbus.peak_bus_names&quot;: 33,
  &quot;dbus.peak_bus_names_per_connection&quot;: 2,
  &quot;dbus.peak_match_rules&quot;: 33,
  &quot;dbus.peak_match_rules_per_connection&quot;: 13,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.activation_request_bytes&quot;: 0,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.activation_request_fds&quot;: 0,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.incoming_bytes&quot;: 16,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.incoming_fds&quot;: 0,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.match_bytes&quot;: 6942,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.matches&quot;: 5,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.name_objects&quot;: 1,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.outgoing_bytes&quot;: 0,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.outgoing_fds&quot;: 0,
  &quot;dbus.cgroup.system.slice-systemd-logind.service.reply_objects&quot;: 0,
  &quot;dbus.peer.org.freedesktop.systemd1.activation_request_bytes&quot;: 0,
  &quot;dbus.peer.org.freedesktop.systemd1.activation_request_fds&quot;: 0,
  &quot;dbus.peer.org.freedesktop.systemd1.incoming_bytes&quot;: 16,
  &quot;dbus.peer.org.freedesktop.systemd1.incoming_fds&quot;: 0,
  &quot;dbus.peer.org.freedesktop.systemd1.match_bytes&quot;: 46533,
  &quot;dbus.peer.org.freedesktop.systemd1.matches&quot;: 33,
  &quot;dbus.peer.org.freedesktop.systemd1.name_objects&quot;: 1,
  &quot;dbus.peer.org.freedesktop.systemd1.outgoing_bytes&quot;: 0,
  &quot;dbus.peer.org.freedesktop.systemd1.outgoing_fds&quot;: 0,
  &quot;dbus.peer.org.freedesktop.systemd1.reply_objects&quot;: 0,
  &quot;dbus.user.cooper.bytes&quot;: 919236,
  &quot;dbus.user.cooper.fds&quot;: 78,
  &quot;dbus.user.cooper.matches&quot;: 510,
  &quot;dbus.user.cooper.objects&quot;: 80,
  &quot;networkd.eno4.address_state&quot;: 3,
  &quot;networkd.eno4.admin_state&quot;: 4,
  &quot;networkd.eno4.carrier_state&quot;: 5,
  &quot;networkd.eno4.ipv4_address_state&quot;: 3,
  &quot;networkd.eno4.ipv6_address_state&quot;: 2,
  &quot;networkd.eno4.oper_state&quot;: 9,
  &quot;networkd.eno4.required_for_online&quot;: 1,
  &quot;networkd.managed_interfaces&quot;: 2,
  &quot;networkd.wg0.address_state&quot;: 3,
  &quot;networkd.wg0.admin_state&quot;: 4,
  &quot;networkd.wg0.carrier_state&quot;: 5,
  &quot;networkd.wg0.ipv4_address_state&quot;: 3,
  &quot;networkd.wg0.ipv6_address_state&quot;: 3,
  &quot;networkd.wg0.oper_state&quot;: 9,
  &quot;networkd.wg0.required_for_online&quot;: 1,
  &quot;pid1.cpu_time_kernel&quot;: 48,
  &quot;pid1.cpu_user_kernel&quot;: 41,
  &quot;pid1.fd_count&quot;: 245,
  &quot;pid1.memory_usage_bytes&quot;: 19165184,
  &quot;pid1.tasks&quot;: 1,
  &quot;services.chronyd.service.active_enter_timestamp&quot;: 1683556542382710,
  &quot;services.chronyd.service.active_exit_timestamp&quot;: 0,
  &quot;services.chronyd.service.cpuusage_nsec&quot;: 328951000,
  &quot;services.chronyd.service.inactive_exit_timestamp&quot;: 1683556541360626,
  &quot;services.chronyd.service.ioread_bytes&quot;: 18446744073709551615,
  &quot;services.chronyd.service.ioread_operations&quot;: 18446744073709551615,
  &quot;services.chronyd.service.memory_available&quot;: 18446744073709551615,
  &quot;services.chronyd.service.memory_current&quot;: 5214208,
  &quot;services.chronyd.service.nrestarts&quot;: 0,
  &quot;services.chronyd.service.restart_usec&quot;: 100000,
  &quot;services.chronyd.service.state_change_timestamp&quot;: 1683556542382710,
  &quot;services.chronyd.service.status_errno&quot;: 0,
  &quot;services.chronyd.service.tasks_current&quot;: 1,
  &quot;services.chronyd.service.timeout_clean_usec&quot;: 18446744073709551615,
  &quot;services.chronyd.service.watchdog_usec&quot;: 0,
  &quot;system-state&quot;: 3,
  &quot;timers.fstrim.timer.accuracy_usec&quot;: 3600000000,
  &quot;timers.fstrim.timer.fixed_random_delay&quot;: 0,
  &quot;timers.fstrim.timer.last_trigger_usec&quot;: 1743397269608978,
  &quot;timers.fstrim.timer.last_trigger_usec_monotonic&quot;: 0,
  &quot;timers.fstrim.timer.next_elapse_usec_monotonic&quot;: 0,
  &quot;timers.fstrim.timer.next_elapse_usec_realtime&quot;: 1744007133996149,
  &quot;timers.fstrim.timer.persistent&quot;: 1,
  &quot;timers.fstrim.timer.randomized_delay_usec&quot;: 6000000000,
  &quot;timers.fstrim.timer.remain_after_elapse&quot;: 1,
  &quot;timers.fstrim.timer.service_unit_last_state_change_usec&quot;: 1743517244700135,
  &quot;timers.fstrim.timer.service_unit_last_state_change_usec_monotonic&quot;: 639312703,
  &quot;unit_states.chronyd.service.active_state&quot;: 1,
  &quot;unit_states.chronyd.service.loaded_state&quot;: 1,
  &quot;unit_states.chronyd.service.unhealthy&quot;: 0,
  &quot;units.activating_units&quot;: 0,
  &quot;units.active_units&quot;: 403,
  &quot;units.automount_units&quot;: 1,
  &quot;units.device_units&quot;: 150,
  &quot;units.failed_units&quot;: 0,
  &quot;units.inactive_units&quot;: 159,
  &quot;units.jobs_queued&quot;: 0,
  &quot;units.loaded_units&quot;: 497,
  &quot;units.masked_units&quot;: 25,
  &quot;units.mount_units&quot;: 52,
  &quot;units.not_found_units&quot;: 38,
  &quot;units.path_units&quot;: 4,
  &quot;units.scope_units&quot;: 17,
  &quot;units.service_units&quot;: 199,
  &quot;units.slice_units&quot;: 7,
  &quot;units.socket_units&quot;: 28,
  &quot;units.target_units&quot;: 54,
  &quot;units.timer_units&quot;: 20,
  &quot;units.total_units&quot;: 562,
  &quot;verify.failing.device&quot;: 43,
  &quot;verify.failing.mount&quot;: 15,
  &quot;verify.failing.service&quot;: 31,
  &quot;verify.failing.slice&quot;: 1,
  &quot;verify.failing.total&quot;: 97,
  &quot;version&quot;: &quot;255.7-1.fc40&quot;
}
</code></pre>
<h3>json-pretty</h3>
<p>Normal <code>serde_json</code> pretty representations of each components structs.</p>
<h2>dbus stats</h2>
<p>You're going to need to be root or allow permissiong to pull dbus stats.
For dbus-broker here is example config allow a user <code>monitord</code> to query
<code>getStats</code></p>
<pre><code class="language-xml">[cooper@l33t ~]# cat /etc/dbus-1/system.d/allow_monitord_stats.conf
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE busconfig PUBLIC
 &quot;-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN&quot;
 &quot;http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd&quot;&gt;
&lt;busconfig&gt;
  &lt;policy user=&quot;monitord&quot;&gt;
    &lt;allow send_destination=&quot;org.freedesktop.DBus&quot;
           send_interface=&quot;org.freedesktop.DBus.Debug.Stats&quot;
           send_member=&quot;GetStats&quot;
           send_path=&quot;/org/freedesktop/DBus&quot;
           send_type=&quot;method_call&quot;/&gt;
  &lt;/policy&gt;
&lt;/busconfig&gt;
</code></pre>
<h2>Development</h2>
<p>To do test runs (requires <code>systemd</code> and <code>systemd-networkd</code> <em>installed</em>)</p>
<ul>
<li>
<p>Pending what you have enabled in your config ...</p>
</li>
<li>
<p><code>cargo run -- -c monitord.conf -l debug</code></p>
</li>
</ul>
<p>Ensure the following pass before submitting a PR (CI checks):</p>
<ul>
<li><code>cargo test</code></li>
<li><code>cargo clippy</code></li>
<li><code>cargo fmt</code></li>
</ul>
<h3>Generate codegen APIs</h3>
<ul>
<li><code>cargo install zbus_xmlgen</code></li>
<li><code>zbus-xmlgen system org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/chronyd_2eservice</code></li>
</ul>
<p>Then add the following macros to tell clippy to go away:</p>
<pre><code class="language-rust">#![allow(warnings)]
#![allow(clippy)]
</code></pre>
<h3>Non Linux development</h3>
<p>Sometimes I develop from my Mac OS X laptop. So I thought I'd document and
add the way I build a Fedora Rawhide container and mount the local repo to /repo
in the container to run monitord and test.</p>
<ul>
<li>Build the image (w/git, rust tools and systemd)</li>
<li><code>docker build -t monitord-dev .</code></li>
<li>Start via systemd and mount the monitord repo to /repo</li>
<li><code>docker run --rm --name monitord-dev -it --privileged --tmpfs /run --tmpfs /tmp -v $(pwd):/repo monitord-dev /sbin/init</code><ul>
<li><code>--rm</code> is optional but will remove the container when stopped</li>
</ul>
</li>
</ul>
<p>You can now log into the container to build + run tests and run the binary now against systemd.</p>
<ul>
<li><code>docker exec -it monitord-dev bash</code></li>
<li><code>cd /repo ; cargo run -- -c monitord</code></li>
<li>networkd etc. are not running my default but can be started ...</li>
<li><code>systemctl start systemd-networkd</code><ul>
<li>No interfaces will be managed tho by default in the container ...</li>
</ul>
</li>
</ul>
<h2>API Usage</h2>
<h2>DBus</h2>
<p>All monitord's dbus is done via async (tokio) <a href="https://crates.io/crates/zbus">zbus</a> crate.</p>
<p>systemd Dbus APIs are in use in the following modules:</p>
<ul>
<li>machines</li>
<li><code>ManagerProxy::list_machines()</code></li>
<li>Can do most other calls then on the machine's systemd/dbus</li>
<li>networkd</li>
<li><code>ManagerProxy::list_links()</code></li>
<li>Would love to stop parsing <code>/run/systemd/netif/links</code> and replace via varlink API<ul>
<li>https://github.com/systemd/systemd/issues/36877</li>
</ul>
</li>
<li>system</li>
<li><code>ManagerProxy::get_version()</code></li>
<li><code>ManagerProxy::system_state()</code></li>
<li>timer</li>
<li><code>TimerProxy::unit()</code> - Find service unit of timer</li>
<li><code>ManagerProxy::get_unit()</code></li>
<li><code>UnitProxy::state_change_timestamp()</code></li>
<li><code>UnitProxy::state_change_timestamp_monotonic()</code></li>
<li>units</li>
<li><code>ManagerProxy::list_units()</code> - Main counting of unit stats</li>
<li><code>ServiceProxy::cpuusage_nsec()</code></li>
<li><code>ServiceProxy::ioread_bytes()</code></li>
<li><code>ServiceProxy::ioread_operations()</code></li>
<li><code>ServiceProxy::memory_current()</code></li>
<li><code>ServiceProxy::memory_available()</code></li>
<li><code>ServiceProxy::nrestarts()</code></li>
<li><code>ServiceProxy::get_processes()</code></li>
<li><code>ServiceProxy::restart_usec()</code></li>
<li><code>ServiceProxy::status_errno()</code></li>
<li><code>ServiceProxy::tasks_current()</code></li>
<li><code>ServiceProxy::timeout_clean_usec()</code></li>
<li><code>ServiceProxy::watchdog_usec()</code></li>
<li><code>UnitProxy::active_enter_timestamp</code></li>
<li><code>UnitProxy::active_exit_timestamp</code></li>
<li><code>UnitProxy::inactive_exit_timestamp()</code></li>
<li><code>UnitProxy::state_change_timestamp()</code> - Used for raw stat + time_in_state</li>
</ul>
<p>Some of these modules can be disabled via configuration. Due to this, monitord might not
always be running / calling all these DBus calls per run.</p>
<h2>Varlink</h2>
<p>None yet :(.</p>
<h3>varlink 101</h3>
<p>varlink might one day replace our DBUS usage. Here are some notes on how to work with systemd varlink
as there isn't really documentation outside <code>man</code> pages.</p>
<h4>Checking interfaces</h4>
<ul>
<li>varlinkctl is your friend - https://man7.org/linux/man-pages/man1/varlinkctl.1.html</li>
</ul>
<p>Here is an example with networkd's interfaces:</p>
<pre><code>varlinkctl info unix:/run/systemd/netif/io.systemd.Network
varlinkctl introspect unix:/run/systemd/netif/io.systemd.Network io.systemd.Network

cooper@au:~$ varlinkctl call unix:/run/systemd/netif/io.systemd.Network io.systemd.Network.GetStates '{}' -j | jq
{
  &quot;AddressState&quot;: &quot;routable&quot;,
  &quot;IPv4AddressState&quot;: &quot;routable&quot;,
  &quot;IPv6AddressState&quot;: &quot;routable&quot;,
  &quot;CarrierState&quot;: &quot;carrier&quot;,
  &quot;OnlineState&quot;: &quot;online&quot;,
  &quot;OperationalState&quot;: &quot;routable&quot;
}
</code></pre>
    </div>

    <footer>
      <small><a href="https://github.com/cooperlees/monitord">Website source on GitHub</a></small>
    </footer>
  </div>
</body>
</html>