module PgsqlStats class Process include PgsqlStats::Parsing attr_accessor :database_oid, :database_name, :process_id, :user_oid, :user_name, :current_query, :waiting, :query_started_at, :started_at, :client_address, :client_port def initialize(row) load(row) end def refresh load(Collector.connection.select_one("SELECT * FROM pg_stat_activity WHERE procpid = #{process_id}")) end def database Collector.database(database_oid) end def waiting? waiting == true end private def load(row) self.database_oid = row["datid"].to_i self.database_name = row["datname"] self.process_id = row["procpid"].to_i self.user_oid = row["usesysid"].to_i self.user_name = row["usename"] self.current_query = row["current_query"] self.waiting = (row["waiting"] == "t") self.query_started_at = parse_time(row["query_start"]) self.started_at = parse_time(row["backend_start"]) self.client_address = row["client_addr"] self.client_port = row["client_port"].to_i end end end