Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it actually locally or in cloud? #7

Open
Zachery2008 opened this issue Sep 8, 2020 · 1 comment
Open

How to use it actually locally or in cloud? #7

Zachery2008 opened this issue Sep 8, 2020 · 1 comment

Comments

@Zachery2008
Copy link

Zachery2008 commented Sep 8, 2020

Hey, firstly thank you for sharing this package. Could you add some supported document about how to run/use it actually?

I am trying use this package for my project. I have 2 bull job queues, the purpose is to send the metrics of bull queue to prometheus in order to autoscale my pods. For initial try/test locally, I wrote simple express server to create bull queue, add jobs into the queue by GET request, and I consume the job trivially.

import Queue from 'bull'
import express = require('express')
import sleep = require('sleep');

const producer = new Queue('testQueue', {
  redis: {
    port: parseInt(process.env.REDIS_PORT || '6379'),
    host: '127.0.0.1',
  }
})

const consumer = new Queue('testQueue', {
  redis: {
    port: parseInt(process.env.REDIS_PORT || '6379'),
    host: '127.0.0.1',
  }
})

const app: express.Application = express()

let countIdx  = 0;
app.get('/add-job', async function (req, res) {
  producer.add({
    jobIndex: countIdx
  })

  let jobCnt = await getQueueLenth()
  console.log('Number of jobs in queue: ' + jobCnt)

  countIdx++
  console.log('Total jobs have been added: ' + countIdx)

  res.send('a job has added sucessfully!')
})

function getQueueLenth(){
  return consumer.count()
}

consumer.process(1, async (job) => {
  //sleep.sleep(30)
  await pauseTime(5000)
  console.log(job.data)
})

function pauseTime(ms: number){
  return new Promise((resolve) => {
    setTimeout(resolve, ms)
  })
}

app.listen(3000)

And I have set up a local prometheus server locally. I'm not sure how to set up the configuration yml file properly. And I don't understand the meaning of promClient and how to send metrics to prometheus. The following is my code:

import Queue from 'bull';
import promClient from 'prom-client';
import * as bullProm from 'bull-prom';
 
const queue = new Queue('testQueue', {
  redis: {
    port: parseInt(process.env.REDIS_PORT || '6379'),
    host: '127.0.0.1',
  }
})
 
const bullMetric = bullProm.init({
  promClient, //promClient: '0.0.0.0:9090', // optional, it will use internal prom client if it is not given
  interval: 5000, // optional, in ms, default to 60000
})

const started = bullMetric.start(queue);

@pbadenski
Copy link
Collaborator

Hi, sorry, for delayed reply.. I currently don't use bull-prom anymore, so can't exactly remember. I will however accept pull requests, in case someone from the community is reading it.

At the moment I can only recommend you have a look at the source code or documentation of prom-client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants