Open6

Windows のメモリー不足を早めに察知したい

wintwint

モチベ

仮想メモリーまで枯渇すると再起動しなきゃいけないので、エラーが出出す前に検知したい

方針

  • Windows の本体のイベントで察知する
    • よく知らない
  • サーバー監視 agent を入れる
    • 手間が多い
wintwint

イベントのサンプル

ログの名前:         System
ソース:           Microsoft-Windows-Resource-Exhaustion-Detector
日付:            2021/11/09 22:41:41
イベント ID:       2004
タスクのカテゴリ:      リソース消費診断イベント
レベル:           警告
キーワード:         システムのコミット リミット (仮想メモリ) の消費に関連するイベントです。
ユーザー:          SYSTEM
コンピューター:       DESKTOP-UUVVV6M
説明:
Windows は仮想メモリの不足状態を診断しました。仮想メモリを多く消費したのは次のプログラムです: chrome.exe (29700) は 1308913664 バイトを消費し、Discord.exe (21512) は 767610880 バイトを消費し、chrome.exe (36876) は 682995712 バイトを消費しました。
イベント XML:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-Resource-Exhaustion-Detector" Guid="{9988748e-c2e8-4054-85f6-0c3e1cad2470}" />
    <EventID>2004</EventID>
    <Version>0</Version>
    <Level>3</Level>
    <Task>3</Task>
    <Opcode>33</Opcode>
    <Keywords>0x8000000020000000</Keywords>
    <TimeCreated SystemTime="2021-11-09T13:41:41.5367566Z" />
    <EventRecordID>52816</EventRecordID>
    <Correlation ActivityID="{4d800752-d6f3-49f5-ace0-53a9f433ca5d}" />
    <Execution ProcessID="14632" ThreadID="18032" />
    <Channel>System</Channel>
    <Computer>DESKTOP-UUVVV6M</Computer>
    <Security UserID="S-1-5-18" />
  </System>
  <UserData>
    <MemoryExhaustionInfo xmlns="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events">
      <SystemInfo>
        <SystemCommitLimit>86719217664</SystemCommitLimit>
        <SystemCommitCharge>86450978816</SystemCommitCharge>
        <ProcessCommitCharge>26248486912</ProcessCommitCharge>
        <PagedPoolUsage>1395204096</PagedPoolUsage>
        <PhysicalMemorySize>34290417664</PhysicalMemorySize>
        <PhysicalMemoryUsage>21349613568</PhysicalMemoryUsage>
        <NonPagedPoolUsage>1261527040</NonPagedPoolUsage>
        <Processes>395</Processes>
      </SystemInfo>
      <PagedPoolInfo>
        <Tag_1>
          <Name>MmSt</Name>
          <PoolUsed>309383648</PoolUsed>
        </Tag_1>
        <Tag_2>
          <Name>FMfn</Name>
          <PoolUsed>128116816</PoolUsed>
        </Tag_2>
        <Tag_3>
          <Name>Ntff</Name>
          <PoolUsed>75409664</PoolUsed>
        </Tag_3>
      </PagedPoolInfo>
      <NonPagedPoolInfo>
        <Tag_1>
          <Name>smNp</Name>
          <PoolUsed>187367424</PoolUsed>
        </Tag_1>
        <Tag_2>
          <Name>smBt</Name>
          <PoolUsed>157433856</PoolUsed>
        </Tag_2>
        <Tag_3>
          <Name>Py28</Name>
          <PoolUsed>94028496</PoolUsed>
        </Tag_3>
      </NonPagedPoolInfo>
      <ProcessInfo>
        <Process_1>
          <Name>chrome.exe</Name>
          <ID>29700</ID>
          <CreationTime>2021-11-06T03:41:22.1265656Z</CreationTime>
          <CommitCharge>1308913664</CommitCharge>
          <HandleCount>1061</HandleCount>
          <Version>95.0.4638.69</Version>
          <TypeInfo>201</TypeInfo>
        </Process_1>
        <Process_2>
          <Name>Discord.exe</Name>
          <ID>21512</ID>
          <CreationTime>2021-10-31T06:51:36.0748780Z</CreationTime>
          <CommitCharge>767610880</CommitCharge>
          <HandleCount>110612</HandleCount>
          <Version>1.0.9003.0</Version>
          <TypeInfo>210</TypeInfo>
        </Process_2>
        <Process_3>
          <Name>chrome.exe</Name>
          <ID>36876</ID>
          <CreationTime>2021-11-06T03:41:38.6349776Z</CreationTime>
          <CommitCharge>682995712</CommitCharge>
          <HandleCount>594</HandleCount>
          <Version>95.0.4638.69</Version>
          <TypeInfo>219</TypeInfo>
        </Process_3>
        <Process_4>
          <Name>
          </Name>
          <ID>0</ID>
          <CreationTime>1601-01-01T00:00:00.0000000Z</CreationTime>
          <CommitCharge>0</CommitCharge>
          <HandleCount>0</HandleCount>
          <Version>0.0.0.0</Version>
          <TypeInfo>0</TypeInfo>
        </Process_4>
        <Process_5>
          <Name>
          </Name>
          <ID>0</ID>
          <CreationTime>1601-01-01T00:00:00.0000000Z</CreationTime>
          <CommitCharge>0</CommitCharge>
          <HandleCount>0</HandleCount>
          <Version>0.0.0.0</Version>
          <TypeInfo>0</TypeInfo>
        </Process_5>
        <Process_6>
          <Name>
          </Name>
          <ID>0</ID>
          <CreationTime>1601-01-01T00:00:00.0000000Z</CreationTime>
          <CommitCharge>0</CommitCharge>
          <HandleCount>0</HandleCount>
          <Version>0.0.0.0</Version>
          <TypeInfo>0</TypeInfo>
        </Process_6>
      </ProcessInfo>
      <ExhaustionEventInfo>
        <Time>2021-11-09T13:41:29.8781920Z</Time>
      </ExhaustionEventInfo>
    </MemoryExhaustionInfo>
  </UserData>
</Event>
ログの名前:         Microsoft-Windows-Resource-Exhaustion-Detector/Operational
ソース:           Microsoft-Windows-Resource-Exhaustion-Detector
日付:            2021/11/09 22:03:19
イベント ID:       1003
タスクのカテゴリ:      リソース消費検出イベント
レベル:           警告
キーワード:         システムのコミット リミット (仮想メモリ) の消費に関連するイベントです。
ユーザー:          SYSTEM
コンピューター:       DESKTOP-UUVVV6M
説明:
Windows Resource Exhaustion Detector は、コンピューターの仮想メモリ不足の通知を受けました。
イベント XML:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-Resource-Exhaustion-Detector" Guid="{9988748e-c2e8-4054-85f6-0c3e1cad2470}" />
    <EventID>1003</EventID>
    <Version>0</Version>
    <Level>3</Level>
    <Task>2</Task>
    <Opcode>22</Opcode>
    <Keywords>0x4000000020000000</Keywords>
    <TimeCreated SystemTime="2021-11-09T13:03:19.8596954Z" />
    <EventRecordID>598</EventRecordID>
    <Correlation ActivityID="{5213aeca-c0ec-4e47-9afb-7086fcdd864a}" />
    <Execution ProcessID="14632" ThreadID="34744" />
    <Channel>Microsoft-Windows-Resource-Exhaustion-Detector/Operational</Channel>
    <Computer>DESKTOP-UUVVV6M</Computer>
    <Security UserID="S-1-5-18" />
  </System>
  <UserData>
    <CommitLimitExhaustion xmlns="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events">
      <SystemCommitLimit>86719217664</SystemCommitLimit>
      <SystemCommitCharge>86451912704</SystemCommitCharge>
    </CommitLimitExhaustion>
  </UserData>
</Event>
wintwint

custom view

query (XPath)

<QueryList>
  <Query Id="0" Path="Microsoft-Windows-Resource-Exhaustion-Detector/Operational">
    <Select Path="Microsoft-Windows-Resource-Exhaustion-Detector/Operational">*[System[Provider[@Name='Microsoft-Windows-Resource-Exhaustion-Detector' or @Name='Microsoft-Windows-Resource-Exhaustion-Resolver'] and TimeCreated[timediff(@SystemTime) &lt;= 2592000000]]]</Select>
    <Select Path="Microsoft-Windows-Resource-Exhaustion-Resolver/Operational">*[System[Provider[@Name='Microsoft-Windows-Resource-Exhaustion-Detector' or @Name='Microsoft-Windows-Resource-Exhaustion-Resolver'] and TimeCreated[timediff(@SystemTime) &lt;= 2592000000]]]</Select>
  </Query>
</QueryList>