Skip to content

Instantly share code, notes, and snippets.

@ktpm489
Forked from kylemclaren/findLongRunningOp.js
Created September 25, 2020 09:15
Show Gist options
  • Select an option

  • Save ktpm489/f0566f7de767d673fbe860e22ce1acac to your computer and use it in GitHub Desktop.

Select an option

Save ktpm489/f0566f7de767d673fbe860e22ce1acac to your computer and use it in GitHub Desktop.

Revisions

  1. @kylemclaren kylemclaren revised this gist Dec 17, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion killLongRunningOps.js
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,6 @@ killLongRunningOps = function(maxSecsRunning) {
    db.killOp(op.opid);
    }
    }
    };
    };

    //example: killLongRunningOps(5)
  2. @kylemclaren kylemclaren revised this gist Oct 14, 2014. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions findLongRunningOp.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    db.currentOp().inprog.forEach(
    function(op) {
    if(op.secs_running > 5) printjson(op);
    }
    )
  3. @comerford comerford revised this gist Jun 10, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion killLongRunningOps.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ killLongRunningOps = function(maxSecsRunning) {
    op = currOp.inprog[oper-0];
    if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
    print("Killing opId: " + op.opid
    + " running over for secs: "
    + " running for over secs: "
    + op.secs_running);
    db.killOp(op.opid);
    }
  4. @comerford comerford revised this gist Feb 27, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion killLongRunningOps.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    // kills long running ops (taking seconds as an arg to define "long")
    // kills long running ops in MongoDB (taking seconds as an arg to define "long")
    // attempts to be a bit safer than killing all by excluding replication related operations
    // and only targeting queries as opposed to commands etc.

    killLongRunningOps = function(maxSecsRunning) {
    currOp = db.currentOp();
  5. @comerford comerford created this gist Feb 27, 2014.
    15 changes: 15 additions & 0 deletions killLongRunningOps.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // kills long running ops (taking seconds as an arg to define "long")
    // attempts to be a bit safer than killing all by excluding replication related operations

    killLongRunningOps = function(maxSecsRunning) {
    currOp = db.currentOp();
    for (oper in currOp.inprog) {
    op = currOp.inprog[oper-0];
    if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
    print("Killing opId: " + op.opid
    + " running over for secs: "
    + op.secs_running);
    db.killOp(op.opid);
    }
    }
    };