{
  "ibe_sql_queries": [
    {
      "caption": "Default monitoring queries FB 2.5",
      "queries": [
        {
          "caption": "Database",
          "source": "SELECT db.mon$database_name as Database_Name,\r\n       db.mon$page_size as Page_Size,\r\n       db.mon$ods_major || '.' || db.mon$ods_minor as ODS_Version,\r\n       db.mon$oldest_transaction as Oldest_Tr,\r\n       db.mon$oldest_active as Oldest_Active_Tr,\r\n       db.mon$oldest_snapshot as Oldest_Snapshot_Tr,\r\n       db.mon$next_transaction as Next_Tr,\r\n       db.mon$page_buffers Page_Buffers,\r\n       db.mon$sql_dialect SQL_Dialect,\r\n       case\r\n         when db.mon$shutdown_mode = 0 then 'Online'\r\n         when db.mon$shutdown_mode = 1 then 'Multi-user'\r\n         when db.mon$shutdown_mode = 2 then 'Single-user'\r\n         when db.mon$shutdown_mode = 3 then 'Full'\r\n       end as Shutdown_Mode,\r\n       db.mon$sweep_interval as Sweep_Interval,\r\n       case\r\n         when db.mon$read_only = 0 then 'No'\r\n         when db.mon$read_only = 1 then 'Yes'\r\n       end as Read_Only,\r\n       case\r\n         when db.mon$forced_writes = 0 then 'No'\r\n         when db.mon$forced_writes = 1 then 'Yes'\r\n       end as Forced_Writes,\r\n       case\r\n         when db.mon$reserve_space = 0 then 'No'\r\n         when db.mon$reserve_space = 1 then 'Yes'\r\n       end as Reserve_Space,\r\n       db.mon$creation_date as Created_At,\r\n       db.mon$pages Pages,\r\n       cast((db.mon$pages * db.mon$page_size / 1024.00) as numeric(18,2))  as Size_KB,\r\n       cast((db.mon$pages * db.mon$page_size / 1024.00 / 1024.00) as numeric(18,2)) as Size_MB,\r\n       case\r\n         when db.mon$backup_state = 0 then 'Normal'\r\n         when db.mon$backup_state = 1 then 'Stalled'\r\n         when db.mon$backup_state = 2 then 'Merge'\r\n       end as Backup_State,\r\n       r.mon$record_seq_reads as Non_indexed_Reads,\r\n       r.mon$record_idx_reads as Indexed_Reads,\r\n       r.mon$record_inserts as Records_Inserted,\r\n       r.mon$record_updates as Records_Updated,\r\n       r.mon$record_deletes as Records_Deleted,\r\n       r.mon$record_backouts as Records_Backed_Out,\r\n       r.mon$record_purges as Records_Purged,\r\n       r.mon$record_expunges as Records_Expunged,\r\n       io.mon$page_reads as Page_Reads,\r\n       io.mon$page_writes as Page_Writes,\r\n       io.mon$page_fetches as Page_Fetches,\r\n       io.mon$page_marks as Page_Marks\r\nFROM mon$database db\r\nleft join mon$record_stats r on (db.mon$stat_id = r.mon$stat_id)\r\nleft join mon$io_stats io on (db.mon$stat_id = io.mon$stat_id)"
        },
        {
          "caption": "Attachments",
          "source": "SELECT a.mon$attachment_id as Attachment_ID, \r\n       a.mon$server_pid as Server_PID, \r\n       a.mon$state as State, \r\n       a.mon$attachment_name as Attachment_Name, \r\n       a.mon$user as User_Name, \r\n       a.mon$role as Role_Name, \r\n       a.mon$remote_protocol as Remote_Protocol, \r\n       a.mon$remote_address as Remote_Address, \r\n       a.mon$remote_pid as Remote_PID, \r\n       cs.rdb$character_set_name as Character_Set, \r\n       a.mon$timestamp as Established_At, \r\n       a.mon$garbage_collection as Garbage_Collection, \r\n       a.mon$remote_process as Remote_Process, \r\n       a.mon$stat_id as Statistics_ID,\r\n       r.mon$record_seq_reads as Non_indexed_Reads,\r\n       r.mon$record_idx_reads as Indexed_Reads,\r\n       r.mon$record_inserts as Records_Inserted,\r\n       r.mon$record_updates as Records_Updated,\r\n       r.mon$record_deletes as Records_Deleted,\r\n       r.mon$record_backouts as Records_Backed_Out,\r\n       r.mon$record_purges as Records_Purged,\r\n       r.mon$record_expunges as Records_Expunged,\r\n       io.mon$page_reads as Page_Reads,\r\n       io.mon$page_writes as Page_Writes,\r\n       io.mon$page_fetches as Page_Fetches,\r\n       io.mon$page_marks as Page_Marks\r\nfrom mon$attachments a\r\njoin rdb$character_sets cs on (a.mon$character_set_id = cs.rdb$character_set_id)\r\nleft join mon$record_stats r on (a.mon$stat_id = r.mon$stat_id)\r\nleft join mon$io_stats io on (a.mon$stat_id = io.mon$stat_id)"
        },
        {
          "caption": "Transactions",
          "source": "SELECT tr.mon$transaction_id as Tr_ID, \r\n       tr.mon$attachment_id as Attachment_ID, \r\n       a.mon$server_pid as Server_PID, \r\n       a.mon$user as UserName, \r\n       a.mon$remote_address as Remote_Address, \r\n       a.mon$remote_pid as Remote_PID, \r\n       a.mon$remote_process as Remote_Process, \r\n       case\r\n         when tr.mon$state = 1 then 'STARTED'\r\n         when tr.mon$state = 0 then 'FINISHED'\r\n       end as State,\r\n       tr.mon$timestamp as Started_At, \r\n       tr.mon$top_transaction as Top_Tr, \r\n       tr.mon$oldest_transaction as Oldest_Tr, \r\n       tr.mon$oldest_active Oldest_Active_Tr, \r\n       case\r\n         when tr.mon$isolation_mode = 0 then 'consistence'\r\n         when tr.mon$isolation_mode = 1 then 'concurrency'\r\n         when tr.mon$isolation_mode = 2 then 'read committed record version'\r\n         when tr.mon$isolation_mode = 3 then 'read committed no record version'\r\n       end as Isolation_Mode,\r\n       case\r\n         when tr.mon$lock_timeout = -1 then 'Infinite wait'\r\n         when tr.mon$lock_timeout = 0 then 'No wait'\r\n         when tr.mon$lock_timeout > 0  then 'Timeout ' || mon$lock_timeout\r\n       end as Lock_Timeout,\r\n       case\r\n         when tr.mon$read_only = 0 then 'No'\r\n         when tr.mon$read_only = 1 then 'Yes'\r\n       end as Read_Only,\r\n       case\r\n         when tr.mon$auto_commit = 0 then 'No'\r\n         when tr.mon$auto_commit = 1 then 'Yes'\r\n       end as Auto_Commit,\r\n       case\r\n         when tr.mon$auto_undo = 0 then 'No'\r\n         when tr.mon$auto_undo = 1 then 'Yes'\r\n       end as Auto_Undo,\r\n       r.mon$record_seq_reads as Non_indexed_Reads,\r\n       r.mon$record_idx_reads as Indexed_Reads,\r\n       r.mon$record_inserts as Records_Inserted,\r\n       r.mon$record_updates as Records_Updated,\r\n       r.mon$record_deletes as Records_Deleted,\r\n       r.mon$record_backouts as Records_Backed_Out,\r\n       r.mon$record_purges as Records_Purged,\r\n       r.mon$record_expunges as Records_Expunged,\r\n       io.mon$page_reads as Page_Reads,\r\n       io.mon$page_writes as Page_Writes,\r\n       io.mon$page_fetches as Page_Fetches,\r\n       io.mon$page_marks as Page_Marks\r\nFROM mon$transactions tr\r\njoin mon$attachments a on a.mon$attachment_id = tr.mon$attachment_id\r\nleft join mon$record_stats r on (tr.mon$stat_id = r.mon$stat_id)\r\nleft join mon$io_stats io on (tr.mon$stat_id = io.mon$stat_id)\r\norder by tr.mon$timestamp"
        },
        {
          "caption": "Statements",
          "source": "select st.mon$statement_id as Statement_ID, \r\n       st.mon$attachment_id as Attachment_ID, \r\n       st.mon$transaction_id Transaction_ID, \r\n       a.mon$server_pid as Server_PID, \r\n       a.mon$user as User_Name, \r\n       a.mon$remote_address as Remote_Address, \r\n       a.mon$remote_pid as Remote_PID, \r\n       a.mon$remote_process as Remote_Process, \r\n       case\r\n         when st.mon$state = 0 then 'IDLE'\r\n         when st.mon$state = 1 then 'ACTIVE'\r\n       end as State,\r\n       st.mon$timestamp Started_At, \r\n       st.mon$sql_text Statement_Text, \r\n       r.mon$record_seq_reads as Non_indexed_Reads,\r\n       r.mon$record_idx_reads as Indexed_Reads,\r\n       r.mon$record_inserts as Records_Inserted,\r\n       r.mon$record_updates as Records_Updated,\r\n       r.mon$record_deletes as Records_Deleted,\r\n       r.mon$record_backouts as Records_Backed_Out,\r\n       r.mon$record_purges as Records_Purged,\r\n       r.mon$record_expunges as Records_Expunged,\r\n       io.mon$page_reads as Page_Reads,\r\n       io.mon$page_writes as Page_Writes,\r\n       io.mon$page_fetches as Page_Fetches,\r\n       io.mon$page_marks as Page_Marks\r\nfrom mon$statements st\r\njoin mon$attachments a on a.mon$attachment_id = st.mon$attachment_id\r\njoin mon$record_stats r on (st.mon$stat_id = r.mon$stat_id)\r\njoin mon$io_stats io on (st.mon$stat_id = io.mon$stat_id)\r\norder by st.mon$timestamp"
        },
        {
          "caption": "Statements I/O",
          "source": "select count(*) executions , \r\n       cast(sum(r.mon$record_seq_reads)+ \r\n       sum(r.mon$record_idx_reads)+ \r\n       sum(r.mon$record_inserts)+ \r\n       sum(r.mon$record_updates)+ \r\n       sum(r.mon$record_deletes) as numeric(15)) as Record_ops, \r\n       cast(sum(io.mon$page_reads)+ \r\n       sum(io.mon$page_writes) as numeric(15)) as Page_Ops,\r\n       cast(substring(st.mon$sql_text from 1 for 8000) as varchar(8000)) Statement_Text \r\nfrom mon$statements st \r\njoin mon$attachments a on a.mon$attachment_id = st.mon$attachment_id \r\njoin mon$record_stats r on (st.mon$stat_id = r.mon$stat_id) \r\njoin mon$io_stats io on (st.mon$stat_id = io.mon$stat_id) \r\ngroup by 4 \r\norder by 3 desc"
        }
      ]
    }
  ]
}
