forked from jacksontj/mongodb_exporter
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from amsingh-wish/amsingh-add-currentop-metric
Added currentOp info to metrics
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package collector | ||
|
||
import ( | ||
"github.com/globalsign/mgo" | ||
"github.com/globalsign/mgo/bson" | ||
"github.com/golang/glog" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
instanceFsyncLockWorker = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: Namespace, | ||
Subsystem: "instance", | ||
Name: "fsync_lock_worker", | ||
Help: "The value of the fsync field corresponds to whether the fsyncLockWorker is active or not.", | ||
}) | ||
) | ||
|
||
// CurrentOp keeps the data returned by the currentOp() method. | ||
type CurrentOp struct { | ||
FsyncLockWorker bool `bson:"fsyncLock"` | ||
} | ||
|
||
// Export exports the current operation status to be consumed by prometheus. | ||
func (status *CurrentOp) Export(ch chan<- prometheus.Metric) { | ||
var floatVar = float64(0) | ||
if (status.FsyncLockWorker){ | ||
floatVar = float64(1) | ||
} | ||
instanceFsyncLockWorker.Set(floatVar) | ||
instanceFsyncLockWorker.Collect(ch) | ||
} | ||
|
||
// Describe describes the current operation status for prometheus. | ||
func (status *CurrentOp) Describe(ch chan<- *prometheus.Desc) { | ||
instanceFsyncLockWorker.Describe(ch) | ||
} | ||
|
||
// GetCurrentOp returns the current operation info. | ||
func GetCurrentOp(session *mgo.Session, maxTimeMS int64) *CurrentOp { | ||
result := &CurrentOp{} | ||
err := session.DB("admin").Run(bson.D{{"currentOp", 1}, {"notexist", 0}}, result) | ||
if err != nil { | ||
glog.Error("Failed to get currentOp status.") | ||
return nil | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters