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

Multiple Identifier #112

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
101 changes: 101 additions & 0 deletions Documentation/User Documentation/9. create_metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# The New Metrics User Interface
The new Metrics User Interface for ZEBRA allows users to create and delete custom metrics for prometheus. It contains two forms: New metrics and Existing metrics form. It also displays Metrics already created by the user and users can view and delete these metrics.

# Terminilogies
**Metric** : This represented an RMF III report and its LPAR. its format is LPAR_REPORT e.g RPRT_CPC, RPRT_CHANNEL, RPRT_SYSINFO. Only one metric can be created for each report in a single LPAR. This means only one CPC report can exist for RPRT LPAR. Below is an example of a CPC metric
```
"RPRT_CPC": {
"lpar": "RPRT",
"request": {
"report": "CPC",
"resource": ",RPRT,MVS_IMAGE"
},
"identifiers": [

]
}
```

**Identifiers** : This represent the parameters required to build a prometheus client metric from a Report. e.g parameters from CPC report needed to create a Total Utilization or effective utilization prometheus metric in ZEBRA. Each Metric can have multiple identifiers. Identifiers has 5 parameters:
- **Identifier Key**: This represent the parameter in a report that has a Unique value you will like to monitor. e.g CPCHPNAM in That represent Name of partition that collected the data in CPC report
- **Identifier Value**: This takes either ALL(to represent all Identifier key values) or a specific value for the identifier key (e.g VIRPT for CPCHPNAM in CPC report to signify intrest in only VIRPT LPAR data)
- **Metric ID (m_id)**: This is a unique ID selected by user to represent the Identifier (e.g TOU for Total Utilization, EFU for effective utilization)
- **Field**: This represent a numeric field in the report from which the number will be used to plot a chart in grafana. e.g CPCPLTOU which represent Logical processor total utilization, CPCPLEFU which represent Logical processor effective utilization in CPC Report
- **Description (desc)**: This is a user choosen description for the identifier

Below is an example of CPC metric with Total Utilization and Effective Utilization Identifiers
```
"RPRT_CPC": {
"lpar": "RPRT",
"request": {
"report": "CPC",
"resource": ",RPRT,MVS_IMAGE"
},
"identifiers": [
{
"field": "CPCPLTOU",
"key": "CPCPPNAM",
"value": "ALL",
"m_id": "TOU",
"desc": "CPC Total Utilization"
},
{
"key": "CPCPPNAM",
"value": "ALL",
"field": "CPCPLEFU",
"m_id": "EFU",
"desc": "Effective Utilization"
}
]
}
```
**Prometheus Metric** : These are the final metrics created by ZEBRA and exposed through http(s)://ZEBRA Ip:port/prommetric Endpoint. They are of the folloeing format:
```
{LPAR}_{IDENTIFIER_VALUE}_{METRIC_ID}
```

example of ZEBRA Prometheus Metrics

```
# HELP RPRT_TRNG_TOU CPC Total Utilization
# TYPE RPRT_TRNG_TOU gauge
RPRT_TRNG_TOU{parm="CPCPLTOU"} 0.4

# HELP RPRT_VIDVLP_TOU CPC Total Utilization
# TYPE RPRT_VIDVLP_TOU gauge
RPRT_VIDVLP_TOU{parm="CPCPLTOU"} 0.5

# HELP RPRT_VIRPT_TOU CPC Total Utilization
# TYPE RPRT_VIRPT_TOU gauge
RPRT_VIRPT_TOU{parm="CPCPLTOU"} 0.5

# HELP RPRT_TRNG_EFU Effective Utilization
# TYPE RPRT_TRNG_EFU gauge
RPRT_TRNG_EFU{parm="CPCPLEFU"} 0.4

# HELP RPRT_VIDVLP_EFU Effective Utilization
# TYPE RPRT_VIDVLP_EFU gauge
RPRT_VIDVLP_EFU{parm="CPCPLEFU"} 0.4

# HELP RPRT_VIRPT_EFU Effective Utilization
# TYPE RPRT_VIRPT_EFU gauge
RPRT_VIRPT_EFU{parm="CPCPLEFU"} 0.5
```

# How To create a Metric
- Using the metrics user interface (http://zebraIP:port/metrics)
- Click on New Metric. Use this form to add a new metric with one identifier
- Click Save

# How to Add Identifiers
- Using the metrics user interface (http://zebraIP:port/metrics)
- Click on Existing Metric
- Select The Metric from the drop Down
- Fill the form
- Click Save

# View and Delete Metric/Identifier
- From the dropdown under metrics added in the center of the page
- Select a metric to view it details
- Click Delete ID to delete a single identifier
- Click Delete Metric to delete the metric and its Identifiers
1 change: 1 addition & 0 deletions src/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ db
data
my.db
my.dbrefresh
admin.db

# node modules
node_modules
1 change: 0 additions & 1 deletion src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module.exports.token = function(req, res){
res.json({accessToken: accessToken})
})
});

}catch(err){
res.send("Token Generation Failed");
}
Expand Down
Binary file added src/admin.db
Binary file not shown.
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var path = require('path');
var cookieParser = require('cookie-parser');
const fs = require('fs');
var session = require('express-session');
const tls = require('tls');

const cors = require('cors');
const bodyParser = require('body-parser');
Expand Down Expand Up @@ -73,6 +74,7 @@ if(lpar_prom.length > 0){
}
//require("./Eureka_conn");
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
tls.DEFAULT_MIN_VERSION = "TLSv1.1";
var mainRouter = require('./app_server/routes/mainRouter');
var rmf3Router = require('./app_server/routes/rmf3Router');
var rmfppRouter = require('./app_server/routes/rmfppRouter');
Expand Down
105 changes: 93 additions & 12 deletions src/app_server/routes/mainRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ function parameters(fn){
usePrometheus: Zconfig.usePrometheus,
https: Zconfig.https,
grafanaurl: Zconfig.grafanaurl,
grafanaport: Zconfig.grafanaport
grafanaport: Zconfig.grafanaport
}
fn(parms); //return the parameters
}

router.get('/pwdd', (req, res) => { //remember to delete
/* router.get('/pwdd', (req, res) => { //remember to delete
res.render("login", {data: "pwd"})
})
}) */

// Checks if user login session is available in browser
var sessionChecker = (req, res, next) => {
Expand Down Expand Up @@ -96,6 +96,49 @@ router.post('/delmtr', (req, res) => {
});
});

router.post('/delid', (req, res) => {
fs.readFile('metrics.json', (err, data) => {
if (err) throw err;
let metricsfile = JSON.parse(data);
var id_len = metricsfile[req.body.ky]["identifiers"].length;
for(i=0; i < id_len; i++){
if (metricsfile[req.body.ky]["identifiers"][i]["m_id"] == req.body.id){
metricsfile[req.body.ky]["identifiers"].splice(i,1);
break;
}
}
fs.writeFile("metrics.json", JSON.stringify(metricsfile, null, '\t'), 'utf-8', function(err, data) {
res.send("Metric ID Deleted Successfully");
});
});
});


router.get('/getmetr', (req, res) => {
fs.readFile('metrics.json', (err, data) => {
if (err) throw err;
let metricsfile = JSON.parse(data);
res.send({sc:Object.keys(metricsfile)});
});
})

router.post('/getmetricdis', (req, res) => {
try{
var metric = req.body.metric;
fs.readFile('metrics.json', (err, data) => {
if (err) throw err;
let metricsfile = JSON.parse(data);
let mtr = metricsfile[metric]
res.send({sysid: mtr.lpar, rpt: mtr.request.report, rsc: mtr.request.resource, ids:mtr.identifiers});
});

}catch(err){
res.send("error")

}

})

router.post('/savemtr', (req, res) => {
try{
var lpar = req.body.lpar;
Expand All @@ -106,7 +149,7 @@ router.post('/savemtr', (req, res) => {
var umi = req.body.umi;
var umd = req.body.umd;
var rst = req.body.rst;
var key = `${lpar}_${snvl}_${umi}`;
var key = `${lpar}_${rpt}`;
var mtr = JSON.parse(`{
"lpar": "${lpar}",
"request": {
Expand All @@ -116,18 +159,56 @@ router.post('/savemtr', (req, res) => {
"identifiers": [
{
"key": "${nid}",
"value": "${snvl}"
"value": "${snvl}",
"field": "${vid}",
"m_id": "${umi}",
"desc": "${umd}"
}
],
"field": "${vid}",
"desc": "${umd}"
]
}`)
fs.readFile('metrics.json', (err, data) => {
if (err) throw err;
let metricsfile = JSON.parse(data);
metricsfile[`${key}`] = mtr
metrkeys = Object.keys(metricsfile);
if(metrkeys.includes(key)){
res.status(304).send();
}else {
metricsfile[`${key}`] = mtr
fs.writeFile("metrics.json", JSON.stringify(metricsfile, null, '\t'), 'utf-8', function(err, data) {
res.send("Metric Added Successfully");
});
}
});

}catch(err){
res.send("error")
}
})

router.post('/saveexmtr', (req, res) => {
try{
var metr = req.body.metr;
var nidex = req.body.nidex;
var snvlex = req.body.snvlex;
var videx = req.body.videx;
var umiex = req.body.umiex;
var umdex = req.body.umdex;
var idf = JSON.parse(`
{

"key": "${nidex}",
"value": "${snvlex}",
"field": "${videx}",
"m_id": "${umiex}",
"desc": "${umdex}"
}
`)
fs.readFile('metrics.json', (err, data) => {
if (err) throw err;
let metricsfile = JSON.parse(data);
(metricsfile[`${metr}`]["identifiers"]).push(idf)
fs.writeFile("metrics.json", JSON.stringify(metricsfile, null, '\t'), 'utf-8', function(err, data) {
res.send("Metric Added Successfully");
res.send("Metric Identifier Successfully");
});
});

Expand Down Expand Up @@ -201,9 +282,9 @@ router.get('/metrics', sessionChecker, (req, res) => {
}
//console.log(c);
if(req.session.name){ //Check if User login session is available
res.render("metrics",{msg:"Admin", resources:resource, lpars:lpar, reports:REPORTS.RMFM3}); // render the metrics page wih Admin previledge
res.render("metricdev",{msg:"Admin", resources:resource, lpars:lpar, reports:REPORTS.RMFM3}); // render the metrics page wih Admin previledge
}else{
res.render("metrics", {resources:resource, lpars:lpar, reports:REPORTS.RMFM3});
res.render("metricdev", {resources:resource, lpars:lpar, reports:REPORTS.RMFM3});
}
})

Expand Down
Loading
Loading