question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use with Koa?

See original GitHub issue

I see the example is for express.js but I would like to use it with Koa, basically we just want to monitor open file descriptors (it will be hosted on linux) using prometheus.

The docs say:

See example folder for a sample usage. The library does not bundle any web framework, to expose the metrics just return the metrics() function in the registry.

Which I find confusing especially combined with the example which has a globalRegistry on line #5

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Jun 29, 2017

The example could probably be better and not use the internal prom-client globalRegistry property.

b4e9be54dc5d1172c78591d095495857c441b7b5

0reactions
montanaflynncommented, Jun 29, 2017

@siimon and @SimenB thanks so much I got it working!

let app = require('koa')();
let router = require('koa-router')();

const { register, collectDefaultMetrics } = require('prom-client');

collectDefaultMetrics();

router.get('/', function *(next) {
    yield next;
    this.body = "hello world";
});

router.get('/metrics', function *(next) {
    yield next;
    this.body = register.metrics();
});

app.use(router.routes());
app.use(router.allowedMethods());

app.listen(3000);
console.log('listening on port 3000');
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Build a "Hello World" Application with Koa
mkdir koa-example. Note: You can give your project any name, but this article will be using koa-example as the project name and directory....
Read more >
Koa - next generation web framework for node.js
Koa is a new web framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust...
Read more >
First steps with Koa.js - LogRocket Blog
This is a brief introduction to the powers of Koa.js and how it can make things ... The Koa middleware must be stated...
Read more >
Koa.js - Routing - Tutorialspoint
We need to use the Koa-router module to easily create routes in Koa. Install this module using the following command. npm install --save...
Read more >
Camping Loyalty Program & Discounts With KOA Rewards
Get 10% off your daily registration rate, rewards points to use on future stays, discounts from partners & more when you enroll in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found