influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.56k stars 5.56k forks source link

Users would like to monitor the state of SQL Server Agent Jobs #8203

Open ChrisTuckerNM opened 4 years ago

ChrisTuckerNM commented 4 years ago

Feature Request

Add the ability to monitor SQL Server Agent Jobs

Proposal:

Propose that each job on the SQLserver be monitored with the state of the job, status of last execution, time take for last execution, enabled/disabled status, last run date..

Current behavior:

None

Desired behavior:

Use case:

Detect long running jobs, detect failing jobs, detec disabled jobs...

Trovalo commented 3 years ago

When I have the time I'll draft something for it, if in the meanwhile you have some queries you'd like to propose to fetch the data feel free to share them. I think it would be better to have 2 separate queries, one to list the jobs and their status and another to fetch the job execution history.

If you got the time you can try to make a PR yourself, it's not that hard (even if you don't know GO) trust me.

ghost commented 3 years ago

I use this Query to list all SQL server agent jobs, it will list a SQL agent job names latest run status and the output message

Select Jobs.name, Jh.run_status, MSDB.dbo.agent_datetime(jh.run_date,jh.run_time) as date_time,Jh.message from msdb.dbo.sysjobhistory as Jh inner join (select Max(instance_id) As LastJobsID from msdb.dbo.sysjobhistory group by job_id) as Lastjob on jh.instance_id = Lastjob.LastJobsID inner join (select job_id, name from msdb.dbo.sysjobs as Jobname where TRY_CONVERT(UNIQUEIDENTIFIER, Jobname.name ) IS NULL and Jobname.enabled = 1) as Jobs on Jobs.job_id = Jh.job_id