@@ -70,6 +70,61 @@ export class DatabaseConnection {
7070 help : 'Total number of mongodb queues' ,
7171 labelNames : [ "collection" ]
7272 } )
73+ public static mongodb_insert = new client . Histogram ( {
74+ name : 'openflow_mongodb_insert_seconds' ,
75+ help : 'Duration for mongodb inserts microseconds' ,
76+ labelNames : [ 'collection' ] ,
77+ buckets : [ 0.1 , 0.3 , 0.5 , 0.7 , 1 , 3 , 5 , 7 , 10 ]
78+ } )
79+ public static mongodb_insert_count = new client . Counter ( {
80+ name : 'openflow_mongodb_insert_count' ,
81+ help : 'Total number of mongodb inserts' ,
82+ labelNames : [ "collection" ]
83+ } )
84+ public static mongodb_update = new client . Histogram ( {
85+ name : 'openflow_mongodb_update_seconds' ,
86+ help : 'Duration for mongodb updates microseconds' ,
87+ labelNames : [ 'collection' ] ,
88+ buckets : [ 0.1 , 0.3 , 0.5 , 0.7 , 1 , 3 , 5 , 7 , 10 ]
89+ } )
90+ public static mongodb_update_count = new client . Counter ( {
91+ name : 'openflow_mongodb_update_count' ,
92+ help : 'Total number of mongodb updates' ,
93+ labelNames : [ "collection" ]
94+ } )
95+ public static mongodb_replace = new client . Histogram ( {
96+ name : 'openflow_mongodb_replace_seconds' ,
97+ help : 'Duration for mongodb replaces microseconds' ,
98+ labelNames : [ 'collection' ] ,
99+ buckets : [ 0.1 , 0.3 , 0.5 , 0.7 , 1 , 3 , 5 , 7 , 10 ]
100+ } )
101+ public static mongodb_replace_count = new client . Counter ( {
102+ name : 'openflow_mongodb_replace_count' ,
103+ help : 'Total number of mongodb replaces' ,
104+ labelNames : [ "collection" ]
105+ } )
106+ public static mongodb_delete = new client . Histogram ( {
107+ name : 'openflow_mongodb_delete_seconds' ,
108+ help : 'Duration for mongodb deletes microseconds' ,
109+ labelNames : [ 'collection' ] ,
110+ buckets : [ 0.1 , 0.3 , 0.5 , 0.7 , 1 , 3 , 5 , 7 , 10 ]
111+ } )
112+ public static mongodb_delete_count = new client . Counter ( {
113+ name : 'openflow_mongodb_delete_count' ,
114+ help : 'Total number of mongodb deletes' ,
115+ labelNames : [ "collection" ]
116+ } )
117+ public static mongodb_deletemany = new client . Histogram ( {
118+ name : 'openflow_mongodb_deletemany_seconds' ,
119+ help : 'Duration for mongodb deletemanys microseconds' ,
120+ labelNames : [ 'collection' ] ,
121+ buckets : [ 0.1 , 0.3 , 0.5 , 0.7 , 1 , 3 , 5 , 7 , 10 ]
122+ } )
123+ public static mongodb_deletemany_count = new client . Counter ( {
124+ name : 'openflow_mongodb_deletemany_count' ,
125+ help : 'Total number of mongodb deletemanys' ,
126+ labelNames : [ "collection" ]
127+ } )
73128 static toArray ( iterator ) : Promise < any [ ] > {
74129 return new Promise ( ( resolve , reject ) => {
75130 iterator . toArray ( ( err , res ) => {
@@ -203,8 +258,10 @@ export class DatabaseConnection {
203258 if ( ! Base . hasRight ( u , item . _id , Rights . read ) ) {
204259 this . _logger . debug ( "Assigning " + item . name + " read permission to " + u . name ) ;
205260 Base . addRight ( u , item . _id , item . name , [ Rights . read ] , false ) ;
206-
261+ DatabaseConnection . mongodb_update_count . labels ( "users" ) . inc ( ) ;
262+ const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
207263 await this . db . collection ( "users" ) . updateOne ( { _id : u . _id } , { $set : { _acl : u . _acl } } ) ;
264+ end ( { collection : "users" } ) ;
208265 // await this.db.collection("users").save(u);
209266 } else if ( u . _id != item . _id ) {
210267 this . _logger . debug ( item . name + " allready exists on " + u . name ) ;
@@ -218,7 +275,10 @@ export class DatabaseConnection {
218275 }
219276 this . _logger . debug ( "Assigning " + item . name + " read permission to " + r . name ) ;
220277 Base . addRight ( r , item . _id , item . name , [ Rights . read ] , false ) ;
278+ DatabaseConnection . mongodb_update_count . labels ( "users" ) . inc ( ) ;
279+ const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
221280 await this . db . collection ( "users" ) . updateOne ( { _id : r . _id } , { $set : { _acl : r . _acl } } ) ;
281+ end ( { collection : "users" } ) ;
222282 // await this.db.collection("users").save(r);
223283 } else if ( r . _id != item . _id ) {
224284 this . _logger . debug ( item . name + " allready exists on " + r . name ) ;
@@ -249,8 +309,10 @@ export class DatabaseConnection {
249309 if ( right == null ) {
250310 this . _logger . debug ( "Removing " + item . name + " read permissions from " + u . name ) ;
251311 // await this.db.collection("users").save(u);
312+ DatabaseConnection . mongodb_update_count . labels ( 'users' ) . inc ( ) ;
313+ const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
252314 await this . db . collection ( "users" ) . updateOne ( { _id : u . _id } , { $set : { _acl : u . _acl } } ) ;
253-
315+ end ( { collection : 'users' } ) ;
254316 }
255317
256318 } else {
@@ -266,7 +328,10 @@ export class DatabaseConnection {
266328 if ( right == null ) {
267329 this . _logger . debug ( "Removing " + item . name + " read permissions from " + r . name ) ;
268330 // await this.db.collection("users").save(r);
331+ DatabaseConnection . mongodb_update_count . labels ( 'users' ) . inc ( ) ;
332+ const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
269333 await this . db . collection ( "users" ) . updateOne ( { _id : r . _id } , { $set : { _acl : r . _acl } } ) ;
334+ end ( { collection : 'users' } ) ;
270335 }
271336
272337 } else {
@@ -400,7 +465,6 @@ export class DatabaseConnection {
400465 let arr : T [ ] = [ ] ;
401466
402467
403- DatabaseConnection . mongodb_query_count . inc ( ) ;
404468 DatabaseConnection . mongodb_query_count . labels ( collectionname ) . inc ( ) ;
405469 const end = DatabaseConnection . mongodb_query . startTimer ( ) ;
406470 let _pipe = this . db . collection ( collectionname ) . find ( _query ) ;
@@ -522,7 +586,6 @@ export class DatabaseConnection {
522586 const options : CollectionAggregationOptions = { } ;
523587 options . hint = myhint ;
524588 try {
525- DatabaseConnection . mongodb_aggregate_count . inc ( ) ;
526589 DatabaseConnection . mongodb_aggregate_count . labels ( collectionname ) . inc ( ) ;
527590 const end = DatabaseConnection . mongodb_aggregate . startTimer ( ) ;
528591 const items : T [ ] = await this . db . collection ( collectionname ) . aggregate ( aggregates , options ) . toArray ( ) ;
@@ -736,7 +799,10 @@ export class DatabaseConnection {
736799 // const options:CollectionInsertOneOptions = { writeConcern: { w: parseInt((w as any)), j: j } };
737800 const options : CollectionInsertOneOptions = { w : w , j : j } ;
738801 //const options: CollectionInsertOneOptions = { w: "majority" };
802+ DatabaseConnection . mongodb_insert_count . labels ( collectionname ) . inc ( ) ;
803+ const end = DatabaseConnection . mongodb_insert . startTimer ( ) ;
739804 const result : InsertOneWriteOpResult < T > = await this . db . collection ( collectionname ) . insertOne ( item , options ) ;
805+ end ( { collection : collectionname } ) ;
740806 item = result . ops [ 0 ] ;
741807 if ( collectionname === "users" && item . _type === "user" ) {
742808 Base . addRight ( item , item . _id , item . name , [ Rights . read , Rights . update , Rights . invoke ] ) ;
@@ -761,7 +827,10 @@ export class DatabaseConnection {
761827 if ( collectionname === "users" && item . _type === "role" ) {
762828 Base . addRight ( item , item . _id , item . name , [ Rights . read ] ) ;
763829 item = await this . CleanACL ( item , user ) ;
830+ DatabaseConnection . mongodb_replace_count . labels ( collectionname ) . inc ( ) ;
831+ const end = DatabaseConnection . mongodb_replace . startTimer ( ) ;
764832 await this . db . collection ( collectionname ) . replaceOne ( { _id : item . _id } , item ) ;
833+ end ( { collection : collectionname } ) ;
765834 DBHelper . cached_roles = [ ] ;
766835 }
767836 DatabaseConnection . traversejsondecode ( item ) ;
@@ -942,7 +1011,6 @@ export class DatabaseConnection {
9421011 delete ( q . item as any ) . newpassword ;
9431012 }
9441013 this . _logger . silly ( "[" + user . username + "][" + q . collectionname + "] Updating " + ( q . item . name || q . item . _name ) + " in database" ) ;
945- // await this.db.collection(collectionname).replaceOne({ _id: item._id }, item, options);
9461014
9471015 if ( q . query === null || q . query === undefined ) {
9481016 const id : string = q . item . _id ;
@@ -979,10 +1047,16 @@ export class DatabaseConnection {
9791047 }
9801048
9811049 if ( q . collectionname != "fs.files" ) {
1050+ DatabaseConnection . mongodb_replace_count . labels ( q . collectionname ) . inc ( ) ;
1051+ const end = DatabaseConnection . mongodb_replace . startTimer ( ) ;
9821052 q . opresult = await this . db . collection ( q . collectionname ) . replaceOne ( _query , q . item , options ) ;
1053+ end ( { collection : q . collectionname } ) ;
9831054 } else {
9841055 const fsc = Config . db . db . collection ( "fs.files" ) ;
1056+ DatabaseConnection . mongodb_update_count . labels ( 'fs.files' ) . inc ( ) ;
1057+ const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
9851058 q . opresult = await fsc . updateOne ( _query , { $set : { metadata : ( q . item as any ) . metadata } } ) ;
1059+ end ( { collection : 'fs.files' } ) ;
9861060 }
9871061 } else {
9881062 if ( ( q . item [ "$set" ] ) === undefined ) { ( q . item [ "$set" ] ) = { } } ;
@@ -991,7 +1065,10 @@ export class DatabaseConnection {
9911065 ( q . item [ "$set" ] ) . _modified = new Date ( new Date ( ) . toISOString ( ) ) ;
9921066 if ( ( q . item [ "$inc" ] ) === undefined ) { ( q . item [ "$inc" ] ) = { } } ;
9931067 ( q . item [ "$inc" ] ) . _version = 1 ;
1068+ DatabaseConnection . mongodb_update_count . labels ( q . collectionname ) . inc ( ) ;
1069+ const end = DatabaseConnection . mongodb_update . startTimer ( ) ;
9941070 q . opresult = await this . db . collection ( q . collectionname ) . updateOne ( _query , q . item , options ) ;
1071+ end ( { collection : q . collectionname } ) ;
9951072 }
9961073 if ( q . collectionname != "fs.files" ) {
9971074 q . item = this . decryptentity ( q . item ) ;
@@ -1153,7 +1230,10 @@ export class DatabaseConnection {
11531230 q . result = uqres . result ;
11541231 } else {
11551232 if ( Config . log_updates ) this . _logger . debug ( "[" + user . username + "][" + q . collectionname + "] InsertOrUpdateOne, Inserting as new in database" ) ;
1233+ DatabaseConnection . mongodb_insert_count . labels ( q . collectionname ) . inc ( ) ;
1234+ const end = DatabaseConnection . mongodb_insert . startTimer ( ) ;
11561235 q . result = await this . InsertOne ( q . item , q . collectionname , q . w , q . j , q . jwt ) ;
1236+ end ( { collection : q . collectionname } ) ;
11571237 }
11581238 if ( q . collectionname === "users" && q . item . _type === "role" ) {
11591239 DBHelper . cached_roles = [ ] ;
@@ -1197,14 +1277,20 @@ export class DatabaseConnection {
11971277 _query = { $and : [ { _id : safeObjectID ( id ) } , this . getbasequery ( jwt , "metadata._acl" , [ Rights . delete ] ) ] } ;
11981278 const arr = await this . db . collection ( collectionname ) . find ( _query ) . toArray ( ) ;
11991279 if ( arr . length == 1 ) {
1280+ DatabaseConnection . mongodb_delete_count . labels ( collectionname ) . inc ( ) ;
1281+ const end = DatabaseConnection . mongodb_delete . startTimer ( ) ;
12001282 await this . _DeleteFile ( id ) ;
1283+ end ( { collection : collectionname } ) ;
12011284 return ;
12021285 } else {
12031286 throw Error ( "item not found!" ) ;
12041287 }
12051288 }
12061289 if ( Config . log_deletes ) this . _logger . verbose ( "[" + user . username + "][" + collectionname + "] Deleting " + id + " in database" ) ;
1290+ DatabaseConnection . mongodb_delete_count . labels ( collectionname ) . inc ( ) ;
1291+ const end = DatabaseConnection . mongodb_delete . startTimer ( ) ;
12071292 const res : DeleteWriteOpResultObject = await this . db . collection ( collectionname ) . deleteOne ( _query ) ;
1293+ end ( { collection : collectionname } ) ;
12081294 }
12091295
12101296 /**
@@ -1263,7 +1349,10 @@ export class DatabaseConnection {
12631349 if ( Config . log_deletes ) this . _logger . verbose ( "[" + user . username + "][" + collectionname + "] deleted " + arr . length + " items in database" ) ;
12641350 return arr . length ;
12651351 } else {
1352+ DatabaseConnection . mongodb_deletemany_count . labels ( collectionname ) . inc ( ) ;
1353+ const end = DatabaseConnection . mongodb_deletemany . startTimer ( ) ;
12661354 const res : DeleteWriteOpResultObject = await this . db . collection ( collectionname ) . deleteMany ( _query ) ;
1355+ end ( { collection : collectionname } ) ;
12671356 if ( Config . log_deletes ) this . _logger . verbose ( "[" + user . username + "][" + collectionname + "] deleted " + res . deletedCount + " items in database" ) ;
12681357 return res . deletedCount ;
12691358 }
@@ -1590,7 +1679,10 @@ export class DatabaseConnection {
15901679 _version : _version ,
15911680 reason : ""
15921681 }
1682+ DatabaseConnection . mongodb_insert_count . labels ( q . collectionname ) . inc ( ) ;
1683+ const end = DatabaseConnection . mongodb_insert . startTimer ( ) ;
15931684 await this . db . collection ( q . collectionname + '_hist' ) . insertOne ( updatehist ) ;
1685+ end ( { collection : q . collectionname } ) ;
15941686 } catch ( error ) {
15951687 this . _logger . error ( error ) ;
15961688 }
@@ -1680,7 +1772,10 @@ export class DatabaseConnection {
16801772 if ( baseversion == _version ) {
16811773 deltahist . item = original ;
16821774 }
1775+ DatabaseConnection . mongodb_insert_count . labels ( collectionname + '_hist' ) . inc ( ) ;
1776+ const end = DatabaseConnection . mongodb_insert . startTimer ( ) ;
16831777 await this . db . collection ( collectionname + '_hist' ) . insertOne ( deltahist ) ;
1778+ end ( { collection : collectionname + '_hist' } ) ;
16841779 }
16851780 } else {
16861781 const fullhist = {
@@ -1698,7 +1793,10 @@ export class DatabaseConnection {
16981793 _version : _version ,
16991794 reason : reason
17001795 }
1796+ DatabaseConnection . mongodb_insert_count . labels ( collectionname + '_hist' ) . inc ( ) ;
1797+ const end = DatabaseConnection . mongodb_insert . startTimer ( ) ;
17011798 await this . db . collection ( collectionname + '_hist' ) . insertOne ( fullhist ) ;
1799+ end ( { collection : collectionname + '_hist' } ) ;
17021800 }
17031801 item . _modifiedby = _modifiedby ;
17041802 item . _modifiedbyid = _modifiedbyid ;
0 commit comments