Class: Fluent::Plugin::WindowsExporterInput

Inherits:
Input
  • Object
show all
Includes:
Constants
Defined in:
lib/fluent/plugin/in_windows_exporter.rb

Constant Summary

Constants included from Constants

Constants::PERF_100NSEC_TIMER, Constants::PERF_ELAPSED_TIME, Constants::PERF_PRECISION_100NS_TIMER, Constants::TICKS_TO_SECONDS_SCALE_FACTOR, Constants::WINDOWS_EPOCH

Instance Method Summary collapse

Instance Method Details

#collect_cpuObject



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
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 102

def collect_cpu
  hpd = @cache_manager.hkey_perf_data_cache
  counterset_name = "Processor Information"
  unless hpd.key?(counterset_name)
    $log.warn("Could not get HKeyPerfData CounterSet: #{counterset_name}")
    return []
  end

  records = []
  for core in hpd[counterset_name].instances do
    if core.name.downcase.include?("_total")
      next
    end
    records += [
      {
        "type" => "counter",
        "name" => "windows_cpu_cstate_seconds_total",
        "desc" => "Time spent in low-power idle state",
        "labels" => {"core" => core.name, "state" => "c1" },
        "value" => core.counters["% C1 Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_cstate_seconds_total",
        "desc" => "Time spent in low-power idle state",
        "labels" => {"core" => core.name, "state" => "c2" },
        "value" => core.counters["% C2 Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_cstate_seconds_total",
        "desc" => "Time spent in low-power idle state",
        "labels" => {"core" => core.name, "state" => "c3" },
        "value" => core.counters["% C3 Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_time_total",
        "desc" => "Time that processor spent in different modes (idle, user, system, ...)",
        "labels" => {"core" => core.name, "mode" => "idle"},
        "value" => core.counters["% Idle Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_time_total",
        "desc" => "Time that processor spent in different modes (idle, user, system, ...)",
        "labels" => {"core" => core.name, "mode" => "interrupt"},
        "value" => core.counters["% Interrupt Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_time_total",
        "desc" => "Time that processor spent in different modes (idle, user, system, ...)",
        "labels" => {"core" => core.name, "mode" => "dpc"},
        "value" => core.counters["% DPC Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_time_total",
        "desc" => "Time that processor spent in different modes (idle, user, system, ...)",
        "labels" => {"core" => core.name, "mode" => "privileged"},
        "value" => core.counters["% Privileged Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_time_total",
        "desc" => "Time that processor spent in different modes (idle, user, system, ...)",
        "labels" => {"core" => core.name, "mode" => "user"},
        "value" => core.counters["% User Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_interrupts_total",
        "desc" => "Total number of received and serviced hardware interrupts",
        "labels" => {"core" => core.name},
        "value" => core.counters["Interrupts/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_dpcs_total",
        "desc" => "Total number of received and serviced deferred procedure calls (DPCs)",
        "labels" => {"core" => core.name},
        "value" => core.counters["DPCs Queued/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_clock_interrupts_total",
        "desc" => "Total number of received and serviced clock tick interrupts",
        "labels" => {"core" => core.name},
        "value" => core.counters["Clock Interrupts/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_cpu_idle_break_events_total",
        "desc" => "Total number of time processor was woken from idle",
        "labels" => {"core" => core.name},
        "value" => core.counters["Idle Break Events/sec"].value
      },
      {
        "type" => "gauge",
        "name" => "windows_cpu_parking_status",
        "desc" => "Parking Status represents whether a processor is parked or not",
        "labels" => {"core" => core.name},
        "value" => core.counters["Parking Status"].value
      },
      {
        "type" => "gauge",
        "name" => "windows_cpu_core_frequency_mhz",
        "desc" => "Core frequency in megahertz",
        "labels" => {"core" => core.name},
        "value" => core.counters["Processor Frequency"].value
      },
      {
        "type" => "gauge",
        "name" => "windows_cpu_processor_performance",
        "desc" => "Processor Performance is the average performance of the processor while it is executing instructions, as a percentage of the nominal performance of the processor. On some processors, Processor Performance may exceed 100%",
        "labels" => {"core" => core.name},
        "value" => core.counters["% Processor Performance"].value
      }
    ]
  end
  return records
end

#collect_logical_diskObject



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
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 226

def collect_logical_disk
  hpd = @cache_manager.hkey_perf_data_cache
  counterset_name = "LogicalDisk"
  unless hpd.key?(counterset_name)
    $log.warn("Could not get HKeyPerfData CounterSet: #{counterset_name}")
    return []
  end

  records = []
  for volume in hpd[counterset_name].instances do
    if volume.name.downcase.include?("_total")
      next
    end

    records += [
      {
        "type" => "gauge",
        "name" => "windows_logical_disk_requests_queued",
        "desc" => "Number of requests outstanding on the disk at the time the performance data is collected",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Current Disk Queue Length"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_read_bytes_total",
        "desc" => "Rate at which bytes are transferred from the disk during read operations",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Disk Read Bytes/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_reads_total",
        "desc" => "Rate of read operations on the disk",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Disk Reads/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_write_bytes_total",
        "desc" => "Rate at which bytes are transferred to the disk during write operations",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Disk Write Bytes/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_writes_total",
        "desc" => "Rate of write operations on the disk",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Disk Writes/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_read_seconds_total",
        "desc" => "Seconds the disk was busy servicing read requests",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["% Disk Read Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_write_seconds_total",
        "desc" => "Seconds the disk was busy servicing write requests",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["% Disk Write Time"].value
      },
      {
        "type" => "gauge",
        "name" => "windows_logical_disk_free_bytes",
        "desc" => "Unused space of the disk in bytes (not real time, updates every 10-15 min)",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Free Megabytes"].value * 1024 * 1024
      },
      {
        "type" => "gauge",
        "name" => "windows_logical_disk_size_bytes",
        "desc" => "Total size of the disk in bytes (not real time, updates every 10-15 min)",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["% Free Space"].base_value * 1024 * 1024
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_idle_seconds_total",
        "desc" => "Seconds the disk was idle (not servicing read/write requests)",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["% Idle Time"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_split_ios_total",
        "desc" => "Number of I/Os to the disk split into multiple I/Os",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Split IO/Sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_read_latency_seconds_total",
        "desc" => "Shows the average time, in seconds, of a read operation from the disk",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Avg. Disk sec/Read"].value * TICKS_TO_SECONDS_SCALE_FACTOR
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_write_latency_seconds_total",
        "desc" => "Shows the average time, in seconds, of a write operation to the disk",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Avg. Disk sec/Write"].value * TICKS_TO_SECONDS_SCALE_FACTOR
      },
      {
        "type" => "counter",
        "name" => "windows_logical_disk_read_write_latency_seconds_total",
        "desc" => "Shows the time, in seconds, of the average disk transfer",
        "labels" => {"volume" => volume.name},
        "value" => volume.counters["Avg. Disk sec/Transfer"].value * TICKS_TO_SECONDS_SCALE_FACTOR
      }
    ]
  end
  return records
end

#collect_memoryObject



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
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 344

def collect_memory
  hpd = @cache_manager.hkey_perf_data_cache
  counterset_name = "Memory"
  unless hpd.key?(counterset_name)
    $log.warn("Could not get HKeyPerfData CounterSet: #{counterset_name}")
    return []
  end

  return [
    {
      "type" => "gauge",
      "name" => "windows_memory_available_bytes",
      "desc" => "The amount of physical memory immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to the standby (cached), free and zero page lists",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Available Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_cache_bytes",
      "desc" => "Number of bytes currently being used by the file system cache",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Cache Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_cache_bytes_peak",
      "desc" => "Maximum number of CacheBytes after the system was last restarted",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Cache Bytes Peak"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_cache_faults_total",
      "desc" => "Number of faults which occur when a page sought in the file system cache is not found there and must be retrieved from elsewhere in memory (soft fault) or from disk (hard fault)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Cache Faults/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_commit_limit",
      "desc" => "Amount of virtual memory, in bytes, that can be committed without having to extend the paging file(s)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Commit Limit"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_committed_bytes",
      "desc" => "Amount of committed virtual memory, in bytes",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Committed Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_demand_zero_faults_total",
      "desc" => "The number of zeroed pages required to satisfy faults. Zeroed pages, pages emptied of previously stored data and filled with zeros, are a security feature of Windows that prevent processes from seeing data stored by earlier processes that used the memory space",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Demand Zero Faults/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_free_and_zero_page_list_bytes",
      "desc" => "(FreeAndZeroPageListBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Free & Zero Page List Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_free_system_page_table_entries",
      "desc" => "Number of page table entries not being used by the system",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Free System Page Table Entries"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_modified_page_list_bytes",
      "desc" => "(ModifiedPageListBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Modified Page List Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_page_faults_total",
      "desc" => "Overall rate at which faulted pages are handled by the processor",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Page Faults/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_swap_page_reads_total",
      "desc" => "Number of disk page reads (a single read operation reading several pages is still only counted once)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Page Reads/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_swap_pages_read_total",
      "desc" => "Number of pages read across all page reads (ie counting all pages read even if they are read in a single operation)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pages Input/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_swap_pages_written_total",
      "desc" => "Number of pages written across all page writes (ie counting all pages written even if they are written in a single operation)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pages Output/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_swap_page_operations_total",
      "desc" => "Total number of swap page read and writes (PagesPersec)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pages/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_swap_page_writes_total",
      "desc" => "Number of disk page writes (a single write operation writing several pages is still only counted once)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Page Writes/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_pool_nonpaged_allocs_total",
      "desc" => "The number of calls to allocate space in the nonpaged pool. The nonpaged pool is an area of system memory area for objects that cannot be written to disk, and must remain in physical memory as long as they are allocated",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pool Nonpaged Allocs"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_pool_nonpaged_bytes_total",
      "desc" => "Number of bytes in the non-paged pool",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pool Nonpaged Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_pool_paged_allocs_total",
      "desc" => "Number of calls to allocate space in the paged pool, regardless of the amount of space allocated in each call",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pool Paged Allocs"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_pool_paged_bytes",
      "desc" => "Number of bytes in the paged pool",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pool Paged Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_pool_paged_resident_bytes",
      "desc" => "(PoolPagedResidentBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Pool Paged Resident Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_standby_cache_core_bytes",
      "desc" => "(StandbyCacheCoreBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Standby Cache Core Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_standby_cache_normal_priority_bytes",
      "desc" => "(StandbyCacheNormalPriorityBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Standby Cache Normal Priority Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_standby_cache_reserve_bytes",
      "desc" => "(StandbyCacheReserveBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Standby Cache Reserve Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_system_cache_resident_bytes",
      "desc" => "(SystemCacheResidentBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["System Cache Resident Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_system_code_resident_bytes",
      "desc" => "(SystemCodeResidentBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["System Code Resident Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_system_code_total_bytes",
      "desc" => "(SystemCodeTotalBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["System Code Total Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_system_driver_resident_bytes",
      "desc" => "(SystemDriverResidentBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["System Driver Resident Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_system_driver_total_bytes",
      "desc" => "(SystemDriverTotalBytes)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["System Driver Total Bytes"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_transition_faults_total",
      "desc" => "(TransitionFaultsPersec)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Transition Faults/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_transition_pages_repurposed_total",
      "desc" => "(TransitionPagesRePurposedPersec)",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Transition Pages RePurposed/sec"].value
    },
    {
      "type" => "gauge",
      "name" => "windows_memory_write_copies_total",
      "desc" => "The number of page faults caused by attempting to write that were satisfied by copying the page from elsewhere in physical memory",
      "labels" => {},
      "value" => hpd["Memory"].instances[0].counters["Write Copies/sec"].value
    }
  ]
end

#collect_netObject



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
678
679
680
681
682
683
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 580

def collect_net
  hpd = @cache_manager.hkey_perf_data_cache
  counterset_name = "Network Interface"
  unless hpd.key?(counterset_name)
    $log.warn("Could not get HKeyPerfData CounterSet: #{counterset_name}")
    return []
  end

  records = []
  for nic in hpd[counterset_name].instances do
    name = nic.name.gsub!(/[^a-zA-Z0-9]/, '_')
    if name == ""
      next
    end

    records += [
      {
        "type" => "counter",
        "name" => "windows_net_bytes_received_total",
        "desc" => "Total bytes received by interface",
        "labels" => {"nic": name},
        "value" => nic.counters["Bytes Received/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_bytes_sent_total",
        "desc" => "Total bytes transmitted by interface",
        "labels" => {"nic": name},
        "value" => nic.counters["Bytes Sent/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_bytes_total",
        "desc" => "Total bytes received and transmitted by interface",
        "labels" => {"nic": name},
        "value" => nic.counters["Bytes Total/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_outbound_discarded_total",
        "desc" => "Total outbound packets that were chosen to be discarded even though no errors had been detected to prevent transmission",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Outbound Discarded"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_outbound_errors_total",
        "desc" => "Total packets that could not be transmitted due to errors",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Outbound Errors"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_total",
        "desc" => "Total packets received and transmitted by interface",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_received_discarded_total",
        "desc" => "Total inbound packets that were chosen to be discarded even though no errors had been detected to prevent delivery",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Received Discarded"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_received_errors_total",
        "desc" => "Total packets that could not be received due to errors",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Received Errors"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_received_total",
        "desc" => "Total packets received by interface",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Received/sec"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_received_unknown_total",
        "desc" => "Total packets received by interface that were discarded because of an unknown or unsupported protocol",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Received Unknown"].value
      },
      {
        "type" => "counter",
        "name" => "windows_net_packets_sent_total",
        "desc" => "Total packets transmitted by interface",
        "labels" => {"nic": name},
        "value" => nic.counters["Packets Sent/sec"].value
      },
      {
        "type" => "gauge",
        "name" => "windows_net_current_bandwidth_bytes",
        "desc" => "Estimate of the interface's current bandwidth in bytes per second",
        "labels" => {"nic": name},
        "value" => nic.counters["Current Bandwidth"].value / 8
      }
    ]
  end
  return records
end

#collect_osObject



685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 685

def collect_os
  hpd = @cache_manager.hkey_perf_data_cache
  mem = @cache_manager.memory_status_cache
  work = @cache_manager.work_station_info_cache
  perf = @cache_manager.performance_info_cache
  reg = @cache_manager.registry_info_cache

  records = [
    {
      "type" => "gauge",
      "name" => "windows_os_info",
      "desc" => "Contains full product name & version in labels",
      "labels" => {
        :product => "Microsoft #{reg[:ProductName]}",
        :version => "#{work[:VersionMajor]}.#{work[:VersionMinor]}.#{reg[:CurrentBuildNumber]}"
      },
      "value" => 1.0
    },
    {
      "type" => "gauge",
      "name" => "windows_os_physical_memory_free_bytes",
      "desc" => "Bytes of physical memory currently unused and available",
      "labels" => {},
      "value" => mem[:AvailPhys]
    },
    {
      "type" => "gauge",
      "name" => "windows_os_time",
      "desc" => "Current time as reported by the operating system, in Unix time",
      "labels" => {},
      "value" => Fluent::EventTime.now.to_f
    },
    {
      "type" => "gauge",
      "name" => "windows_os_timezone",
      "desc" => "Current timezone as reported by the operating system",
      "labels" => {:timezone => Time.now.strftime("%z")},
      "value" => 1.0
    },
    {
      "type" => "gauge",
      "name" => "windows_os_virtual_memory_free_bytes",
      "desc" => "Bytes of virtual memory currently unused and available",
      "labels" => {},
      "value" => mem[:AvailPageFile]
    },
    {
      "type" => "gauge",
      "name" => "windows_os_processes_limit",
      "desc" => "Maximum number of process contexts the operating system can support. The default value set by the provider is 4294967295 (0xFFFFFFFF)",
      "labels" => {},
      # prometheus-community/windows-exporter/collector/os.go#L275
      "value" => 4294967295.0
    },
    {
      "type" => "gauge",
      "name" => "windows_os_process_memory_limit_bytes",
      "desc" => "Maximum number of bytes of memory that can be allocated to a process",
      "labels" => {},
      "value" => mem[:TotalVirtual]
    },
    {
      "type" => "gauge",
      "name" => "windows_os_processes",
      "desc" => "Number of process contexts currently loaded or running on the operating system",
      "labels" => {},
      "value" => perf[:ProcessCount]
    },
    {
      "type" => "gauge",
      "name" => "windows_os_users",
      "desc" => "Number of user sessions for which the operating system is storing state information currently. For a list of current active logon sessions.",
      "labels" => {},
      "value" => work[:LoggedOnUsers]
    },
    {
      "type" => "gauge",
      "name" => "windows_os_paging_limit_bytes",
      "desc" => "Total number of bytes that can be sotred in the operating system paging files. 0 (zero) indicates that there are no paging files",
      "labels" => {},
      "value" => reg[:PagingLimitBytes]
    },
    {
      "type" => "gauge",
      "name" => "windows_os_virtual_memory_bytes",
      "desc" => "Bytes of virtual memory",
      "labels" => {},
      "value" => mem[:TotalPageFile],
    },
    {
      "type" => "gauge",
      "name" => "windows_os_visible_memory_bytes",
      "desc" => "Total bytes of physical memory available to the operating system. This value does not necessarily indicate the true amount of physical memory, but what is reported to the operating system as available to it",
      "labels" => {},
      "value" => mem[:TotalPhys]
    }
  ]

  counterset_name = "Paging File"
  unless hpd.key?(counterset_name)
    $log.warn("Could not get HKeyPerfData CounterSet: #{counterset_name}")
    return records
  end

  pfusage = 0
  for ins in hpd[counterset_name].instances do
    unless ins.name.downcase.include?("_total")
      pfusage += ins.counters["% Usage"].value
    end
  end

  records += [
    {
      "type" => "gauge",
      "name" => "windows_os_paging_free_bytes",
      "desc" => "Number of bytes that can be mapped into the operating system paging files without causing any other pages to be swapped out",
      "labels" => {},
      "value" =>  reg[:PagingLimitBytes] - pfusage * perf[:PageSize]
    }
  ]

  return records
end

#configure(conf) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 57

def configure(conf)
  super
  @cache_manager = CacheManager.new

  @collectors = []
  @collectors << method(:collect_cpu) if @cpu
  @collectors << method(:collect_logical_disk) if @logical_disk
  @collectors << method(:collect_memory) if @memory
  @collectors << method(:collect_net) if @net
  @collectors << method(:collect_os) if @os
end

#on_timerObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 79

def on_timer
  now = Fluent::EventTime.now
  update_cache()
  $log.debug("Updated Windows counters (%.2fs)" % (Fluent::EventTime.now.to_f - now.to_f))

  es = Fluent::MultiEventStream.new
  for method in @collectors do
    begin
      for record in method.call() do
        es.add(now, record)
      end
    rescue => e
      $log.error(e.message)
      $log.error_backtrace
    end
  end
  router.emit_stream(@tag, es)
end

#shutdownObject



75
76
77
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 75

def shutdown
  super
end

#startObject



69
70
71
72
73
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 69

def start
  super
  timer_execute(:in_windows_exporter, @scrape_interval, &method(:on_timer))
  $log.info("Start in_windows_exporter (%i collectors, every %is)" % [@collectors.count, @scrape_interval])
end

#update_cacheObject



98
99
100
# File 'lib/fluent/plugin/in_windows_exporter.rb', line 98

def update_cache
  @cache_manager.update
end