Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ apps/models

# Files generated by dask
apps/dask-worker-space

# vscode config
.vscode/
10 changes: 10 additions & 0 deletions deploy/templates/docker-compose.jin
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ services:
- JAGERENV={{environ.JAGERENV}}
- ACCESS_KEY={{services.obj_storage.credentials.access_key}}
- SECRET_KEY={{services.obj_storage.credentials.secret_key}}
prometheus:
{%- if build %}
build: "{{services.prometheus.buildpath}}"
{%- endif %}
image: "jagereye/prometheus:{{services.prometheus.version}}"
network_mode: "{{services.prometheus.network_mode}}"
ports:
{%- for key, port in services.prometheus.ports.items() %}
- "{{port}}"
{%- endfor %}
{%- endif %}
{%- if apps %}
{%- for app, content in apps.items() %}
Expand Down
48 changes: 48 additions & 0 deletions services/api/analyzers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ const MAX_ANALYZERS = 8
const NUM_OF_BRAINS = 1
const DEFAULT_REQUEST_TIMEOUT = 15000

// setup for prometheus
const prometheusClient = require('prom-client')
const register = prometheusClient.register
const Gauge = prometheusClient.Gauge
const g = new Gauge({
name: 'analyzer_status',
help: 'Analyzer status',
labelNames: ['analyzer']
});

// status mapping
const analyzerStatus = ['created','starting','running','source_down','stopped']

/*
* Projections
*/
Expand Down Expand Up @@ -444,6 +457,37 @@ function getAnalyzerPipeline(req, res, next) {
})
}

function getMetrics(req, res, next) {
models['analyzers'].find({}, getConfProjection, (err, list) => {
if (err) { return next(createError(500, null, err)) }
if (list.length === 0) { return res.status(200).send([]) }
const request = JSON.stringify({
command: 'READ',
params: list.map(x => x['_id'])
})
requestBackend(request, (reply, isLastReply, closeResponse) => {
if (reply['code'] && reply['code'] === NATS.REQ_TIMEOUT) {
let error = new Error('Timeout Error: Request: getting analyzers')
return next(createError(500, null, error))
}
if (reply['error']) {
closeResponse()
return next(createError(500, reply['error']['message']))
}
closeResponse()
result = list.map(x => {
let status = reply['result'][x['_id']]
g.labels(x['name']).set(analyzerStatus.indexOf(status))
return
})

res.set('Content-Type', register.contentType);
res.status(200).send(register.metrics())
return
})
})
}

/*
* Routing Table
*/
Expand All @@ -467,5 +511,9 @@ routesWithAuth(
['post', '/analyzer/:id/start', startAnalyzer],
['post', '/analyzer/:id/stop', stopAnalyzer],
)
routesWithAuth(
router,
['get', '/metrics', getMetrics]
)

module.exports = router
2 changes: 2 additions & 0 deletions services/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const cors = require('cors')
const config = require('./config')
const { users, createAdminUser } = require('./users')
const analyzers = require('./analyzers')
const status = require('./status')
const events = require('./events')
const helpers = require('./helpers')

Expand All @@ -20,6 +21,7 @@ app.use(expressValidator())
const API_ENTRY = `/${config.services.api.base_url}`
app.use(API_ENTRY, users)
app.use(API_ENTRY, analyzers)
app.use(API_ENTRY, status)
app.use(API_ENTRY, events)
app.use(API_ENTRY, helpers)

Expand Down
Loading