{"action":"opened","issue":{"url":"https://api.github.com/repos/siimon/prom-client/issues/203","repository_url":"https://api.github.com/repos/siimon/prom-client","labels_url":"https://api.github.com/repos/siimon/prom-client/issues/203/labels{/name}","comments_url":"https://api.github.com/repos/siimon/prom-client/issues/203/comments","events_url":"https://api.github.com/repos/siimon/prom-client/issues/203/events","html_url":"https://github.com/siimon/prom-client/issues/203","id":337668128,"node_id":"MDU6SXNzdWUzMzc2NjgxMjg=","number":203,"title":"Running cluster mode + aggregation metrics as api","user":{"login":"lfender6445","id":959505,"node_id":"MDQ6VXNlcjk1OTUwNQ==","avatar_url":"https://avatars2.githubusercontent.com/u/959505?v=4","gravatar_id":"","url":"https://api.github.com/users/lfender6445","html_url":"https://github.com/lfender6445","followers_url":"https://api.github.com/users/lfender6445/followers","following_url":"https://api.github.com/users/lfender6445/following{/other_user}","gists_url":"https://api.github.com/users/lfender6445/gists{/gist_id}","starred_url":"https://api.github.com/users/lfender6445/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lfender6445/subscriptions","organizations_url":"https://api.github.com/users/lfender6445/orgs","repos_url":"https://api.github.com/users/lfender6445/repos","events_url":"https://api.github.com/users/lfender6445/events{/privacy}","received_events_url":"https://api.github.com/users/lfender6445/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-02T21:24:07Z","updated_at":"2018-07-02T21:24:07Z","closed_at":null,"author_association":"NONE","body":"I'd like to collect aggregate metrics via koa midlleware \r\n\r\n```jsx\r\nimport mount from 'koa-mount'\r\n\r\nconst AggregatorRegistry = require('prom-client').AggregatorRegistry\r\n\r\nconst registry = new AggregatorRegistry()\r\n\r\nconst metricsServer = ctx => {\r\n  registry.clusterMetrics((err, metrics) => {\r\n    console.log('made it here', metrics)\r\n    if (err) console.log('Prometheus aggregation error', err)\r\n    ctx.status = 200\r\n    ctx.headers['content-type'] = registry.contentType\r\n    ctx.body = metrics\r\n  })\r\n}\r\n\r\nexport default koaApp => {\r\n  koaApp.use(\r\n    mount('/metrics', metricsServer)\r\n  )\r\n}\r\n```\r\n\r\nBut I get a failure here https://github.com/siimon/prom-client/blob/master/lib/cluster.js#L41\r\n\r\n`TypeError: Cannot convert undefined or null to object` because cluster.workers is undefined - i am however running my app in cluster mode - any thoughts on why cluster.workers comes back undefined? Does the app think its running on a single thread? \r\n\r\nI have had success following the example that runs aggregate metrics from a standalone server rather than middleware but was hoping someone could shed light on what i'm missing here\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"lfender6445"}}