{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/comments/83907961","pull_request_review_id":4720199,"id":83907961,"diff_hunk":"@@ -0,0 +1,293 @@\n+\"use strict\";\n+\n+var fs = require(\"fs\");\n+\n+var TICKS_PER_SEC = 100; // TODO(paul): look this up via sysconf(_SC_CLK_TCK)\n+\n+/**\n+ * Prometheus-style /metrics gathering and exporting.\n+ * This class provides a central location to register gauge and counter metrics\n+ * used to generate the <code>/metrics</code> page. It also contains collector\n+ * code to generate the standard <code>process_</code> and <code>nodejs_</code>\n+ * metrics:\n+ *   process_resident_memory_bytes\n+ *   process_virtual_memory_bytes\n+ *   process_heap_bytes\n+ *   process_cpu_seconds_total\n+ *   process_open_fds\n+ *   process_max_fds\n+ *   process_start_time_seconds\n+ *   nodejs_heap_used_bytes\n+ *\n+ * @example <caption>A simple metric that counts the keys in an object:</caption>\n+ *   var metrics = new Metrics();\n+ *\n+ *   var orange = {};\n+ *   metrics.addGauge({\n+ *       name: \"oranges\",\n+ *       help: \"current number of oranges\",\n+ *       refresh: (gauge) => {\n+ *           gauge.set({}, Object.keys(oranges).length);\n+ *       },\n+ *   });\n+ *\n+ * @example <caption>Generating values for multiple gauges in a single collector function.</caption>\n+ *   var metrics = new Metrics();\n+ *\n+ *   var oranges_gauge = metrics.addGauge({\n+ *       name: \"oranges\",\n+ *       help: \"current number of oranges\",\n+ *   });\n+ *   var apples_gauge = metrics.addGauge({\n+ *       name: \"apples\",\n+ *       help: \"current number of apples\",\n+ *   });\n+ *\n+ *   metrics.addCollector(() => {\n+ *       var counts = this._countFruit();\n+ *       oranges_gauge.set({}, counts.oranges);\n+ *       apples_gauge.set({}, counts.apples);\n+ *   });\n+ *\n+ * @example <caption>Using counters</caption>\n+ *   var metrics = new Metrics();\n+ *\n+ *   metrics.addCollector({\n+ *       name: \"things_made\",\n+ *       help: \"count of things that we have made\",\n+ *   });\n+ *\n+ *   function makeThing() {\n+ *       metrics.incCounter(\"things_made\");\n+ *       return new Thing();\n+ *   }\n+ *\n+ * @constructor\n+ */\n+function Metrics() {\n+    // Only attempt to load these dependencies if metrics are enabled\n+    var Prometheus = require(\"prometheus-client\");","path":"lib/components/metrics.js","position":72,"original_position":69,"commit_id":"543a998f24d6947225621ac9ec1f979990ab86c8","original_commit_id":"48a59bb770f6f9fd5c00bebac679f01a6b036263","user":{"login":"leonerd","id":350941,"avatar_url":"https://avatars.githubusercontent.com/u/350941?v=3","gravatar_id":"","url":"https://api.github.com/users/leonerd","html_url":"https://github.com/leonerd","followers_url":"https://api.github.com/users/leonerd/followers","following_url":"https://api.github.com/users/leonerd/following{/other_user}","gists_url":"https://api.github.com/users/leonerd/gists{/gist_id}","starred_url":"https://api.github.com/users/leonerd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonerd/subscriptions","organizations_url":"https://api.github.com/users/leonerd/orgs","repos_url":"https://api.github.com/users/leonerd/repos","events_url":"https://api.github.com/users/leonerd/events{/privacy}","received_events_url":"https://api.github.com/users/leonerd/received_events","type":"User","site_admin":false},"body":"Done 543a998","created_at":"2016-10-18T17:32:28Z","updated_at":"2016-10-18T17:32:29Z","html_url":"https://github.com/matrix-org/matrix-appservice-bridge/pull/32#discussion_r83907961","pull_request_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/comments/83907961"},"html":{"href":"https://github.com/matrix-org/matrix-appservice-bridge/pull/32#discussion_r83907961"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32","id":89824930,"html_url":"https://github.com/matrix-org/matrix-appservice-bridge/pull/32","diff_url":"https://github.com/matrix-org/matrix-appservice-bridge/pull/32.diff","patch_url":"https://github.com/matrix-org/matrix-appservice-bridge/pull/32.patch","issue_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/32","number":32,"state":"open","locked":false,"title":"Upport `Metrics.js` out of matrix-appservice-{slack,gitter}","user":{"login":"leonerd","id":350941,"avatar_url":"https://avatars.githubusercontent.com/u/350941?v=3","gravatar_id":"","url":"https://api.github.com/users/leonerd","html_url":"https://github.com/leonerd","followers_url":"https://api.github.com/users/leonerd/followers","following_url":"https://api.github.com/users/leonerd/following{/other_user}","gists_url":"https://api.github.com/users/leonerd/gists{/gist_id}","starred_url":"https://api.github.com/users/leonerd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonerd/subscriptions","organizations_url":"https://api.github.com/users/leonerd/orgs","repos_url":"https://api.github.com/users/leonerd/repos","events_url":"https://api.github.com/users/leonerd/events{/privacy}","received_events_url":"https://api.github.com/users/leonerd/received_events","type":"User","site_admin":false},"body":"Another step along #29.\r\n\r\nI'm hoping after this is in, to pull some more of the integration code out of the specific bridges and into the toplevel bridge object too, so it can export some gauges automatically and also apply hit counters to bits of internal API I can't see easily from the outside.","created_at":"2016-10-18T14:17:53Z","updated_at":"2016-10-18T17:32:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ef6207d71aa63d58436b74d52cfd4cb1cb70e8ac","assignee":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"assignees":[{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32/commits","review_comments_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32/comments","review_comment_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/32/comments","statuses_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/statuses/543a998f24d6947225621ac9ec1f979990ab86c8","head":{"label":"matrix-org:paul/upport-metrics","ref":"paul/upport-metrics","sha":"543a998f24d6947225621ac9ec1f979990ab86c8","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":41039785,"name":"matrix-appservice-bridge","full_name":"matrix-org/matrix-appservice-bridge","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-appservice-bridge","description":"Bridging infrastructure for Application Services","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge","forks_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/deployments","created_at":"2015-08-19T14:36:53Z","updated_at":"2016-07-18T22:05:11Z","pushed_at":"2016-10-18T17:32:21Z","git_url":"git://github.com/matrix-org/matrix-appservice-bridge.git","ssh_url":"git@github.com:matrix-org/matrix-appservice-bridge.git","clone_url":"https://github.com/matrix-org/matrix-appservice-bridge.git","svn_url":"https://github.com/matrix-org/matrix-appservice-bridge","homepage":null,"size":1039,"stargazers_count":7,"watchers_count":7,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4,"mirror_url":null,"open_issues_count":11,"forks":4,"open_issues":11,"watchers":7,"default_branch":"master"}},"base":{"label":"matrix-org:develop","ref":"develop","sha":"e2dec16854f364f7a07f71815540138a93ded0ab","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":41039785,"name":"matrix-appservice-bridge","full_name":"matrix-org/matrix-appservice-bridge","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-appservice-bridge","description":"Bridging infrastructure for Application Services","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge","forks_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/deployments","created_at":"2015-08-19T14:36:53Z","updated_at":"2016-07-18T22:05:11Z","pushed_at":"2016-10-18T17:32:21Z","git_url":"git://github.com/matrix-org/matrix-appservice-bridge.git","ssh_url":"git@github.com:matrix-org/matrix-appservice-bridge.git","clone_url":"https://github.com/matrix-org/matrix-appservice-bridge.git","svn_url":"https://github.com/matrix-org/matrix-appservice-bridge","homepage":null,"size":1039,"stargazers_count":7,"watchers_count":7,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4,"mirror_url":null,"open_issues_count":11,"forks":4,"open_issues":11,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32"},"html":{"href":"https://github.com/matrix-org/matrix-appservice-bridge/pull/32"},"issue":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/32"},"comments":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/matrix-appservice-bridge/statuses/543a998f24d6947225621ac9ec1f979990ab86c8"}}}}
{"actor":{"display_login":"leonerd"}}