Repository navigation
Expand file tree
/
Copy pathsqlagent.workbook
More file actions
859 lines (859 loc) · 37 KB
/
Copy pathsqlagent.workbook
File metadata and controls
859 lines (859 loc) · 37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
{
"version": "Notebook/1.0",
"items": [
{
"type": 9,
"content": {
"version": "KqlParameterItem/1.0",
"parameters": [
{
"id": "afdfedd6-1853-4e9f-8e78-19d86f65455e",
"version": "KqlParameterItem/1.0",
"name": "sqlagentstateSampleType",
"label": "Data to show",
"type": 10,
"description": "\"Last available\" shows the most recent sample within specified time range, if any. \"Historical\" lets you select any sample within specified time range. Refresh the workbook to see most recent samples.",
"isRequired": true,
"typeSettings": {
"additionalResourceOptions": [],
"showDefault": false
},
"jsonData": "[{\"value\":\"Latest\",\"label\":\"Last available\"},{\"value\":\"Historical\",\"label\":\"Historical\"}]",
"timeContext": {
"durationMs": 86400000
},
"value": "Latest"
}
],
"style": "formHorizontal",
"queryType": 0,
"resourceType": "microsoft.operationalinsights/workspaces"
},
"name": "sqlagentstate_sample_type_parameters"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_state\\r\\n| where sample_time_utc between ({timeRange:start} .. {timeRange:end})\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| make-series metric = dcount(sample_time_utc) default = long(null) on sample_time_utc from {timeRange:start} to {timeRange:end} step {timeRange:grain}/{grainFactor}*2\\r\\n\\r\\n\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"size": 4,
"aggregation": 3,
"title": "Select a sample",
"noDataMessage": "No SQL Agent job state samples are available",
"timeBrushParameterName": "timeRange",
"exportFieldName": "",
"exportParameterName": "sqlagentstateHistoricalSample",
"exportDefaultValue": "0",
"queryType": 9,
"visualization": "barchart",
"chartSettings": {
"showMetrics": false,
"seriesLabelSettings": [
{
"seriesName": "metric",
"color": "purpleDark"
}
]
}
},
"conditionalVisibility": {
"parameterName": "sqlagentstateSampleType",
"comparison": "isEqualTo",
"value": "Historical"
},
"name": "sqlagentstate_timeline"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_state\\r\\n| where sample_time_utc between ({timeRange:start} .. {timeRange:end})\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| summarize count_samples = dcount(sample_time_utc)\\r\\n| project strcat(\\\"There are `\\\", count_samples, \\\"` samples in the selected time range. Each vertical bar stands for a group of samples. Bar height is the number of samples in a group. Select a bar to view one sample from that group. Zoom in to see smaller sample groups, down to individual samples.\\\")\\r\\n\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"size": 3,
"noDataMessage": "No SQL Agent job state samples are available",
"queryType": 9,
"visualization": "card",
"textSettings": {
"style": "markdown"
}
},
"conditionalVisibility": {
"parameterName": "sqlagentstateSampleType",
"comparison": "isEqualTo",
"value": "Historical"
},
"name": "sqlagentstate_sample_count"
},
{
"type": 9,
"content": {
"version": "KqlParameterItem/1.0",
"parameters": [
{
"id": "d91ea020-aca3-4834-83a1-f19730aa6c3c",
"version": "KqlParameterItem/1.0",
"name": "sqlagentstateLatestSampleTime",
"type": 1,
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_state\\r\\n| where sample_time_utc between (\\r\\n iif(({timeRange:end} - {timeRange:start}) <= 5m, ({timeRange:start} - 5m), {timeRange:start})\\r\\n ..\\r\\n iif(({timeRange:end} - {timeRange:start}) <= 5m, ({timeRange:end} + 5m), {timeRange:end})\\r\\n ) // Expand the range if selected range is shorter than the least frequent collection interval (5m)\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| summarize sample_time_utc = max(sample_time_utc)\\r\\n\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"isHiddenWhenLocked": true,
"timeContext": {
"durationMs": 86400000
},
"queryType": 9
},
{
"id": "587cb1f3-411c-4d74-bd7c-fc93dfc9d5af",
"version": "KqlParameterItem/1.0",
"name": "sqlagentstateHistoricalSampleTime",
"type": 1,
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_state\\r\\n| where sample_time_utc between (todatetime(\\\"{sqlagentstateHistoricalSample:$.x}\\\") .. (todatetime(\\\"{sqlagentstateHistoricalSample:$.x}\\\") + {timeRange:grain}))\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| summarize sample_time_utc = min(sample_time_utc)\\r\\n\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"isHiddenWhenLocked": true,
"timeContext": {
"durationMs": 86400000
},
"queryType": 9
},
{
"id": "80ec1ea3-7583-4958-bb00-f18784698010",
"version": "KqlParameterItem/1.0",
"name": "sqlagentstateSampleTime",
"type": 1,
"isHiddenWhenLocked": true,
"criteriaData": [
{
"criteriaContext": {
"leftOperand": "sqlagentstateSampleType",
"operator": "==",
"rightValType": "static",
"rightVal": "Latest",
"resultValType": "param",
"resultVal": "sqlagentstateLatestSampleTime"
}
},
{
"criteriaContext": {
"leftOperand": "sqlagentstateSampleType",
"operator": "==",
"rightValType": "static",
"rightVal": "Historical",
"resultValType": "param",
"resultVal": "sqlagentstateHistoricalSampleTime"
}
},
{
"criteriaContext": {
"operator": "Default",
"resultValType": "param",
"resultVal": "sqlagentstateLatestSampleTime"
}
}
],
"timeContext": {
"durationMs": 86400000
}
}
],
"style": "formHorizontal",
"queryType": 9
},
"conditionalVisibility": {
"parameterName": "alwaysHidden",
"comparison": "isNotEqualTo"
},
"customWidth": "50",
"name": "sqlagentstate_sample_time_parameters"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_state\\r\\n| where sample_time_utc == todatetime(\\\"{sqlagentstateSampleTime}\\\")\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| summarize count_jobs = count() by sample_time_utc, sqlagent_start_time_local\\r\\n| project sample_time = sample_time_utc, sample_time_utc, sample_age = format_timespan(now() - sample_time_utc, \\\"d.hh:mm:ss\\\"), count_jobs, sqlagent_start_time_local\\r\\n\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"size": 3,
"noDataMessage": "No SQL Agent job state samples are available",
"queryType": 9,
"gridSettings": {
"formatters": [
{
"columnMatch": "sample_time",
"formatter": 6,
"formatOptions": {
"customColumnWidthSetting": "28ch"
},
"dateFormat": {
"showUtcTime": null,
"formatName": "shortDateTimeNoMsPattern"
}
},
{
"columnMatch": "sample_time_utc",
"formatter": 6,
"formatOptions": {
"customColumnWidthSetting": "28ch"
},
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
}
},
{
"columnMatch": "sample_age",
"formatter": 2,
"tooltipFormat": {
"tooltip": "Time difference between the last dashboard refresh and the displayed sample"
}
},
{
"columnMatch": "sqlagent_start_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
},
{
"columnMatch": "collection_time",
"formatter": 6,
"dateFormat": {
"showUtcTime": null,
"formatName": "shortDateTimeNoMsPattern"
}
},
{
"columnMatch": "collection_time_utc",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
}
}
],
"labelSettings": [
{
"columnId": "sample_time",
"label": "Collection time"
},
{
"columnId": "sample_time_utc",
"label": "Collection time (UTC)"
},
{
"columnId": "sample_age",
"label": "Age of sample"
},
{
"columnId": "count_jobs",
"label": "Jobs"
},
{
"columnId": "sqlagent_start_time_local",
"label": "SQL Agent start time"
}
]
}
},
"conditionalVisibility": {
"parameterName": "sqlagentstateSampleTime",
"comparison": "isNotEqualTo"
},
"name": "selected_sqlagentstate_sample"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_state\\r\\n| where sample_time_utc == todatetime(\\\"{sqlagentstateSampleTime}\\\")\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| project-away sample_time_utc, managed_instance_name, sqlagent_start_time_local, sqlagent_session_id\\r\\n| project job_name, job_category, is_job_enabled, is_job_running, start_execution_time_local, stop_execution_time_local, last_completed_execution_time_local, last_completed_execution_result, next_scheduled_execution_time_local, last_execution_requestor, last_executed_step_name, job_id\\r\\n| sort by tolower(job_name) asc\\r\\n\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"size": 3,
"showAnalytics": true,
"title": "Job state",
"noDataMessage": "There is no data for specified parameters.",
"showExportToExcel": true,
"queryType": 9,
"gridSettings": {
"formatters": [
{
"columnMatch": "is_job_enabled",
"formatter": 18,
"formatOptions": {
"thresholdsOptions": "icons",
"thresholdsGrid": [
{
"operator": "==",
"thresholdValue": "1",
"representation": "Available",
"text": ""
},
{
"operator": "==",
"thresholdValue": "0",
"representation": "disabled",
"text": ""
},
{
"operator": "Default",
"thresholdValue": null,
"representation": "Unknown",
"text": ""
}
]
}
},
{
"columnMatch": "is_job_running",
"formatter": 18,
"formatOptions": {
"thresholdsOptions": "icons",
"thresholdsGrid": [
{
"operator": "==",
"thresholdValue": "true",
"representation": "pending",
"text": ""
},
{
"operator": "==",
"thresholdValue": "false",
"representation": "stopped",
"text": ""
},
{
"operator": "Default",
"thresholdValue": null,
"representation": "unknown",
"text": ""
}
]
}
},
{
"columnMatch": "start_execution_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
},
{
"columnMatch": "stop_execution_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
},
{
"columnMatch": "last_completed_execution_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
},
{
"columnMatch": "last_completed_execution_result",
"formatter": 18,
"formatOptions": {
"thresholdsOptions": "icons",
"thresholdsGrid": [
{
"operator": "==",
"thresholdValue": "Succeeded",
"representation": "success",
"text": "{0}{1}"
},
{
"operator": "==",
"thresholdValue": "Failed",
"representation": "failed",
"text": "{0}{1}"
},
{
"operator": "==",
"thresholdValue": "Retry",
"representation": "Clock",
"text": "{0}{1}"
},
{
"operator": "==",
"thresholdValue": "Canceled",
"representation": "cancelled",
"text": "{0}{1}"
},
{
"operator": "==",
"representation": "pending",
"text": "{0}{1}"
},
{
"operator": "Default",
"thresholdValue": null,
"representation": "Blank",
"text": "{0}{1}"
}
]
}
},
{
"columnMatch": "next_scheduled_execution_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
},
{
"columnMatch": "last_execution_start_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
},
{
"columnMatch": "last_execution_stop_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
},
"tooltipFormat": {
"tooltip": "Displayed in local time of the database engine instance"
}
}
],
"filter": true,
"labelSettings": [
{
"columnId": "job_name",
"label": "Name"
},
{
"columnId": "job_category",
"label": "Category"
},
{
"columnId": "is_job_enabled",
"label": "Enabled"
},
{
"columnId": "is_job_running",
"label": "Running"
},
{
"columnId": "start_execution_time_local",
"label": "Start time"
},
{
"columnId": "stop_execution_time_local",
"label": "Stop time"
},
{
"columnId": "last_completed_execution_time_local",
"label": "Last execution time"
},
{
"columnId": "last_completed_execution_result",
"label": "Last result"
},
{
"columnId": "next_scheduled_execution_time_local",
"label": "Next start time"
},
{
"columnId": "last_execution_requestor",
"label": "Last executed by"
},
{
"columnId": "last_executed_step_name",
"label": "Last executed step"
},
{
"columnId": "job_id",
"label": "Job ID"
}
]
}
},
"conditionalVisibility": {
"parameterName": "sqlagentstateSampleTime",
"comparison": "isNotEqualTo"
},
"name": "sql_agent_job_state"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"sqlmi_sqlagent_job_history\\r\\n| where collection_time_utc between (datetime_add(\\\"second\\\", -datetime_diff(\\\"second\\\", {timeRange:end}, {timeRange:start}), todatetime(\\\"{sqlagentstateSampleTime}\\\")) .. todatetime(\\\"{sqlagentstateSampleTime}\\\"))\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| where step_id == 0\\r\\n| summarize count_jobs = count() by job_id, job_name, run_status_desc\\r\\n| extend tooltip_suffix = case(run_status_desc==\\\"Succeeded\\\", \\\"have succeeded\\\", run_status_desc==\\\"In Progress\\\", \\\"are in progress\\\", run_status_desc==\\\"Retry\\\", \\\"are retrying\\\", run_status_desc==\\\"Canceled\\\", \\\"were canceled\\\", run_status_desc==\\\"Failed\\\", \\\"have failed\\\", \\\"have unknown status\\\")\\r\\n| sort by tolower(job_name) asc, status_ordinal = case(run_status_desc==\\\"Succeeded\\\", 1, run_status_desc==\\\"In Progress\\\", 2, run_status_desc==\\\"Retry\\\", 3, run_status_desc==\\\"Canceled\\\", 4, run_status_desc==\\\"Failed\\\", 5, 6) asc\\r\\n| extend tile_ordinal = row_number()\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"size": 3,
"showAnalytics": true,
"title": "Job execution statistics",
"noDataMessage": "There is no data for specified parameters.",
"exportFieldName": "job_id",
"exportParameterName": "job_id",
"showExportToExcel": true,
"queryType": 9,
"visualization": "tiles",
"tileSettings": {
"titleContent": {
"columnMatch": "run_status_desc",
"formatter": 18,
"formatOptions": {
"thresholdsOptions": "icons",
"thresholdsGrid": [
{
"operator": "==",
"thresholdValue": "Succeeded",
"representation": "success",
"text": "[\"job_name\"]"
},
{
"operator": "==",
"thresholdValue": "Failed",
"representation": "failed",
"text": "[\"job_name\"]"
},
{
"operator": "==",
"thresholdValue": "Retry",
"representation": "2",
"text": "[\"job_name\"]"
},
{
"operator": "==",
"thresholdValue": "Canceled",
"representation": "cancelled",
"text": "[\"job_name\"]"
},
{
"operator": "==",
"thresholdValue": "In Progress",
"representation": "pending",
"text": "[\"job_name\"]"
},
{
"operator": "Default",
"thresholdValue": null,
"representation": "Unavailable",
"text": "[\"job_name\"]"
}
]
},
"tooltipFormat": {
"tooltip": "[\"count_jobs\"] executions of job \"[\"job_name\"]\" [\"tooltip_suffix\"]"
}
},
"rightContent": {
"columnMatch": "count_jobs",
"formatter": 12,
"formatOptions": {
"palette": "none"
},
"tooltipFormat": {
"tooltip": "[\"count_jobs\"] executions of job \"[\"job_name\"]\" [\"tooltip_suffix\"]"
}
},
"secondaryContent": {
"columnMatch": "run_status_desc",
"formatter": 1,
"tooltipFormat": {
"tooltip": "[\"count_jobs\"] executions of job \"[\"job_name\"]\" [\"tooltip_suffix\"]"
}
},
"showBorder": true,
"sortCriteriaField": "tile_ordinal",
"sortOrderField": 1,
"size": "auto"
}
},
"conditionalVisibilities": [
{
"parameterName": "sqlmi_sqlagent_job_history",
"comparison": "isEqualTo",
"value": "1"
},
{
"parameterName": "sqlagentstateSampleTime",
"comparison": "isNotEqualTo"
}
],
"name": "sql_agent_job_exec_stats"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"AzureDataExplorerQuery/1.0\",\"queryText\":\"let history = materialize (\\r\\nsqlmi_sqlagent_job_history\\r\\n| where collection_time_utc between (datetime_add(\\\"second\\\", -datetime_diff(\\\"second\\\", {timeRange:end}, {timeRange:start}), todatetime(\\\"{sqlagentstateSampleTime}\\\")) .. todatetime(\\\"{sqlagentstateSampleTime}\\\"))\\r\\n| where managed_instance_name =~ @\\\"{managedInstanceName}\\\"\\r\\n| where ({haReplica} and replica_type == \\\"HA secondary\\\") or (not ({haReplica}) and replica_type != \\\"HA secondary\\\")\\r\\n| where job_id == \\\"{job_id}\\\"\\r\\n| project-away collection_time_utc, managed_instance_name\\r\\n| sort by start_execution_time_local asc, step_id asc // Arrange job steps together in the sort order, starting with job outcome step (step_id 0)\\r\\n| extend job_execution_id = row_number(1) - row_number(1, step_id == 0) // Number each job step sequentially within a job execution. The difference between global row number and job execution row number is constant for a given job execution.\\r\\n);\\r\\n// column labels for each grid\\r\\nlet column_labels_string = dynamic(\\r\\n[\\r\\n\\\"job_id\\\", \\\"job_name\\\", \\\"job_category\\\", \\\"subsystem\\\", \\\"output_file_name\\\", \\\"emailed_operator_name\\\", \\\"job_execution_server\\\"\\r\\n]);\\r\\nlet column_labels_number = dynamic(\\r\\n[\\r\\n\\\"job_history_id\\\", \\\"is_job_enabled\\\", \\\"job_version_number\\\", \\\"step_id\\\", \\\"sql_message_id\\\", \\\"sql_severity\\\"\\r\\n]);\\r\\nlet column_labels_datetime = dynamic(\\r\\n[\\r\\n\\\"job_create_time_local\\\", \\\"job_modify_time_local\\\"\\r\\n]);\\r\\n// result set for strings grid\\r\\nlet history_string = (\\r\\nhistory\\r\\n| project job_history_id, job_id, job_name, job_category, subsystem, output_file_name, emailed_operator_name, job_execution_server\\r\\n| project job_history_id, columns = pack_all() // put all columns into a property bag\\r\\n| mv-apply column_label = column_labels_string to typeof(string) on (project column_label, column_value = tostring(columns[column_label])) // create a row for each name/value pair\\r\\n| project-away columns\\r\\n| sort by column_label asc //make_list later will preserve sort order\\r\\n| project job_history_id, c = pack(\\\"Property\\\", column_label, \\\"Value\\\", column_value) // introduce \\\"Property\\\" and \\\"Value\\\" column names\\r\\n| summarize details_string = dynamic_to_json(make_list(c)) by job_history_id // for each job_history_id, aggregate rowset into a json array of rows, to be used as grid source\\r\\n);\\r\\n// result set for numbers grid\\r\\nlet history_number = (\\r\\nhistory\\r\\n| project job_history_id, is_job_enabled, job_version_number, step_id, sql_message_id, sql_severity\\r\\n| project job_history_id, columns = pack_all() // put all columns into a property bag\\r\\n| mv-apply column_label = column_labels_number to typeof(string) on (project column_label, column_value = toint(columns[column_label])) // create a row for each name/value pair\\r\\n| project-away columns\\r\\n| sort by column_label asc //make_list later will preserve sort order\\r\\n| project job_history_id, c = pack(\\\"Property\\\", column_label, \\\"Value\\\", column_value) // introduce \\\"Property\\\" and \\\"Value\\\" column names\\r\\n| summarize details_number = dynamic_to_json(make_list(c)) by job_history_id // for each job_history_id, aggregate rowset into a json array of rows, to be used as grid source\\r\\n);\\r\\n// result set for datetime grid\\r\\nlet history_datetime = (\\r\\nhistory\\r\\n| project job_history_id, job_create_time_local, job_modify_time_local\\r\\n| project job_history_id, columns = pack_all() // put all columns into a property bag\\r\\n| mv-apply column_label = column_labels_datetime to typeof(string) on (project column_label, column_value = todatetime(columns[column_label])) // create a row for each name/value pair\\r\\n| project-away columns\\r\\n| sort by column_label asc //make_list later will preserve sort order\\r\\n| project job_history_id, c = pack(\\\"Property\\\", column_label, \\\"Value\\\", column_value) // introduce \\\"Property\\\" and \\\"Value\\\" column names\\r\\n| summarize details_datetime = dynamic_to_json(make_list(c)) by job_history_id // for each job_history_id, aggregate rowset into a json array of rows, to be used as grid source\\r\\n);\\r\\nlet history_details = (\\r\\nhistory\\r\\n| join kind=inner history_string on job_history_id\\r\\n| join kind=inner history_number on job_history_id\\r\\n| join kind=inner history_datetime on job_history_id\\r\\n| project job_execution_id, start_execution_time_local, job_history_id, step_id, step_name, message, run_status_desc, job_duration_seconds, retries_attempted, details_string, details_number, details_datetime, message_json = dynamic_to_json(pack(\\\"message\\\", message))\\r\\n);\\r\\nhistory_details\\r\\n| where step_id == 0 // job outcome pseudo-step\\r\\n| extend grid_id = job_execution_id, grid_parent_id = long(null)\\r\\n| union (\\r\\nhistory_details\\r\\n| where step_id != 0 // job steps\\r\\n| extend grid_id = tolong(job_history_id), grid_parent_id = job_execution_id\\r\\n)\\r\\n| sort by start_execution_time_local desc, step_id asc, retries_attempted asc\",\"clusterName\":\"{adxClusterUri}\",\"databaseName\":\"{adxDatabase}\"}",
"size": 0,
"showAnalytics": true,
"title": "Job history",
"noDataMessage": "There is no data for specified parameters.",
"exportedParameters": [
{
"fieldName": "message_json",
"parameterName": "message_json",
"parameterType": 1,
"defaultValue": "{\"message\":\"\"}"
},
{
"fieldName": "details_string",
"parameterName": "details_string",
"parameterType": 1,
"defaultValue": "{\"Property\":\"\",\"Value\":\"\"}"
},
{
"fieldName": "details_number",
"parameterName": "details_number",
"parameterType": 1,
"defaultValue": "{\"Property\":\"\",\"Value\":\"\"}"
},
{
"fieldName": "details_datetime",
"parameterName": "details_datetime",
"parameterType": 1,
"defaultValue": "{\"Property\":\"\",\"Value\":\"\"}"
},
{
"fieldName": "grid_id",
"parameterName": "job_history_grid_id",
"parameterType": 1
}
],
"showExportToExcel": true,
"queryType": 9,
"visualization": "table",
"gridSettings": {
"formatters": [
{
"columnMatch": "job_execution_id",
"formatter": 5
},
{
"columnMatch": "start_execution_time_local",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
}
},
{
"columnMatch": "job_history_id",
"formatter": 5
},
{
"columnMatch": "job_duration_seconds",
"formatter": 0,
"numberFormat": {
"unit": 24,
"options": {
"style": "decimal"
}
}
},
{
"columnMatch": "retries_attempted",
"formatter": 0,
"numberFormat": {
"unit": 17,
"options": {
"style": "decimal",
"useGrouping": true
}
}
},
{
"columnMatch": "details_string",
"formatter": 5
},
{
"columnMatch": "details_number",
"formatter": 5
},
{
"columnMatch": "details_datetime",
"formatter": 5
},
{
"columnMatch": "message_json",
"formatter": 5
},
{
"columnMatch": "grid_id",
"formatter": 5
},
{
"columnMatch": "grid_parent_id",
"formatter": 5
}
],
"filter": true,
"hierarchySettings": {
"idColumn": "grid_id",
"parentColumn": "grid_parent_id",
"treeType": 0,
"expanderColumn": "start_execution_time_local",
"expandTopLevel": false
},
"labelSettings": [
{
"columnId": "start_execution_time_local",
"label": "Start time"
},
{
"columnId": "step_id",
"label": "Step ID"
},
{
"columnId": "step_name",
"label": "Step name"
},
{
"columnId": "message",
"label": "Message"
},
{
"columnId": "run_status_desc",
"label": "Run status"
},
{
"columnId": "job_duration_seconds",
"label": "Duration"
},
{
"columnId": "retries_attempted",
"label": "Retries"
}
]
}
},
"conditionalVisibilities": [
{
"parameterName": "sqlmi_sqlagent_job_history",
"comparison": "isEqualTo",
"value": "1"
},
{
"parameterName": "job_id",
"comparison": "isNotEqualTo"
},
{
"parameterName": "sqlagentstateSampleTime",
"comparison": "isNotEqualTo"
}
],
"name": "sql_agent_job_history"
},
{
"type": 12,
"content": {
"version": "NotebookGroup/1.0",
"groupType": "editable",
"title": "Job history details",
"expandable": true,
"expanded": true,
"items": [
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"1.0.0\",\"content\":\"{message_json}\",\"transformers\":null}",
"size": 3,
"queryType": 8,
"visualization": "card",
"textSettings": {
"style": "editor"
}
},
"name": "job_history_message"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"1.0.0\",\"content\":\"{details_string}\",\"transformers\":null}",
"size": 3,
"showExportToExcel": true,
"queryType": 8
},
"customWidth": "33",
"name": "job_history_details_string"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"1.0.0\",\"content\":\"{details_number}\",\"transformers\":null}",
"size": 3,
"showExportToExcel": true,
"queryType": 8
},
"customWidth": "33",
"name": "job_history_details_number"
},
{
"type": 3,
"content": {
"version": "KqlItem/1.0",
"query": "{\"version\":\"1.0.0\",\"content\":\"{details_datetime}\",\"transformers\":null}",
"size": 3,
"showExportToExcel": true,
"queryType": 8,
"gridSettings": {
"formatters": [
{
"columnMatch": "Value",
"formatter": 6,
"dateFormat": {
"showUtcTime": true,
"formatName": "shortDateTimeNoMsPattern"
}
}
]
}
},
"customWidth": "33",
"name": "job_history_details_datetime"
}
],
"exportParameters": true
},
"conditionalVisibilities": [
{
"parameterName": "sqlmi_sqlagent_job_history",
"comparison": "isEqualTo",
"value": "1"
},
{
"parameterName": "job_id",
"comparison": "isNotEqualTo"
},
{
"parameterName": "sqlagentstateSampleTime",
"comparison": "isNotEqualTo"
},
{
"parameterName": "job_history_grid_id",
"comparison": "isNotEqualTo"
}
],
"name": "sql_agent_history_details_group"
}
],
"$schema": "https://github.com/Microsoft/Application-Insights-Workbooks/blob/master/schema/workbook.json"
}