Skip to content

Instantly share code, notes, and snippets.

View Deeptiman's full-sized avatar
:octocat:
Open Source

Deeptiman Pattnaik Deeptiman

:octocat:
Open Source
View GitHub Profile
@Deeptiman
Deeptiman / mongo_monitoring.go
Created August 24, 2021 11:01
MongoDB Cluster Monitoring using Go
package main
import (
"context"
"encoding/json"
"fmt"
gohandlers "github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/hashicorp/go-hclog"
"go.mongodb.org/mongo-driver/bson"
@Deeptiman
Deeptiman / pool-monitor-mongodb-cluster.json
Created August 24, 2021 11:04
pool-monitor-mongodb-cluster
{
"connPoolCreated": 1,
"connSuccess": 2,
"connClosed": 0,
"connReturned": 2,
"connPoolCleared": 0,
"serverHeartbeatStart": [{
"ConnectionID": "localhost:27017[-2]",
"Awaited": true
}, {
@Deeptiman
Deeptiman / failure-monitor-mongodb-cluster.json
Created August 24, 2021 11:05
failure-monitor-mongodb-cluster
{
"connPoolCreated": 1,
"connSuccess": 2,
"connClosed": 0,
"connReturned": 2,
"connPoolCleared": 3,
"serverHeartbeatStart": [{
"ConnectionID": "localhost:27017[-3]",
"Awaited": true
}, {
@Deeptiman
Deeptiman / pool-monitor.go
Created August 24, 2021 11:48
pool-monitor
poolMonitor := &event.PoolMonitor{
Event: func(e *event.PoolEvent) {
switch e.Type {
case event.PoolCreated:
// mongo-connection pool creation events.
connPoolCreated++
case event.GetSucceeded:
// succesful mongo connection established by the pool
connSuccess++
case event.ConnectionClosed:
@Deeptiman
Deeptiman / command-monitor.go
Created August 24, 2021 11:51
command-monitor
cmdMonitor := &event.CommandMonitor{
Started: func(_ context.Context, evt *event.CommandStartedEvent) {
// Command Started event triggered when a mongo query transaction prepares the command lifecycle for
// certain DatabaseName
CommandStartedEvent {
Command bson.Raw // base64 hash value of the mongo query transaction raw
DatabaseName string // mongodb database name
CommandName string // mongodb query name [ping,insert,update,find]
RequestID int64 // mongo query command unique ID
@Deeptiman
Deeptiman / server-monitor.go
Created August 24, 2021 11:55
server-monitor
serverMonitor := &event.ServerMonitor{
ServerHeartbeatStarted: func(evt *event.ServerHeartbeatStartedEvent) {
// Started event triggered when connection heartbeat prepares to start the connection lifecycle
// in the mongo cluster
ServerHeartbeatStartedEvent struct {
ConnectionID string // mongo connection ids [host-ids]
Awaited bool // If the connection is awaiting
}
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 6 columns, instead of 2. in line 4.
_id,comment,date,email,movie_id,name
5a9427648b0beebeb69579cc,Rem officiis eaque repellendus amet eos doloribus. Porro dolor voluptatum voluptates neque culpa molestias. Voluptate unde nulla temporibus ullam.,2012-03-26T00:00:00.000Z,andrea_le@fakegmail.com,573a1390f29313caabcd6223,Andrea Le
5a9427648b0beebeb6957a87,Reiciendis adipisci veritatis molestias sint officiis ab cupiditate. Reiciendis laudantium nam explicabo rerum. Ea accusamus iste necessitatibus.,1979-12-27T00:00:00.000Z,anthony_cline@fakegmail.com,573a1390f29313caabcd6224,Anthony Cline
5a9427648b0beebeb6957ac9,Accusantium dolore cupiditate saepe iure. Deleniti accusantium voluptatibus vel eligendi nostrum enim incidunt doloribus. Similique laboriosam deleniti blanditiis.,1983-03-11T00:00:00.000Z,emily_ellis@fakegmail.com,573a1390f29313caabcd6225,Emily Ellis
5a9427648b0beebeb6957ad0,Facere esse ducimus animi pariatur ullam ab a est. Tempora odit vero tenetur impedit iure rem. Dicta beatae qui alias. Nihil quibusdam nihil vitae quidem doloribus de
_id title year genres.0 genres.1 genres.2 imdb.votes imdb.rating released_date
573a1390f29313caabcd6223 In Old Arizona 1928 Comedy Western 576 5.8 1929-01-20
573a1390f29313caabcd6224 The Public Enemy 1931 Crime Drama 12384 7.8 1931-04-23
573a1390f29313caabcd6225 High and Dizzy 1920 Comedy Short 646 7 1920-07-11
573a1390f29313caabcd6226 Nanook of the North 1922 Documentary 6918 7.8 1922-06-11
573a1390f29313caabcd6227 Battleship Potemkin 1925 History War 36901 8 1925-12-24
573a1390f29313caabcd6228 The Gold Rush 1925 Adventure Comedy Drama 59483 8.3 1925-07-18
573a1390f29313caabcd6229 For Heaven's Sake 1926 Action Comedy 918 7.6 1926-04-05
573a1390f29313caabcd6213 The Cameraman 1928 Comedy Family 6886 8.3 1928-09-22
573a1390f29313caabcd6263 The Circus 1928 Comedy 16017 8.1 1928-05-02
{
"_id": ObjectId("573a1391f29313caabcd8b94"),
"title": "The Last Command",
"plot": "A former Imperial Russian general and cousin of the Czar ends up in Hollywood as an
extra in a movie directed by a former revolutionary.",
"rated": "GOOD",
"language": "Russian",
"year": 1928,
"poster": "https://m.media-amazon.com/images/M/MV5BMTg2Mjg3MDI5OF5BMl5BanBnXkFtZTgwMjMzMDMyMjE@._V1_SY1000_SX677_AL_.jpg",
"director": "Josef von Sternberg",
db.project_data.aggregate([
{
$project: {
"_id": 0,
"title": 1,
"plot": 1,
"year": 1,
"language": 1,
"rated": 1,
"poster": 1,