diff --git a/irods/connection/connection.go b/irods/connection/connection.go index ea43e07..8449169 100644 --- a/irods/connection/connection.go +++ b/irods/connection/connection.go @@ -31,6 +31,7 @@ type IRODSConnection struct { serverVersion *types.IRODSVersion generatedPasswordForPAM string // used for PAM auth lastSuccessfulAccess time.Time + transferMetrics types.TransferMetrics } // NewIRODSConnection create a IRODSConnection @@ -77,7 +78,7 @@ func (conn *IRODSConnection) Connect() error { conn.connected = false server := fmt.Sprintf("%s:%d", conn.Account.Host, conn.Account.Port) - logger.Infof("Connecting to %s", server) + logger.Debugf("Connecting to %s", server) socket, err := net.Dial("tcp", server) if err != nil { @@ -141,7 +142,7 @@ func (conn *IRODSConnection) connectWithCSNegotiation() (*types.IRODSVersion, er } // Send a startup message - logger.Info("Start up a connection with CS Negotiation") + logger.Debug("Start up a connection with CS Negotiation") startup := message.NewIRODSMessageStartupPack(conn.Account, conn.ApplicationName, true) startupMessage, err := startup.GetMessage() @@ -176,7 +177,7 @@ func (conn *IRODSConnection) connectWithCSNegotiation() (*types.IRODSVersion, er return version.GetVersion(), nil } else if negotiationMessage.Body.Type == message.RODS_MESSAGE_CS_NEG_TYPE { // Server responds with its own negotiation policy - logger.Info("Start up CS Negotiation") + logger.Debug("Start up CS Negotiation") negotiation := message.IRODSMessageCSNegotiation{} err = negotiation.FromMessage(negotiationMessage) @@ -189,7 +190,7 @@ func (conn *IRODSConnection) connectWithCSNegotiation() (*types.IRODSVersion, er return nil, fmt.Errorf("unable to parse server policy - %v", err) } - logger.Infof("Client policy - %s, server policy - %s", clientPolicy, serverPolicy) + logger.Debugf("Client policy - %s, server policy - %s", clientPolicy, serverPolicy) // Perform the negotiation policyResult, status := types.PerformCSNegotiation(clientPolicy, serverPolicy) @@ -229,7 +230,7 @@ func (conn *IRODSConnection) connectWithoutCSNegotiation() (*types.IRODSVersion, // No client-server negotiation // Send a startup message - logger.Info("Start up a connection without CS Negotiation") + logger.Debug("Start up a connection without CS Negotiation") startup := message.NewIRODSMessageStartupPack(conn.Account, conn.ApplicationName, false) version := message.IRODSMessageVersion{} @@ -248,7 +249,7 @@ func (conn *IRODSConnection) sslStartup() error { "function": "sslStartup", }) - logger.Info("Start up SSL") + logger.Debug("Start up SSL") irodsSSLConfig := conn.Account.SSLConfiguration if irodsSSLConfig == nil { @@ -318,7 +319,7 @@ func (conn *IRODSConnection) loginNative(password string) error { "function": "loginNative", }) - logger.Info("Logging in using native authentication method") + logger.Debug("Logging in using native authentication method") // authenticate authRequest := message.NewIRODSMessageAuthRequest() @@ -349,7 +350,7 @@ func (conn *IRODSConnection) loginPAM() error { "function": "loginPAM", }) - logger.Info("Logging in using pam authentication method") + logger.Debug("Logging in using pam authentication method") // Check whether ssl has already started, if not, start ssl. if _, ok := conn.socket.(*tls.Conn); !ok { @@ -383,7 +384,7 @@ func (conn *IRODSConnection) showTicket() error { "function": "showTicket", }) - logger.Info("Submitting a ticket to obtain access") + logger.Debug("Submitting a ticket to obtain access") if len(conn.Account.Ticket) > 0 { // show the ticket @@ -413,7 +414,7 @@ func (conn *IRODSConnection) Disconnect() error { "function": "Disconnect", }) - logger.Info("Disconnecting the connection") + logger.Debug("Disconnecting the connection") disconnect := message.NewIRODSMessageDisconnect() disconnectMessage, err := disconnect.GetMessage() @@ -461,6 +462,10 @@ func (conn *IRODSConnection) Send(buffer []byte, size int) error { return fmt.Errorf("unable to send data - %v", err) } + if size > 0 { + conn.IncreaseTransferMetricsBytesSent(uint64(size)) + } + conn.lastSuccessfulAccess = time.Now() return nil @@ -490,6 +495,10 @@ func (conn *IRODSConnection) Recv(buffer []byte, size int) (int, error) { return readLen, fmt.Errorf("unable to receive data - %v", err) } + if readLen > 0 { + conn.IncreaseTransferMetricsBytesReceived(uint64(readLen)) + } + conn.lastSuccessfulAccess = time.Now() return readLen, nil @@ -734,3 +743,93 @@ func (conn *IRODSConnection) RawBind(socket net.Conn) { conn.connected = true conn.socket = socket } + +/* + * Metrics related functions + */ + +// GetTransferMetrics returns transfer metrics +func (conn *IRODSConnection) GetTransferMetrics() types.TransferMetrics { + // returns a copy of metrics + return conn.transferMetrics +} + +// ClearTransferMetrics clears transfer metrics +func (conn *IRODSConnection) ClearTransferMetrics() { + conn.transferMetrics = types.TransferMetrics{} +} + +// IncreaseTransferMetricsBytesSent increases bytes sent metrics +func (conn *IRODSConnection) IncreaseTransferMetricsBytesSent(n uint64) { + conn.transferMetrics.BytesSent += n +} + +// IncreaseTransferMetricsBytesReceived increases bytes received metrics +func (conn *IRODSConnection) IncreaseTransferMetricsBytesReceived(n uint64) { + conn.transferMetrics.BytesReceived += n +} + +// IncreaseDataObjectMetricsStat increases stat data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsStat(n uint64) { + conn.transferMetrics.DataObjectIO.Stat += n +} + +// IncreaseDataObjectMetricsCreate increases create data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsCreate(n uint64) { + conn.transferMetrics.DataObjectIO.Create += n +} + +// IncreaseDataObjectMetricsDelete increases delete data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsDelete(n uint64) { + conn.transferMetrics.DataObjectIO.Delete += n +} + +// IncreaseDataObjectMetricsWrite increases write data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsWrite(n uint64) { + conn.transferMetrics.DataObjectIO.Write += n +} + +// IncreaseDataObjectMetricsRead increases read data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsRead(n uint64) { + conn.transferMetrics.DataObjectIO.Read += n +} + +// IncreaseDataObjectMetricsRename increases rename data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsRename(n uint64) { + conn.transferMetrics.DataObjectIO.Rename += n +} + +// IncreaseDataObjectMetricsMeta increases meta data object metrics +func (conn *IRODSConnection) IncreaseDataObjectMetricsMeta(n uint64) { + conn.transferMetrics.DataObjectIO.Meta += n +} + +// IncreaseCollectionMetricsStat increases stat collection metrics +func (conn *IRODSConnection) IncreaseCollectionMetricsStat(n uint64) { + conn.transferMetrics.CollectionIO.Stat += n +} + +// IncreaseCollectionMetricsList increases list collection metrics +func (conn *IRODSConnection) IncreaseCollectionMetricsList(n uint64) { + conn.transferMetrics.CollectionIO.List += n +} + +// IncreaseCollectionMetricsCreate increases create collection metrics +func (conn *IRODSConnection) IncreaseCollectionMetricsCreate(n uint64) { + conn.transferMetrics.CollectionIO.Create += n +} + +// IncreaseCollectionMetricsDelete increases delete collection metrics +func (conn *IRODSConnection) IncreaseCollectionMetricsDelete(n uint64) { + conn.transferMetrics.CollectionIO.Delete += n +} + +// IncreaseCollectionMetricsRename increases rename collection metrics +func (conn *IRODSConnection) IncreaseCollectionMetricsRename(n uint64) { + conn.transferMetrics.CollectionIO.Rename += n +} + +// IncreaseCollectionMetricsMeta increases meta collection metrics +func (conn *IRODSConnection) IncreaseCollectionMetricsMeta(n uint64) { + conn.transferMetrics.CollectionIO.Meta += n +} diff --git a/irods/fs/collection.go b/irods/fs/collection.go index 7c8dbf7..bd0d754 100644 --- a/irods/fs/collection.go +++ b/irods/fs/collection.go @@ -44,6 +44,8 @@ func GetCollection(conn *connection.IRODSConnection, path string) (*types.IRODSC return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsStat(1) + query := message.NewIRODSMessageQuery(common.MaxQueryRows, 0, 0, 0) query.AddSelect(common.ICAT_COLUMN_COLL_ID, 1) query.AddSelect(common.ICAT_COLUMN_COLL_NAME, 1) @@ -139,6 +141,8 @@ func ListCollectionMeta(conn *connection.IRODSConnection, path string) ([]*types return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsStat(1) + metas := []*types.IRODSMeta{} continueQuery := true @@ -234,6 +238,8 @@ func ListCollectionAccess(conn *connection.IRODSConnection, path string) ([]*typ return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + accesses := []*types.IRODSAccess{} continueQuery := true @@ -326,6 +332,8 @@ func ListSubCollections(conn *connection.IRODSConnection, path string) ([]*types return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsList(1) + collections := []*types.IRODSCollection{} continueQuery := true @@ -435,6 +443,8 @@ func CreateCollection(conn *connection.IRODSConnection, path string, recurse boo return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsCreate(1) + request := message.NewIRODSMessageMkcolRequest(path, recurse) response := message.IRODSMessageMkcolResponse{} return conn.RequestAndCheck(request, &response) @@ -446,6 +456,8 @@ func DeleteCollection(conn *connection.IRODSConnection, path string, recurse boo return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsDelete(1) + request := message.NewIRODSMessageRmcolRequest(path, recurse, force) response := message.IRODSMessageRmcolResponse{} err := conn.RequestAndCheck(request, &response) @@ -486,6 +498,8 @@ func MoveCollection(conn *connection.IRODSConnection, srcPath string, destPath s return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsRename(1) + request := message.NewIRODSMessageMvcolRequest(srcPath, destPath) response := message.IRODSMessageMvcolResponse{} err := conn.RequestAndCheck(request, &response) @@ -502,6 +516,8 @@ func AddCollectionMeta(conn *connection.IRODSConnection, path string, metadata * return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + request := message.NewIRODSMessageAddMetadataRequest(types.IRODSCollectionMetaItemType, path, metadata) response := message.IRODSMessageModMetaResponse{} return conn.RequestAndCheck(request, &response) @@ -514,6 +530,8 @@ func DeleteCollectionMeta(conn *connection.IRODSConnection, path string, metadat return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + var request *message.IRODSMessageModMetaRequest if metadata.AVUID != 0 { @@ -538,6 +556,8 @@ func SearchCollectionsByMeta(conn *connection.IRODSConnection, metaName string, return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + collections := []*types.IRODSCollection{} continueQuery := true @@ -650,6 +670,8 @@ func SearchCollectionsByMetaWildcard(conn *connection.IRODSConnection, metaName return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + collections := []*types.IRODSCollection{} continueQuery := true @@ -768,6 +790,8 @@ func ChangeAccessControlCollection(conn *connection.IRODSConnection, path string return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + request := message.NewIRODSMessageModAccessRequest(access.ChmodString(), userName, zoneName, path, recursive, adminFlag) response := message.IRODSMessageModAccessResponse{} err := conn.RequestAndCheck(request, &response) @@ -783,6 +807,8 @@ func SetInheritAccessControl(conn *connection.IRODSConnection, path string, inhe return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsMeta(1) + inheritStr := "inherit" if !inherit { diff --git a/irods/fs/data_object.go b/irods/fs/data_object.go index d8fef60..9e5cfb2 100644 --- a/irods/fs/data_object.go +++ b/irods/fs/data_object.go @@ -53,6 +53,8 @@ func GetDataObject(conn *connection.IRODSConnection, collection *types.IRODSColl return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsStat(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -230,6 +232,8 @@ func GetDataObjectMasterReplica(conn *connection.IRODSConnection, collection *ty return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsStat(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -388,6 +392,8 @@ func ListDataObjects(conn *connection.IRODSConnection, collection *types.IRODSCo return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsList(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -560,6 +566,8 @@ func ListDataObjectsMasterReplica(conn *connection.IRODSConnection, collection * return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseCollectionMetricsList(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -714,6 +722,8 @@ func ListDataObjectMeta(conn *connection.IRODSConnection, collection *types.IROD return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + metas := []*types.IRODSMeta{} continueQuery := true @@ -811,6 +821,8 @@ func ListDataObjectAccess(conn *connection.IRODSConnection, collection *types.IR return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + accesses := []*types.IRODSAccess{} continueQuery := true @@ -905,6 +917,8 @@ func DeleteDataObject(conn *connection.IRODSConnection, path string, force bool) return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsDelete(1) + request := message.NewIRODSMessageRmobjRequest(path, force) response := message.IRODSMessageRmobjResponse{} err := conn.RequestAndCheck(request, &response) @@ -920,6 +934,8 @@ func MoveDataObject(conn *connection.IRODSConnection, srcPath string, destPath s return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsRename(1) + request := message.NewIRODSMessageMvobjRequest(srcPath, destPath) response := message.IRODSMessageMvobjResponse{} err := conn.RequestAndCheck(request, &response) @@ -1009,6 +1025,8 @@ func CreateDataObject(conn *connection.IRODSConnection, path string, resource st return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsCreate(1) + request := message.NewIRODSMessageCreateobjRequest(path, resource, force) response := message.IRODSMessageCreateobjResponse{} err := conn.RequestAndCheck(request, &response) @@ -1028,7 +1046,11 @@ func OpenDataObject(conn *connection.IRODSConnection, path string, resource stri return nil, -1, fmt.Errorf("connection is nil or disconnected") } - request := message.NewIRODSMessageOpenobjRequest(path, resource, types.FileOpenMode(mode)) + fileOpenMode := types.FileOpenMode(mode) + + conn.IncreaseDataObjectMetricsCreate(1) + + request := message.NewIRODSMessageOpenobjRequest(path, resource, fileOpenMode) response := message.IRODSMessageOpenobjResponse{} err := conn.RequestAndCheck(request, &response) if err != nil { @@ -1045,7 +1067,7 @@ func OpenDataObject(conn *connection.IRODSConnection, path string, resource stri } // handle seek - _, seekToEnd := types.GetFileOpenFlagSeekToEnd(types.FileOpenMode(mode)) + _, seekToEnd := types.GetFileOpenFlagSeekToEnd(fileOpenMode) var offset int64 = 0 if seekToEnd { offset, err = SeekDataObject(conn, handle, 0, types.SeekEnd) @@ -1063,7 +1085,9 @@ func OpenDataObjectWithReplicaToken(conn *connection.IRODSConnection, path strin return nil, -1, fmt.Errorf("connection is nil or disconnected") } - request := message.NewIRODSMessageOpenobjRequestWithReplicaToken(path, types.FileOpenMode(mode), resourceHierarchy, replicaToken) + fileOpenMode := types.FileOpenMode(mode) + + request := message.NewIRODSMessageOpenobjRequestWithReplicaToken(path, fileOpenMode, resourceHierarchy, replicaToken) response := message.IRODSMessageOpenobjResponse{} err := conn.RequestAndCheck(request, &response) if err != nil { @@ -1080,7 +1104,7 @@ func OpenDataObjectWithReplicaToken(conn *connection.IRODSConnection, path strin } // handle seek - _, seekToEnd := types.GetFileOpenFlagSeekToEnd(types.FileOpenMode(mode)) + _, seekToEnd := types.GetFileOpenFlagSeekToEnd(fileOpenMode) var offset int64 = 0 if seekToEnd { offset, err = SeekDataObject(conn, handle, 0, types.SeekEnd) @@ -1098,7 +1122,9 @@ func OpenDataObjectWithOperation(conn *connection.IRODSConnection, path string, return nil, fmt.Errorf("connection is nil or disconnected") } - request := message.NewIRODSMessageOpenobjRequestWithOperation(path, resource, types.FileOpenMode(mode), oper) + fileOpenMode := types.FileOpenMode(mode) + + request := message.NewIRODSMessageOpenobjRequestWithOperation(path, resource, fileOpenMode, oper) response := message.IRODSMessageOpenobjResponse{} err := conn.RequestAndCheck(request, &response) if err != nil { @@ -1115,7 +1141,7 @@ func OpenDataObjectWithOperation(conn *connection.IRODSConnection, path string, } // handle seek - _, seekToEnd := types.GetFileOpenFlagSeekToEnd(types.FileOpenMode(mode)) + _, seekToEnd := types.GetFileOpenFlagSeekToEnd(fileOpenMode) if seekToEnd { _, err = SeekDataObject(conn, handle, 0, types.SeekEnd) if err != nil { @@ -1172,6 +1198,8 @@ func ReadDataObject(conn *connection.IRODSConnection, handle *types.IRODSFileHan return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsRead(1) + request := message.NewIRODSMessageReadobjRequest(handle.FileDescriptor, length) response := message.IRODSMessageReadobjResponse{} err := conn.RequestAndCheck(request, &response) @@ -1192,6 +1220,8 @@ func WriteDataObject(conn *connection.IRODSConnection, handle *types.IRODSFileHa return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsWrite(1) + request := message.NewIRODSMessageWriteobjRequest(handle.FileDescriptor, data) response := message.IRODSMessageWriteobjResponse{} err := conn.RequestAndCheck(request, &response) @@ -1223,6 +1253,8 @@ func AddDataObjectMeta(conn *connection.IRODSConnection, path string, metadata * return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + request := message.NewIRODSMessageAddMetadataRequest(types.IRODSDataObjectMetaItemType, path, metadata) response := message.IRODSMessageModMetaResponse{} err := conn.RequestAndCheck(request, &response) @@ -1239,6 +1271,8 @@ func DeleteDataObjectMeta(conn *connection.IRODSConnection, path string, metadat return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + var request *message.IRODSMessageModMetaRequest if metadata.AVUID != 0 { @@ -1263,6 +1297,8 @@ func SearchDataObjectsByMeta(conn *connection.IRODSConnection, metaName string, return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -1455,6 +1491,8 @@ func SearchDataObjectsMasterReplicaByMeta(conn *connection.IRODSConnection, meta return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -1630,6 +1668,8 @@ func SearchDataObjectsByMetaWildcard(conn *connection.IRODSConnection, metaName return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -1823,6 +1863,8 @@ func SearchDataObjectsMasterReplicaByMetaWildcard(conn *connection.IRODSConnecti return nil, fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + dataObjects := []*types.IRODSDataObject{} continueQuery := true @@ -1997,6 +2039,8 @@ func ChangeAccessControlDataObject(conn *connection.IRODSConnection, path string return fmt.Errorf("connection is nil or disconnected") } + conn.IncreaseDataObjectMetricsMeta(1) + request := message.NewIRODSMessageModAccessRequest(access.ChmodString(), userName, zoneName, path, false, adminFlag) response := message.IRODSMessageModAccessResponse{} err := conn.RequestAndCheck(request, &response) diff --git a/irods/fs/data_object_bulk.go b/irods/fs/data_object_bulk.go index 0ee90f4..571e3f5 100644 --- a/irods/fs/data_object_bulk.go +++ b/irods/fs/data_object_bulk.go @@ -165,7 +165,7 @@ func UploadDataObjectParallel(session *session.IRODSSession, localPath string, i return err } - logger.Infof("replicaToken %s, resourceHierarchy %s", replicaToken, resourceHierarchy) + logger.Debugf("replicaToken %s, resourceHierarchy %s", replicaToken, resourceHierarchy) errChan := make(chan error, numTasks) taskWaitGroup := sync.WaitGroup{} @@ -184,8 +184,6 @@ func UploadDataObjectParallel(session *session.IRODSSession, localPath string, i return } - logger.Info("Opening...") - taskHandle, _, taskErr := OpenDataObjectWithReplicaToken(taskConn, irodsPath, resource, "a", replicaToken, resourceHierarchy) if taskErr != nil { errChan <- taskErr @@ -200,8 +198,6 @@ func UploadDataObjectParallel(session *session.IRODSSession, localPath string, i } defer f.Close() - logger.Info("Seeking...") - taskNewOffset, taskErr := SeekDataObject(taskConn, taskHandle, taskOffset, types.SeekSet) if taskErr != nil { errChan <- fmt.Errorf("could not seek a data object - %v", taskErr) diff --git a/irods/session/pool.go b/irods/session/pool.go index 85db682..3621234 100644 --- a/irods/session/pool.go +++ b/irods/session/pool.go @@ -187,7 +187,7 @@ func (pool *ConnectionPool) Get() (*connection.IRODSConnection, bool, error) { if idleConn.IsConnected() { // move to occupied connections pool.occupiedConnections[idleConn] = true - logger.Info("Reuse an idle connection") + logger.Debug("Reuse an idle connection") return idleConn, false, nil } diff --git a/irods/session/session.go b/irods/session/session.go index 018b87f..eacd93e 100644 --- a/irods/session/session.go +++ b/irods/session/session.go @@ -13,6 +13,7 @@ type IRODSSession struct { connectionPool *ConnectionPool startNewTransaction bool poormansRollbackFail bool + transferMetrics types.TransferMetrics } // NewIRODSSession create a IRODSSession @@ -55,7 +56,7 @@ func NewIRODSSession(account *types.IRODSAccount, config *IRODSSessionConfig) (* // test if it can create a new transaction if sess.startNewTransaction { - logger.Infof("testing perform poor man rollback") + logger.Debugf("testing perform poor man rollback") conn, _, err := pool.Get() if err != nil { @@ -66,11 +67,11 @@ func NewIRODSSession(account *types.IRODSAccount, config *IRODSSessionConfig) (* err = conn.PoorMansRollback() if err != nil { - logger.Infof("could not perform poor man rollback for the connection, disabling poor mans rollback - %v", err) + logger.Warnf("could not perform poor man rollback for the connection, disabling poor mans rollback - %v", err) pool.Discard(conn) sess.poormansRollbackFail = true } else { - logger.Infof("using poor man rollback for the connection") + logger.Debugf("using poor man rollback for the connection") pool.Return(conn) } } @@ -117,7 +118,7 @@ func (sess *IRODSSession) AcquireConnection() (*connection.IRODSConnection, erro } else { err = conn.PoorMansRollback() if err != nil { - logger.Infof("could not perform poor man rollback for the connection, creating a new connection - %v", err) + logger.Warnf("could not perform poor man rollback for the connection, creating a new connection - %v", err) sess.connectionPool.Discard(conn) sess.poormansRollbackFail = true @@ -141,6 +142,11 @@ func (sess *IRODSSession) ReturnConnection(conn *connection.IRODSConnection) err "function": "ReturnConnection", }) + // add up metrics + metrics := conn.GetTransferMetrics() + sess.sumUpMetrics(&metrics) + conn.ClearTransferMetrics() + if sess.startNewTransaction && sess.poormansRollbackFail { // discard, since we cannot reuse the connection sess.connectionPool.Discard(conn) @@ -157,6 +163,12 @@ func (sess *IRODSSession) ReturnConnection(conn *connection.IRODSConnection) err // DiscardConnection discards a connection func (sess *IRODSSession) DiscardConnection(conn *connection.IRODSConnection) error { + + // add up metrics + metrics := conn.GetTransferMetrics() + sess.sumUpMetrics(&metrics) + conn.ClearTransferMetrics() + sess.connectionPool.Discard(conn) return nil } @@ -170,3 +182,33 @@ func (sess *IRODSSession) Release() { func (sess *IRODSSession) Connections() int { return sess.connectionPool.OpenConnections() } + +// sumUpMetrics adds up transfer metrics +func (sess *IRODSSession) sumUpMetrics(metrics *types.TransferMetrics) { + if metrics == nil { + return + } + + sess.transferMetrics.BytesReceived += metrics.BytesReceived + sess.transferMetrics.BytesSent += metrics.BytesSent + + sess.transferMetrics.CollectionIO.Stat += metrics.CollectionIO.Stat + sess.transferMetrics.CollectionIO.List += metrics.CollectionIO.List + sess.transferMetrics.CollectionIO.Create += metrics.CollectionIO.Create + sess.transferMetrics.CollectionIO.Delete += metrics.CollectionIO.Delete + sess.transferMetrics.CollectionIO.Rename += metrics.CollectionIO.Rename + sess.transferMetrics.CollectionIO.Meta += metrics.CollectionIO.Meta + + sess.transferMetrics.DataObjectIO.Stat += metrics.DataObjectIO.Stat + sess.transferMetrics.DataObjectIO.Create += metrics.DataObjectIO.Create + sess.transferMetrics.DataObjectIO.Delete += metrics.DataObjectIO.Delete + sess.transferMetrics.DataObjectIO.Rename += metrics.DataObjectIO.Rename + sess.transferMetrics.DataObjectIO.Meta += metrics.DataObjectIO.Meta + sess.transferMetrics.DataObjectIO.Read += metrics.DataObjectIO.Read + sess.transferMetrics.DataObjectIO.Write += metrics.DataObjectIO.Write +} + +// GetTransferMetrics returns transfer metrics +func (sess *IRODSSession) GetTransferMetrics() types.TransferMetrics { + return sess.transferMetrics +} diff --git a/irods/types/metrics.go b/irods/types/metrics.go new file mode 100644 index 0000000..1c325f0 --- /dev/null +++ b/irods/types/metrics.go @@ -0,0 +1,30 @@ +package types + +// CollectionIOMetrics - represents collection IO for access +type CollectionIOMetrics struct { + Stat uint64 + List uint64 + Delete uint64 + Create uint64 + Rename uint64 + Meta uint64 +} + +// DataObjectIOMetrics - represents data object IO for access +type DataObjectIOMetrics struct { + Stat uint64 + Read uint64 + Write uint64 + Delete uint64 + Create uint64 + Rename uint64 + Meta uint64 +} + +// TransferMetrics - represents bytes transferred for access +type TransferMetrics struct { + BytesReceived uint64 + BytesSent uint64 + CollectionIO CollectionIOMetrics + DataObjectIO DataObjectIOMetrics +} diff --git a/test/server/server.go b/test/server/server.go index 97ce428..a7d50e6 100644 --- a/test/server/server.go +++ b/test/server/server.go @@ -32,7 +32,7 @@ func startServerExec() error { serverDir := path.Dir(callerPath) scriptPath := fmt.Sprintf("%s/%s", serverDir, "start.sh") - logger.Infof("Executing %s", scriptPath) + logger.Debugf("Executing %s", scriptPath) cmd := exec.Command(scriptPath) cmd.Dir = serverDir @@ -83,7 +83,7 @@ func stopServerExec() error { serverDir := path.Dir(callerPath) scriptPath := fmt.Sprintf("%s/%s", serverDir, "stop.sh") - logger.Infof("Executing %s", scriptPath) + logger.Debugf("Executing %s", scriptPath) cmd := exec.Command(scriptPath) cmd.Dir = serverDir