-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometeus-export.js
36 lines (30 loc) · 1.02 KB
/
prometeus-export.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const MicroserviceClient = require('@microservice-framework/microservice-client');
require('dotenv').config();
var client = new MicroserviceClient({
URL: process.env.SELF_URL,
secureKey: process.env.SECURE_KEY
});
let apiname = 'unknow'
if (process.env.NAME) {
apiname = process.env.NAME
}
let metricName = 'mfwapi_requests_total'
console.log('#HELP ' + metricName + ' The total numbers of mfwapi requests')
console.log('#TYPE ' + metricName + ' counter')
client.search({ }, function(err, handlerResponse){
//console.log(handlerResponse)
for (let name in handlerResponse) {
for (let method in handlerResponse[name].methods) {
for (let code in handlerResponse[name].methods[method]) {
let count = handlerResponse[name].methods[method][code]
let statLine = metricName + '{'
+ 'name="' + apiname + '"'
+ ',path="' + name + '"'
+ ',method="' + method + '"'
+ ',code="' + code + '"'
+ '} ' + count ;
console.log(statLine)
}
}
}
});