LoginSignup
6
6

More than 5 years have passed since last update.

psql経由でのCPU使用率のテーブル蓄積

Last updated at Posted at 2015-11-11

psql経由で、CPU使用率を1秒間隔でテーブルに蓄積します。

-- CPU使用率のus、sy、id、waと取得時のタイムスタンプを記録するテーブルを作成します。
=# CREATE TABLE cpu_usage (
  time timestamp DEFAULT now(),
  us smallint,
  sy smallint,
  id smallint,
  wa smallint
);

-- COPY FROM PROGRAMを使い、vmstatからCPU使用率を取得してテーブルにコピーします。
COPY cpu_usage(us, sy, id, wa)
  FROM PROGRAM 'vmstat | tail -1 | awk ''{print $13 "," $14 "," $15 "," $16}'''
  WITH (FORMAT csv);

-- CPU使用率を1件テーブルに蓄積する上記COPY FROM PROGRAMを1秒間隔で実行します。
\watch 1
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6