Skip to content

Instantly share code, notes, and snippets.

@forstie
Created December 7, 2020 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forstie/a762f83f5b92d8fe8e726be4e3278013 to your computer and use it in GitHub Desktop.
Save forstie/a762f83f5b92d8fe8e726be4e3278013 to your computer and use it in GitHub Desktop.
This gist shows a glimpse into the realm of what's possible when using SQL and IBM i Services to monitor and manage interactive users.
--
-- description: What are ALL my interactive users doing right now? (summary)
-- ====
--
select j.authorization_name as user_name, u.text_description as description,
count(*) as job_count
from qsys2.user_info as u
join table (
qsys2.active_job_info(
subsystem_list_filter => 'QINTER', detailed_info => 'ALL')
) as j
on u.authorization_name = j.authorization_name and
j.job_type = ('INT')
group by j.authorization_name, u.text_description
order by 3 desc;
stop;
--
--
-- description: What functions are ALL my interactive users using right now? (summary)
-- =========
--
select j.authorization_name as user_name, function, count(*) as function_count
from table (
qsys2.active_job_info(subsystem_list_filter => 'QINTER', detailed_info => 'ALL')
) as j
group by j.authorization_name, function
order by 1, 3 desc; ;
stop;
--
-- description: What functions are ALL my interactive users using right now? (detail)
-- =========
--
select j.authorization_name as user_name, job_name, u.text_description as description,
job_entered_system_time as job_start, function, limit_capabilities,
client_applname, regexp_replace(sql_statement_text, ' ', '') as sql_stmt,
cpu_time, j.*
from qsys2.user_info as u
join table (
qsys2.active_job_info(
subsystem_list_filter => 'QINTER', detailed_info => 'ALL')
) as j
on u.authorization_name = j.authorization_name and
j.job_type = ('INT')
order by job_start;
stop;
--
-- description: What locks are my interactive users holding right now?
-- =====
--
select j.authorization_name as user_name, job_name, u.text_description as description, jl.*
from qsys2.user_info as u
join table (
qsys2.active_job_info(
subsystem_list_filter => 'QINTER', detailed_info => 'ALL')
) j
on u.authorization_name = j.authorization_name, lateral (
select *
from table (
qsys2.job_lock_info(job_name)
)
) jl
where j.job_type = ('INT') and lock_category not like 'INTERNAL%'
order by lock_state;
stop;
--
-- description: What files do my interactive users have open right now?
-- =====
--
select j.authorization_name as user_name, job_name, u.text_description as description, op.*
from qsys2.user_info as u
join table (
qsys2.active_job_info(
subsystem_list_filter => 'QINTER', detailed_info => 'ALL')
) j
on u.authorization_name = j.authorization_name, lateral (
select *
from table (
qsys2.open_files(job_name)
)
) op
where j.job_type = ('INT');
@carlosir
Copy link

Thank you, great tool. Carlos

@forstie
Copy link
Author

forstie commented May 10, 2022

Thank you Carlos!

@carlosir
Copy link

carlosir commented May 10, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment