{"action":"created","comment":{"url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/comments/56364866","id":56364866,"diff_hunk":"@@ -0,0 +1,130 @@\n+'use strict';\n+const metrics = require('next-metrics');\n+const reportError = require('./reportError');\n+const logger = require('@financial-times/n-logger').default;\n+\n+\n+const argv = require('minimist')(process.argv.slice(2));\n+const regions = [\n+\t'all',\n+\t'africa',\n+\t'anzac',\n+\t'asia',\n+\t'europe',\n+\t'latam',\n+\t'usa'\n+];\n+\n+const die = (errcode, msg) => {\n+\tlogger.error(`event=${errcode} msg=\"${msg}\"`);\n+\tsetImmediate(() => process.exit(1));\n+};\n+\n+if(!argv.service){\n+\tdie('NO_SERVICE_ERROR', 'No --service argument present');\n+}\n+\n+if (!process.env.FASTLY_APIKEY) {\n+\tdie('NO_FASTLY_APIKEY', 'You must set the FASTLY_APIKEY env var');\n+}\n+\n+\n+const serviceId = argv.service;\n+const fastly = require('fastly')(process.env.FASTLY_APIKEY, encodeURIComponent(serviceId), { verbose: true });\n+\n+const getStats = (region) => {\n+\n+\tlogger.info(`collecting fastly metrics for service ${serviceId} in region ${region}`);\n+\n+\treturn fastly\n+\t\t.stats(serviceId, {\n+\t\t\tfrom: '5 minutes ago',\n+\t\t\tto: '4 minutes ago',\n+\t\t\tby: 'minute',\n+\t\t\tregion: region\n+\t\t})\n+\t\t.then(stats => {\n+\n+\n+\t\t\ttry {\n+\t\t\t\tstats = JSON.parse(stats);\n+\t\t\t} catch (e) {\n+\t\t\t\tlogger.error(`event=JSON_PARSE_ERROR error=${e.toString()} json=${stats}`);\n+\t\t\t\tsetImmediate(() => process.exit(1));\n+\t\t\t}\n+\n+\t\t\tif (!stats.data) {\n+\t\t\t\tlogger.info('No data in response - giving up...');\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tif (!stats.data.length) {\n+\t\t\t\tlogger.info(`Data for ${region} is empty.`);\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tlogger.info(`Collected ${stats.data.length} stats for service ${serviceId} in region ${region}`);\n+\n+\n+\t\t\tstats.data.forEach((stats) => {\n+\n+\t\t\t\tconst m = {\n+\t\t\t\t\t'header_size': stats.header_size,\n+\t\t\t\t\t'body_size': stats.body_size,\n+\t\t\t\t\t'requests': stats.requests,\n+\t\t\t\t\t'hits': stats.hits,\n+\t\t\t\t\t'miss': stats.miss,\n+\t\t\t\t\t'uncacheable': stats.uncacheable,\n+\t\t\t\t\t'pass': stats.pass,\n+\t\t\t\t\t'pipe': stats.pipe,\n+\t\t\t\t\t'synth': stats.synth,\n+\t\t\t\t\t'hits_time': stats.hits_time,\n+\t\t\t\t\t'miss_time': stats.miss_time,\n+\t\t\t\t\t'status_1xx': stats.status_1xx,\n+\t\t\t\t\t'status_2xx': stats.status_2xx,\n+\t\t\t\t\t'status_3xx': stats.status_3xx,\n+\t\t\t\t\t'status_4xx': stats.status_4xx,\n+\t\t\t\t\t'status_5xx': stats.status_5xx,\n+\t\t\t\t\t'status_200': stats.status_200,\n+\t\t\t\t\t'status_204': stats.status_204,\n+\t\t\t\t\t'status_301': stats.status_301,\n+\t\t\t\t\t'status_302': stats.status_302,\n+\t\t\t\t\t'status_304': stats.status_304,\n+\t\t\t\t\t'status_503': stats.status_503,\n+\t\t\t\t\t'bandwidth': stats.bandwith,\n+\t\t\t\t\t'errors': stats.errors\n+\t\t\t\t};\n+\n+\t\t\t\tObject.keys(m).forEach(k => {\n+\t\t\t\t\tlogger.verbose(`fastly.${serviceId}.${region}.${k}`, m[k]);","path":"stats.js","position":99,"original_position":99,"commit_id":"8f42e4857833113dfe61bab8fbea27f3a10221ab","original_commit_id":"8f42e4857833113dfe61bab8fbea27f3a10221ab","user":{"login":"commuterjoy","id":84996,"avatar_url":"https://avatars.githubusercontent.com/u/84996?v=3","gravatar_id":"","url":"https://api.github.com/users/commuterjoy","html_url":"https://github.com/commuterjoy","followers_url":"https://api.github.com/users/commuterjoy/followers","following_url":"https://api.github.com/users/commuterjoy/following{/other_user}","gists_url":"https://api.github.com/users/commuterjoy/gists{/gist_id}","starred_url":"https://api.github.com/users/commuterjoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/commuterjoy/subscriptions","organizations_url":"https://api.github.com/users/commuterjoy/orgs","repos_url":"https://api.github.com/users/commuterjoy/repos","events_url":"https://api.github.com/users/commuterjoy/events{/privacy}","received_events_url":"https://api.github.com/users/commuterjoy/received_events","type":"User","site_admin":false},"body":"might break any alerting set up on these keys?","created_at":"2016-03-16T16:21:31Z","updated_at":"2016-03-16T16:21:31Z","html_url":"https://github.com/Financial-Times/next-fastly-to-graphite/pull/8#discussion_r56364866","pull_request_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/comments/56364866"},"html":{"href":"https://github.com/Financial-Times/next-fastly-to-graphite/pull/8#discussion_r56364866"},"pull_request":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8","id":63066425,"html_url":"https://github.com/Financial-Times/next-fastly-to-graphite/pull/8","diff_url":"https://github.com/Financial-Times/next-fastly-to-graphite/pull/8.diff","patch_url":"https://github.com/Financial-Times/next-fastly-to-graphite/pull/8.patch","issue_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/8","number":8,"state":"open","locked":false,"title":"Upgrade / rewrite","user":{"login":"aintgoin2goa","id":18816,"avatar_url":"https://avatars.githubusercontent.com/u/18816?v=3","gravatar_id":"","url":"https://api.github.com/users/aintgoin2goa","html_url":"https://github.com/aintgoin2goa","followers_url":"https://api.github.com/users/aintgoin2goa/followers","following_url":"https://api.github.com/users/aintgoin2goa/following{/other_user}","gists_url":"https://api.github.com/users/aintgoin2goa/gists{/gist_id}","starred_url":"https://api.github.com/users/aintgoin2goa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aintgoin2goa/subscriptions","organizations_url":"https://api.github.com/users/aintgoin2goa/orgs","repos_url":"https://api.github.com/users/aintgoin2goa/repos","events_url":"https://api.github.com/users/aintgoin2goa/events{/privacy}","received_events_url":"https://api.github.com/users/aintgoin2goa/received_events","type":"User","site_admin":false},"body":"- Brought app into 2016 with nbt config-vars etc\r\n- Copied code from spoor enrichment to split metrics by region - also now uses next-metrics\r\n- Split each service onto a seperate dyno\r\n- Added metrics for falcon service","created_at":"2016-03-16T13:45:59Z","updated_at":"2016-03-16T16:21:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ecc0b8ee3a37b9f933afa63b6cc243de15385e93","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8/commits","review_comments_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8/comments","review_comment_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/8/comments","statuses_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/statuses/8f42e4857833113dfe61bab8fbea27f3a10221ab","head":{"label":"Financial-Times:falcon2","ref":"falcon2","sha":"8f42e4857833113dfe61bab8fbea27f3a10221ab","user":{"login":"Financial-Times","id":3502508,"avatar_url":"https://avatars.githubusercontent.com/u/3502508?v=3","gravatar_id":"","url":"https://api.github.com/users/Financial-Times","html_url":"https://github.com/Financial-Times","followers_url":"https://api.github.com/users/Financial-Times/followers","following_url":"https://api.github.com/users/Financial-Times/following{/other_user}","gists_url":"https://api.github.com/users/Financial-Times/gists{/gist_id}","starred_url":"https://api.github.com/users/Financial-Times/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Financial-Times/subscriptions","organizations_url":"https://api.github.com/users/Financial-Times/orgs","repos_url":"https://api.github.com/users/Financial-Times/repos","events_url":"https://api.github.com/users/Financial-Times/events{/privacy}","received_events_url":"https://api.github.com/users/Financial-Times/received_events","type":"Organization","site_admin":false},"repo":{"id":27223852,"name":"next-fastly-to-graphite","full_name":"Financial-Times/next-fastly-to-graphite","owner":{"login":"Financial-Times","id":3502508,"avatar_url":"https://avatars.githubusercontent.com/u/3502508?v=3","gravatar_id":"","url":"https://api.github.com/users/Financial-Times","html_url":"https://github.com/Financial-Times","followers_url":"https://api.github.com/users/Financial-Times/followers","following_url":"https://api.github.com/users/Financial-Times/following{/other_user}","gists_url":"https://api.github.com/users/Financial-Times/gists{/gist_id}","starred_url":"https://api.github.com/users/Financial-Times/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Financial-Times/subscriptions","organizations_url":"https://api.github.com/users/Financial-Times/orgs","repos_url":"https://api.github.com/users/Financial-Times/repos","events_url":"https://api.github.com/users/Financial-Times/events{/privacy}","received_events_url":"https://api.github.com/users/Financial-Times/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Financial-Times/next-fastly-to-graphite","description":"","fork":false,"url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite","forks_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/forks","keys_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/teams","hooks_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/hooks","issue_events_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/events{/number}","events_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/events","assignees_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/assignees{/user}","branches_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/branches{/branch}","tags_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/tags","blobs_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/refs{/sha}","trees_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/statuses/{sha}","languages_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/languages","stargazers_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/stargazers","contributors_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/contributors","subscribers_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/subscribers","subscription_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/subscription","commits_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/commits{/sha}","git_commits_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/commits{/sha}","comments_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/comments{/number}","issue_comment_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/comments{/number}","contents_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/contents/{+path}","compare_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/merges","archive_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/downloads","issues_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues{/number}","pulls_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls{/number}","milestones_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/milestones{/number}","notifications_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/labels{/name}","releases_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/releases{/id}","deployments_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/deployments","created_at":"2014-11-27T12:11:50Z","updated_at":"2014-12-01T14:27:56Z","pushed_at":"2016-03-16T14:00:11Z","git_url":"git://github.com/Financial-Times/next-fastly-to-graphite.git","ssh_url":"git@github.com:Financial-Times/next-fastly-to-graphite.git","clone_url":"https://github.com/Financial-Times/next-fastly-to-graphite.git","svn_url":"https://github.com/Financial-Times/next-fastly-to-graphite","homepage":null,"size":17,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"Financial-Times:master","ref":"master","sha":"8a7e5e63c89816d5eb85ebb422f0a2495341a0a7","user":{"login":"Financial-Times","id":3502508,"avatar_url":"https://avatars.githubusercontent.com/u/3502508?v=3","gravatar_id":"","url":"https://api.github.com/users/Financial-Times","html_url":"https://github.com/Financial-Times","followers_url":"https://api.github.com/users/Financial-Times/followers","following_url":"https://api.github.com/users/Financial-Times/following{/other_user}","gists_url":"https://api.github.com/users/Financial-Times/gists{/gist_id}","starred_url":"https://api.github.com/users/Financial-Times/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Financial-Times/subscriptions","organizations_url":"https://api.github.com/users/Financial-Times/orgs","repos_url":"https://api.github.com/users/Financial-Times/repos","events_url":"https://api.github.com/users/Financial-Times/events{/privacy}","received_events_url":"https://api.github.com/users/Financial-Times/received_events","type":"Organization","site_admin":false},"repo":{"id":27223852,"name":"next-fastly-to-graphite","full_name":"Financial-Times/next-fastly-to-graphite","owner":{"login":"Financial-Times","id":3502508,"avatar_url":"https://avatars.githubusercontent.com/u/3502508?v=3","gravatar_id":"","url":"https://api.github.com/users/Financial-Times","html_url":"https://github.com/Financial-Times","followers_url":"https://api.github.com/users/Financial-Times/followers","following_url":"https://api.github.com/users/Financial-Times/following{/other_user}","gists_url":"https://api.github.com/users/Financial-Times/gists{/gist_id}","starred_url":"https://api.github.com/users/Financial-Times/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Financial-Times/subscriptions","organizations_url":"https://api.github.com/users/Financial-Times/orgs","repos_url":"https://api.github.com/users/Financial-Times/repos","events_url":"https://api.github.com/users/Financial-Times/events{/privacy}","received_events_url":"https://api.github.com/users/Financial-Times/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Financial-Times/next-fastly-to-graphite","description":"","fork":false,"url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite","forks_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/forks","keys_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/teams","hooks_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/hooks","issue_events_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/events{/number}","events_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/events","assignees_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/assignees{/user}","branches_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/branches{/branch}","tags_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/tags","blobs_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/refs{/sha}","trees_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/statuses/{sha}","languages_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/languages","stargazers_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/stargazers","contributors_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/contributors","subscribers_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/subscribers","subscription_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/subscription","commits_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/commits{/sha}","git_commits_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/git/commits{/sha}","comments_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/comments{/number}","issue_comment_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/comments{/number}","contents_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/contents/{+path}","compare_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/merges","archive_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/downloads","issues_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues{/number}","pulls_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls{/number}","milestones_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/milestones{/number}","notifications_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/labels{/name}","releases_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/releases{/id}","deployments_url":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/deployments","created_at":"2014-11-27T12:11:50Z","updated_at":"2014-12-01T14:27:56Z","pushed_at":"2016-03-16T14:00:11Z","git_url":"git://github.com/Financial-Times/next-fastly-to-graphite.git","ssh_url":"git@github.com:Financial-Times/next-fastly-to-graphite.git","clone_url":"https://github.com/Financial-Times/next-fastly-to-graphite.git","svn_url":"https://github.com/Financial-Times/next-fastly-to-graphite","homepage":null,"size":17,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8"},"html":{"href":"https://github.com/Financial-Times/next-fastly-to-graphite/pull/8"},"issue":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/8"},"comments":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/Financial-Times/next-fastly-to-graphite/statuses/8f42e4857833113dfe61bab8fbea27f3a10221ab"}}}}