SSIS 作业统计

SSIS Job Statistics

我正在尝试找出类似

的 SSIS 作业统计信息

每个帐户 运行 的作业(那么有多少和哪些作业 运行 来自哪个系统帐户与哪个用户帐户)

如果我从 SSISDB 目录调用 SSIS 包,那么我应该知道哪个帐户正在调用该包。它是 SQL 服务器代理帐户还是任何其他用户帐户。

有什么办法可以得到这些信息吗?

谢谢。

SSIS 有一些您可以使用的内部报告。在 Integration Services 选项卡下,您可以右键单击 SSISDB 并转到 Reports > All Executions。这将为您提供所有当前和最近的执行。如果您为给定的执行单击 Overview,则会有一个名为 CALLER_INFO 的字段,它会告诉您这是否是从 SQL Agent 调用的。请注意,如果您不是管理员,某些执行可能会从您在报告中的视图中过滤掉。

如果您有权直接查询 SSISDB 数据库,您可以使用以下命令,它将为您提供调用执行的帐户名以及 运行 当前操作的帐户:

select 
    execution_id
    , folder_name
    , project_name
    , package_name
    , environment_name
    , executed_as_name
    , start_time
    , end_time
    , CASE status WHEN 1 THEN 'Created'
        WHEN 2 THEN 'Running'
        WHEN 3 THEN 'Cancelled'
        WHEN 4 THEN 'Failed'
        WHEN 5 THEN 'Pending'
        WHEN 6 THEN 'Ended Unexpectedly'
        WHEN 7 THEN 'Succeeded'
        WHEN 8 THEN 'Stopping'
        ELSE 'Completed' END AS Status
    , caller_name
    , process_id
    , server_name
from internal.execution_info
--Optionally filter just running jobs
WHERE status = 2

这是一个具有以下过滤器的视图:

WHERE      opers.[operation_id] in (SELECT id FROM [internal].[current_user_readable_operations])
           OR (IS_MEMBER('ssis_admin') = 1)
           OR (IS_SRVROLEMEMBER('sysadmin') = 1)

因此,如果您不是管理员,结果将被过滤到您有权查看的那些执行。您也可以直接查询内部表来解决此限制。

编辑 在 SQL Agent 的情况下,您可以使用如下查询,该查询改编自:https://www.mssqltips.com/sqlservertip/2561/querying-sql-server-agent-job-information/

该步骤将在数据库用户名、代理或作业所有者下 运行,具体取决于其配置方式。

SELECT 
    [sJOB].[job_id] AS [JobID]
    , [sJOB].[name] AS [JobName]
    , [sDBP].[name] AS [JobOwner]
    , [sCAT].[name] AS [JobCategory]
    , [sJOB].[description] AS [JobDescription]
    , CASE [sJOB].[enabled]
        WHEN 1 THEN 'Yes'
        WHEN 0 THEN 'No'
      END AS [IsEnabled]
    , [sJOB].[date_created] AS [JobCreatedOn]
    , [sJOB].[date_modified] AS [JobLastModifiedOn]
    , [sSVR].[name] AS [OriginatingServerName]
    , [sJSTP].[step_id] AS [JobStartStepNo]
    , [sJSTP].[step_name] AS [JobStartStepName]
    , CASE
        WHEN [sSCH].[schedule_uid] IS NULL THEN 'No'
        ELSE 'Yes'
      END AS [IsScheduled]
    , [sSCH].[schedule_uid] AS [JobScheduleID]
    , [sSCH].[name] AS [JobScheduleName]
    , CASE [sJOB].[delete_level]
        WHEN 0 THEN 'Never'
        WHEN 1 THEN 'On Success'
        WHEN 2 THEN 'On Failure'
        WHEN 3 THEN 'On Completion'
      END AS [JobDeletionCriterion]
      , proxyName.name
      , sJSTP.database_user_name
FROM
    [msdb].[dbo].[sysjobs] AS [sJOB]
    LEFT JOIN [msdb].[sys].[servers] AS [sSVR]
        ON [sJOB].[originating_server_id] = [sSVR].[server_id]
    LEFT JOIN [msdb].[dbo].[syscategories] AS [sCAT]
        ON [sJOB].[category_id] = [sCAT].[category_id]
    LEFT JOIN [msdb].[dbo].[sysjobsteps] AS [sJSTP]
        ON [sJOB].[job_id] = [sJSTP].[job_id]
        AND [sJOB].[start_step_id] = [sJSTP].[step_id]
    LEFT JOIN msdb.dbo.sysproxies proxy
        ON sJSTP.proxy_id = proxy.proxy_id
    LEFT JOIN [msdb].[sys].[database_principals] proxyName
        ON proxyName.sid = proxy.user_sid
    LEFT JOIN [msdb].[sys].[database_principals] AS [sDBP]
        ON [sJOB].[owner_sid] = [sDBP].[sid]
    LEFT JOIN [msdb].[dbo].[sysjobschedules] AS [sJOBSCH]
        ON [sJOB].[job_id] = [sJOBSCH].[job_id]
    LEFT JOIN [msdb].[dbo].[sysschedules] AS [sSCH]
        ON [sJOBSCH].[schedule_id] = [sSCH].[schedule_id]

ORDER BY [JobName]