Giter Club home page Giter Club logo

sql_powershell_querymonitoring's Introduction

SQL_Powershell_QueryMonitoring

This script is for monitoring active queries on MSSQL. Tested in Powershell 5.1 and MSSQL 2014 This script needs PS module SqlServer Database should have WhoisActive installed. See http://whoisactive.com/ or install DBAtools and Install-DbaWhoIsActive -sqlinstance sqlserver -database databasename. See https://dbatools.io/.

Permissions

Make sure the user that the script wil run under has permissions to do queries on the database.

Trigger explanation

I don't work continuously with the actual software that uses the SQL server. So to only get logs when users experience 'lag' in the software. There needs to be a user based triger. I don't want to give users permission to run this / a script themselves on te SQLserver for multiple reasons.

Scheduled Task

The script should run as a task. I run this scipt every 1 minute. Task Scheduler only has a minimum of 5 minutes. You can make a scheduled task using powershell. TIP: https://stackoverflow.com/questions/20108886/powershell-scheduled-task-with-daily-trigger-and-repetition-interval

If you need help contact me, or I can make another script with a scheduler.

Here is a solution I used: Make a batch script thats creates a file in a folder. The Powershell script detects if there is a file inside the folder. If there is a file, the script runs. If not, nothing happens.

Example of a batch script

Open Notepad and save the following as a .bat file. Or download trigger.bat and make the changes. Make sure to have the same location in the powershell script.

@echo off whoami >> \\Examplesrv\Exampleloc\Trigger.txt hostname >> \\Examplesrv\Exampleloc\Trigger.txt date /t >> \\Examplesrv\Exampleloc\Trigger.txt

Bat file

I made a shortcut from the bat file. You can assign an icon to the shortcut so it acually looks like a program and you can always make changes to the actual bat file. Share the shortcut with some or all of the users.

sql_powershell_querymonitoring's People

Contributors

lorentz86 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.