Skip to content

Commit c326b3f

Browse files
authored
Merge pull request #394 from codefori/feature/new_example
Add new notebook example for job analysis
2 parents b52271c + fa46d7d commit c326b3f

File tree

2 files changed

+88
-12
lines changed

2 files changed

+88
-12
lines changed

src/notebooks/logic/openAsNotebook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function notebookFromStatements(statements?: string[]) {
2727
workspace.openNotebookDocument(
2828
`db2i-notebook`,
2929
{cells: statements.map(s => {
30-
if (s.startsWith(`--`)) {
30+
if (s.startsWith(`##`)) {
3131
return new NotebookCellData(NotebookCellKind.Markup, s.substring(2).trim(), `markdown`)
3232
} else {
3333
return new NotebookCellData(NotebookCellKind.Code, s, `sql`)

src/views/examples/index.ts

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,86 @@ export const ServiceInfoLabel = `IBM i (SQL) Services`;
1919

2020
export const Examples: SQLExamplesList = {
2121
"Notebooks": [
22+
{
23+
name: "IBM i History",
24+
content: [
25+
`## `.concat([
26+
`This notebook utilizes the \`ENDED_JOB_INFO\` SQL service, which extracts details about jobs that have started and ended within a specific time period.`,
27+
`If no parameter values are passed to \`ENDED_JOB_INFO\`, it will use today and yesterday for the historical analysis.`,
28+
`[Click here for documentation](https://www.ibm.com/docs/en/i/7.5.0?topic=services-ended-job-info-table-function).`,
29+
].join('\n\n')),
30+
31+
`## Top 10 jobs that used the most temporary storage (where the job ended, today or yesterday)`,
32+
[
33+
`-- title: Temp Storage top 10`,
34+
`-- hideStatement: true`,
35+
`-- y: Peak Temporary Storage `,
36+
`bar: select from_job as label, PEAK_TEMPORARY_STORAGE, `,
37+
` from_user concat ' using ' concat JOB_INTERFACE as PEAK_TEMPORARY_STORAGE_DESC`,
38+
` from table (`,
39+
` SYSTOOLS.ENDED_JOB_INFO()`,
40+
` )`,
41+
` where subsystem in ('QUSRWRK', 'QBATCH')`,
42+
` order by PEAK_TEMPORARY_STORAGE desc`,
43+
` limit 10`,
44+
].join('\n'),
45+
46+
`## Top 10 jobs that used the most CPU (where the job ended, today or yesterday)`,
47+
[
48+
`-- title: CPU top 10`,
49+
`-- hideStatement: true`,
50+
`-- y: CPU Consumers `,
51+
`bar: select from_job as label, cpu_time, `,
52+
` from_user concat ' using ' concat JOB_INTERFACE as cpu_time_DESC`,
53+
` from table (`,
54+
` SYSTOOLS.ENDED_JOB_INFO()`,
55+
` )`,
56+
` where subsystem in ('QUSRWRK', 'QBATCH')`,
57+
` order by cpu_time desc`,
58+
` limit 10`,
59+
].join('\n'),
60+
61+
`## Top 10 jobs that used the most I/O (where the job ended, today or yesterday)`,
62+
[
63+
`-- title: I/O top 10`,
64+
`-- hideStatement: true`,
65+
`-- y: I/O Drivers `,
66+
`bar: select from_job as label, sync_aux_io_count, `,
67+
` from_user concat ' using ' concat JOB_INTERFACE as sync_aux_io_count_DESC`,
68+
` from table (`,
69+
` SYSTOOLS.ENDED_JOB_INFO()`,
70+
` )`,
71+
` where subsystem in ('QUSRWRK', 'QBATCH')`,
72+
` order by sync_aux_io_count desc`,
73+
` limit 10`,
74+
].join('\n'),
75+
76+
`## Top 10 longest running jobs over the last 7 days`,
77+
[
78+
`-- title: Longest running jobs over the 7 days`,
79+
`-- hideStatement: true`,
80+
`-- y: Elapsed time (minutes)`,
81+
`bar: with barchart(execution_minutes, job_info) as (`,
82+
` select timestampdiff(4, cast(MESSAGE_TIMESTAMP - JOB_ACTIVE_TIME as char(22))), `,
83+
` from_user concat ' using ' concat JOB_INTERFACE concat ' in job: ' concat from_job`,
84+
` from table (`,
85+
` SYSTOOLS.ENDED_JOB_INFO(start_time => ( CURRENT_DATE - 7 DAYS ))`,
86+
` )`,
87+
` where subsystem in ('QUSRWRK', 'QSYSWRK', 'QBATCH')`,
88+
` order by timestampdiff(4, cast(MESSAGE_TIMESTAMP - JOB_ACTIVE_TIME as char(22))) desc`,
89+
` limit 10`,
90+
` )`,
91+
` select execution_minutes as label, execution_minutes, job_info as execution_minutes_desc`,
92+
` from barchart`,
93+
].join('\n')
94+
],
95+
isNotebook: true
96+
},
97+
2298
{
2399
name: "Local Services (Bar with tooltip)",
24100
content: [
25-
`-- This will show top services sending/receiving data`,
101+
`## This will show top services sending/receiving data`,
26102
[
27103
`bar: `,
28104
` SELECT local_port_name as label, `,
@@ -41,7 +117,7 @@ export const Examples: SQLExamplesList = {
41117
{
42118
"name": "User Storage (Bar)",
43119
content: [
44-
`-- This notebook will show the top 10 users by storage used`,
120+
`## This notebook will show the top 10 users by storage used`,
45121
[
46122
`bar: SELECT A.AUTHORIZATION_NAME as label, SUM(A.STORAGE_USED) AS TOTAL_STORAGE_USED`,
47123
` FROM QSYS2.USER_STORAGE A `,
@@ -55,7 +131,7 @@ export const Examples: SQLExamplesList = {
55131
{
56132
"name": "Spool Storage (Line)",
57133
content: [
58-
`-- This notebook will show the top 10 consumers of spool storage.`,
134+
`## This notebook will show the top 10 consumers of spool storage.`,
59135
[
60136
`line: SELECT USER_NAME as label, SUM(SIZE) AS TOTAL_SPOOL_SPACE FROM `,
61137
` TABLE (QSYS2.OBJECT_STATISTICS('QSYS ', '*LIB') ) as a, `,
@@ -72,7 +148,7 @@ export const Examples: SQLExamplesList = {
72148
{
73149
name: "CPU Consumption (Pie)",
74150
content: [
75-
`-- Find the top 10 consumers of CPU in the QUSRWRK and QSYSWRK subsystems`,
151+
`## Find the top 10 consumers of CPU in the QUSRWRK and QSYSWRK subsystems`,
76152
[
77153
`pie: select JOB_NAME as label, CPU_TIME`,
78154
`from table(QSYS2.ACTIVE_JOB_INFO(SUBSYSTEM_LIST_FILTER => 'QUSRWRK,QSYSWRK')) A `,
@@ -85,7 +161,7 @@ export const Examples: SQLExamplesList = {
85161
{
86162
name: "Largest Objects owned (Line)",
87163
content: [
88-
`-- Find the top 10 largest objects owned by a user (current_user)`,
164+
`## Find the top 10 largest objects owned by a user (current_user)`,
89165
[
90166
`line: with qsysobjs (lib, obj, type) as (`,
91167
` select object_library, object_name, object_type`,
@@ -108,29 +184,29 @@ export const Examples: SQLExamplesList = {
108184
{
109185
name: "Authority Failures review",
110186
content: [
111-
`--Review the audit journal authority failure (AF) detail, over the last month\n\nWhich days had the highest number of AF entries?`,
187+
`## Review the audit journal authority failure (AF) detail, over the last month\n\nWhich days had the highest number of AF entries?`,
112188
`bar: select date(entry_timestamp) as label, count(*) as AF_count\n from table (\n SYSTOOLS.AUDIT_JOURNAL_AF(STARTING_TIMESTAMP => current timestamp - 1 month)\n )\n group by date(entry_timestamp)\n order by AF_count desc`,
113-
`--Which users had the highest number of AF entries?`,
189+
`## Which users had the highest number of AF entries?`,
114190
`bar: select user_name as label, count(*) as AF_count\n from table (\n SYSTOOLS.AUDIT_JOURNAL_AF(STARTING_TIMESTAMP => current timestamp - 1 month)\n )\n group by user_name\n order by AF_count desc`,
115-
`--Which types of AF failures are being hit?`,
191+
`## Which types of AF failures are being hit?`,
116192
`bar: select VIOLATION_TYPE_DETAIL as label, count(*) as AF_count\n from table (\n SYSTOOLS.AUDIT_JOURNAL_AF(STARTING_TIMESTAMP => current timestamp - 1 month)\n )\n group by VIOLATION_TYPE_DETAIL\n order by AF_count desc`,
117-
`--Which objects are having the authorization failures?`,
193+
`## Which objects are having the authorization failures?`,
118194
`bar: select coalesce(\n path_name, object_library concat '/' concat object_name concat ' ' concat object_type) as label,\n count(*) as AF_count\n from table (\n SYSTOOLS.AUDIT_JOURNAL_AF(STARTING_TIMESTAMP => current timestamp - 1 month)\n )\n group by coalesce(\n path_name, object_library concat '/' concat object_name concat ' ' concat object_type)\n order by AF_count desc limit 10 `
119195
],
120196
isNotebook: true
121197
},
122198
{
123199
name: `IFS_OBJECT_STATISTICS (Bar)`,
124200
content: [
125-
`-- Get raw info about files from IFS_OBJECT_STATISTICS. **This is a long running query**.`,
201+
`## Get raw info about files from IFS_OBJECT_STATISTICS. **This is a long running query**.`,
126202
`bar: WITH ALL_OBJS AS (\n SELECT PATH_NAME,\n OBJECT_TYPE,\n DATA_SIZE AS FILESIZE,\n OBJECT_OWNER\n FROM TABLE (\n QSYS2.IFS_OBJECT_STATISTICS(START_PATH_NAME => '/home', -- Set "root" directory for analysis\n SUBTREE_DIRECTORIES => 'YES',\n OMIT_LIST => '/QSYS.LIB /QFileSvr.400')\n )\n ),\n -- Get the total size of all data underneath root\n TOTAL_DATA_SIZE AS (\n SELECT CAST(SUM(FILESIZE) AS DECFLOAT) AS DATA_SIZE\n FROM ALL_OBJS\n WHERE OBJECT_TYPE != '*DIR'\n ),\n -- Get path names to files, also calculate percent storage used (relative to total storage under root).\n PATHS_AND_FILES AS (\n SELECT SUBSTRING(PATH_NAME, 1, LOCATE_IN_STRING(PATH_NAME, '/', -1)) AS PATHNAME,\n SUBSTRING(PATH_NAME, LOCATE_IN_STRING(PATH_NAME, '/', -1) + 1) AS FILENAME,\n FILESIZE,\n OBJECT_TYPE,\n (CAST(FILESIZE AS DECFLOAT) / (SELECT DATA_SIZE FROM TOTAL_DATA_SIZE)) * 100 AS PERCENT_STORAGE\n FROM ALL_OBJS\n WHERE OBJECT_TYPE != '*DIR'\n ),\n \n -- Sum file size by directory.\n FILES_AND_DIRS AS (\n SELECT PATHNAME, \n COUNT(*) AS NUM_FILES,\n CAST(CAST(SUM(FILESIZE) AS DECFLOAT) / 1000000 AS DEC(12, 2)) AS STORAGE_USED_MB, \n CAST(SUM(PERCENT_STORAGE) AS DEC(5, 2)) AS PERCENT_STORAGE_USED_OF_RELATIVE_ROOT\n FROM PATHS_AND_FILES\n GROUP BY PATHNAME)\nSELECT PATHNAME AS LABEL, STORAGE_USED_MB FROM FILES_AND_DIRS\nORDER BY PERCENT_STORAGE_USED_OF_RELATIVE_ROOT DESC\nLIMIT 10;`
127203
],
128204
isNotebook: true
129205
},
130206
{
131207
name: `Temp storage by day (Line)`,
132208
content: [
133-
`--Show the top temp storage consumption by day. **This is a long running query**.`,
209+
`##Show the top temp storage consumption by day. **This is a long running query**.`,
134210
`line: WITH TOP_CONSUMERS AS (\n SELECT RANK() OVER (\n PARTITION BY DATE(MESSAGE_TIMESTAMP)\n ORDER BY PEAK_TEMPORARY_STORAGE DESC\n ) AS RANK,\n DATE(MESSAGE_TIMESTAMP) AS DATE,\n FROM_JOB,\n JOB_END_CODE,\n JOB_END_DETAIL,\n CPU_TIME,\n SYNC_AUX_IO_COUNT,\n PEAK_TEMPORARY_STORAGE\n FROM TABLE (\n SYSTOOLS.ENDED_JOB_INFO(START_TIME => CURRENT TIMESTAMP - 7 DAYS, END_TIME => CURRENT TIMESTAMP)\n )\n )\n SELECT FROM_JOB || ' ' || DATE AS LABEL, PEAK_TEMPORARY_STORAGE \n FROM TOP_CONSUMERS\n WHERE RANK <= 1\n ORDER BY DATE ASC,\n RANK ASC`,
135211
],
136212
isNotebook: true

0 commit comments

Comments
 (0)