You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const path = require("path");
|
|
const knex = require("knex");
|
|
const { knexSnakeCaseMappers } = require("objection");
|
|
const prometheusClient = require("prom-client");
|
|
|
|
const models = require("./models");
|
|
|
|
let migrationsFolder = path.join(__dirname, "../migrations");
|
|
|
|
module.exports = function initialize({ knexfile }) {
|
|
let prometheusRegistry = new prometheusClient.Registry();
|
|
prometheusClient.collectDefaultMetrics({ register: prometheusRegistry });
|
|
|
|
let knexInstance = knex({
|
|
... knexfile,
|
|
... knexSnakeCaseMappers()
|
|
});
|
|
|
|
let state = {
|
|
knex: knexInstance,
|
|
prometheusRegistry: prometheusRegistry,
|
|
metrics: {
|
|
storedItems: new prometheusClient.Counter({
|
|
registers: [ prometheusRegistry ],
|
|
name: "srap_stored_items_total",
|
|
help: "Amount of items that have been created or updated",
|
|
labelNames: [ "tag" ]
|
|
}),
|
|
successfulItems: new prometheusClient.Counter({
|
|
registers: [ prometheusRegistry ],
|
|
name: "srap_successful_items_total",
|
|
help: "Amount of items that have been successfully processed",
|
|
labelNames: [ "task" ]
|
|
}),
|
|
failedItems: new prometheusClient.Counter({
|
|
registers: [ prometheusRegistry ],
|
|
name: "srap_failed_items_total",
|
|
help: "Amount of items that have failed during processing",
|
|
labelNames: [ "task" ]
|
|
}),
|
|
taskFetchTime: new prometheusClient.Gauge({
|
|
registers: [ prometheusRegistry ],
|
|
name: "srap_task_fetch_seconds",
|
|
help: "Time needed for the most recent attempt at fetching new scraping tasks",
|
|
labelNames: [ "task" ]
|
|
}),
|
|
taskFetchResults: new prometheusClient.Gauge({
|
|
registers: [ prometheusRegistry ],
|
|
name: "srap_task_fetch_results_count",
|
|
help: "Amount of new scraping tasks fetched during the most recent attempt",
|
|
labelNames: [ "task" ]
|
|
})
|
|
}
|
|
};
|
|
|
|
return Promise.try(() => {
|
|
return knexInstance.migrate.latest({
|
|
directory: migrationsFolder
|
|
});
|
|
}).then(() => {
|
|
return {
|
|
... state,
|
|
db: models(state)
|
|
};
|
|
});
|
|
};
|
|
|