Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Setup some metrics. Refs #1
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko committed Sep 16, 2014
1 parent 8529c23 commit 00d2188
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/coffee/commands/files-delete.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ try
if loadedCredentials and program.prefix

s3client = new S3Client loadedCredentials
s3client._metrics.increment 'commands.files.delete'

Logger.info 'Fetching files for prefix %s (with regex \'%s\')...', program.prefix, program.regex
s3client.filteredList {prefix: program.prefix, 'max-keys': program.maxKeys}, program.regex
Expand Down
1 change: 1 addition & 0 deletions src/coffee/commands/files-list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ try
if loadedCredentials and program.prefix

s3client = new S3Client loadedCredentials
s3client._metrics.increment 'commands.files.list'

Logger.info 'Fetching files for prefix %s (with regex \'%s\')...', program.prefix, program.regex
s3client.filteredList {prefix: program.prefix, 'max-keys': program.maxKeys}, program.regex
Expand Down
1 change: 1 addition & 0 deletions src/coffee/commands/files-upload.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ try
if loadedCredentials and program.source and program.target

s3client = new S3Client loadedCredentials
s3client._metrics.increment 'commands.files.upload'

Logger.info 'About to upload files to %s ...', program.target
bar = Logger.progress "Uploading file:\t[:bar] :percent, :current of :total files done (time: elapsed :elapseds, eta :etas)", 1
Expand Down
1 change: 1 addition & 0 deletions src/coffee/commands/images-convert.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ try
tmp.setGracefulCleanup()

s3client = new S3Client loadedCredentials, Logger
s3client._metrics.increment 'commands.images.convert'
descriptions = Helpers.parseJsonFromFile program.descriptions

# unsafeCleanup: recursively removes the created temporary directory, even when it's not empty
Expand Down
24 changes: 19 additions & 5 deletions src/coffee/services/s3client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ debug = require('debug')('s3utils-s3client')
_ = require 'underscore'
path = require 'path'
knox = require 'knox'
Lynx = require 'lynx'
Promise = require 'bluebird'
easyimage = require 'easyimage'
{CustomError} = require '../errors'
Expand Down Expand Up @@ -35,9 +36,11 @@ class S3Client
key: key
secret: secret
bucket: bucket

@_knoxClient = Promise.promisifyAll @_knoxClient

@_metrics = new Lynx 'localhost', 8125,
on_error: -> #noop

on: (eventName, cb) -> @_ee.on eventName, cb
emit: (eventName, obj) -> @_ee.emit eventName, obj

Expand All @@ -46,7 +49,9 @@ class S3Client
* @param {Object} headers The request headers for AWS (S3)
* @return {Promise} A promise, fulfilled with the response or rejected with an error
###
list: (headers) -> @_knoxClient.listAsync headers
list: (headers) ->
@_metrics.increment 'file.list'
@_knoxClient.listAsync headers

###*
* Lists all files in the given bucket, filtering by an optional regex
Expand Down Expand Up @@ -78,7 +83,9 @@ class S3Client
* @param {String} source The path to the remote file (bucket)
* @return {Promise} A promise, fulfilled with the response or rejected with an error
###
getFile: (source) -> @_knoxClient.getFileAsync source
getFile: (source) ->
@_metrics.increment 'file.get'
@_knoxClient.getFileAsync source

###*
* Uploads a given file to the given bucket, optionally showing the upload progress
Expand All @@ -90,6 +97,7 @@ class S3Client
###
putFile: (source, target, header, progressBar) ->
new Promise (resolve, reject) =>
@_metrics.increment 'file.put'
upload = @_knoxClient.putFile source, target, header, (err, resp) ->
if err
reject err
Expand Down Expand Up @@ -135,7 +143,9 @@ class S3Client
* @param {String} filename The path to the remote destination file (bucket)
* @return {Promise} A promise, fulfilled with the response or rejected with an error
###
copyFile: (source, destination) -> @_knoxClient.copyFileAsync source, destination
copyFile: (source, destination) ->
@_metrics.increment 'file.copy'
@_knoxClient.copyFileAsync source, destination

###*
* Moves a given file to the given bucket
Expand All @@ -151,7 +161,9 @@ class S3Client
* @param {String} file The path to the remote file to be deleted (bucket)
* @return {Promise} A promise, fulfilled with the response or rejected with an error
###
deleteFile: (file) -> @_knoxClient.deleteFileAsync file
deleteFile: (file) ->
@_metrics.increment 'file.delete'
@_knoxClient.deleteFileAsync file

###*
* @private
Expand Down Expand Up @@ -191,6 +203,7 @@ class S3Client
width: format.width
height: format.height
.then (image) =>
@_metrics.increment 'image.resized'
header = 'x-amz-acl': 'public-read'
aws_content_key = @_imageKey "#{prefix}#{basename}", format.suffix, extension
debug 'about to upload resized image to %s', aws_content_key
Expand All @@ -214,6 +227,7 @@ class S3Client
Promise.map images, (image) =>
name = path.basename(image.Key)
debug 'about to get image %s', name
@_metrics.increment 'image.count'
@getFile(image.Key)
.then (response) ->
tmp_resized = "#{tmpDir}/#{name}"
Expand Down

0 comments on commit 00d2188

Please sign in to comment.