daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION ps_snap_stats() RETURNS BIGINT AS $$
  2. DECLARE
  3.     snapid BIGINT;
  4. BEGIN
  5.     -- Create the snapshot id.
  6.     INSERT INTO ps_snaps
  7.     DEFAULT VALUES
  8.     RETURNING snap
  9.     INTO snapid;
  10.     RAISE DEBUG 'Creating snapshot: %', snapid;
  11.  
  12.     -- Start capturing data.
  13.     INSERT INTO ps_cpustat(snap, cpu_user, cpu_nice, cpu_system, cpu_idle,
  14.             cpu_iowait)
  15.     SELECT snapid, "user", nice, system, idle, iowait
  16.     FROM pg_cputime();
  17.  
  18.     INSERT INTO ps_memstat(snap, memused, memfree, memshared, membuffers,
  19.             memcached, swapused, swapfree, swapcached)
  20.     SELECT snapid, memused, memfree, memshared, membuffers, memcached,
  21.             swapused, swapfree, swapcached
  22.     FROM pg_memusage();
  23.  
  24.     INSERT INTO ps_procstat(snap, pid, comm, fullcomm, state, ppid, pgrp,
  25.             session, tty_nr, tpgid, flags, minflt, cminflt, majflt, cmajflt,
  26.             utime, stime, cutime, cstime, priority, nice, num_threads,
  27.             itrealvalue, starttime, vsize, rss, exit_signal, processor,
  28.             rt_priority, policy, delayacct_blkio_ticks, uid, username)
  29.     SELECT snapid, procpid, comm, fullcomm, state, ppid, pgrp, session, tty_nr,
  30.             tpgid, flags, minflt, cminflt, majflt, cmajflt, utime, stime,
  31.             cutime, cstime, priority, nice, num_threads, itrealvalue,
  32.             starttime, vsize, rss, exit_signal, processor, rt_priority,
  33.             policy, delayacct_blkio_ticks, uid, username
  34.     FROM pg_stat_activity, pg_proctab()
  35.     WHERE procpid = pid;
  36.  
  37.     -- Return the id of the snapshot just created.
  38.     RETURN snapid;
  39. END;
  40. $$ LANGUAGE plpgsql;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top