Automatically output Extended Events data to table

  • Hi there,

    I was wondering if/how I would be able to output the results of an Extended Events session to a database table, either in real time or on a regular schedule. I have seen it suggested that the ring buffer could be used as a target, then that could be queried regularly and copied into a table. Any ideas whether there are any better options, or does that sound the most feasible?

    Ideally I'd like to record events at least every 5 minutes, or real time if possible. I would anticipate there would probably be no more than a few hundred events at most in a 5 minute period.

    Thanks

  • Have a look how's it done in dbatools https://dbatools.io/xevents/

  • I shy away from the ring buffer as an output mechanism. It puts quite the load on the monitored machine. Instead, I'd suggest using file output. You could then use fn_xe_file_target_read_file to pull the information into a table on a scheduled basis. Here's an example of using that query.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • I've found that a lot of people are using XE to do a lot of things that SQL Server already does better than you could do it with XE.  With that, I'll ask, what are you trying to monitor and why???

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Brilliant, thank you both - very useful links!

  • You are probably right Jeff, the actual use case is to log specific query executions to a table...but now you've got me thinking of other potential ways...🤔

    It's partly for performance monitoring, and partly to keep a log of the specific requests coming in. We have a service which dynamically builds queries from our UI, so we are keen to keep track of what kind of requests we're receiving and how efficiently they are being executed.

    • This reply was modified 2 years, 9 months ago by  mg_dba.
  • I think this is a good use case for XE.  If you are on SQL 2016+ Query Store may be already doing what you want though, so you could look at that.

  • Yeah, Jack's right. Query Store is a good way to go. It does aggregate the data you get (by the hour by default), so if you need detailed info, XE is still your buddy. But in general, QS does a fantastic job.

     

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks all, Jeff's reply had me thinking about Query Store as we're on SQL 2019. Potentially both worth looking into though, cheers!

  • Oh, and 2019 introduces a bunch of good knobs for tweaking QS behaviors. You really can reduce the overhead quite a bit (QS is amazing, wonderful and cool, but yeah, introduces overhead, not all system loads will work well with it, testing is your buddy).

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • mg_dba wrote:

    You are probably right Jeff, the actual use case is to log specific query executions to a table...but now you've got me thinking of other potential ways...🤔

    It's partly for performance monitoring, and partly to keep a log of the specific requests coming in. We have a service which dynamically builds queries from our UI, so we are keen to keep track of what kind of requests we're receiving and how efficiently they are being executed.

    On that note, I'll agree that this is a good use case for XE.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply