"use strict";
import classNames from "classnames";
import PropTypes from "prop-types";
import createReactClass from "create-react-class";
var PT = PropTypes;
var StatisticsPage = createReactClass({
// fixme! - class StatisticsPage extends React.Component {
propTypes: {
ajax: PT.func.isRequired,
},
getInitialState: function () {
return {
stats: {},
activeTab: 0,
// searchStats: {},
// lastScanStats: {},
};
},
componentDidMount: function() {
this.refreshStats();
},
refreshStats: function() {
this.props.ajax({
url: 'rest/statistics',
success: function(json, textStatus, jqXHR) {
this.setState({stats: json});
// console.log("stats:", json);
}.bind(this),
});
},
renderWaitTimeSecs: function(t) {
var hue = t * 4;
if (hue > 120) {
hue = 120;
}
var a = hue/120;
hue = 120 - hue;
var shue = "hsla("+hue+",100%,80%,"+a+")";
return
{t.toFixed(3)}s
;
},
renderCollections: function(colls) {
return
{ colls.length === 0 ?
NO collections found
:
{colls.length} root collection(s):
{ colls.map(function(name, i) { return {name}
; }) }
}
;
},
renderDiagnostic: function(d) {
var classes = "inline alert alert-warning " + (d.diagnostic.uri === 'LEGACY' ? "legacy" : "");
return
{ d.counter <= 1 ? false :
x {d.counter}
}
Diagnostic: {d.diagnostic.message}: {d.diagnostic.diagnostic}
;
},
renderError: function(e) {
var xc = e.exception;
return
{ e.counter <= 1 ? false :
x {e.counter}
}
Exception: {xc.message}
{ xc.cause ?
Caused by: {xc.cause}
: false}
;
},
renderEndpoint: function(isScan, endpoint) {
var stat = endpoint[1];
var errors = _.values(stat.errors);
var diagnostics = _.values(stat.diagnostics);
return
-
{ stat.version == "LEGACY" ?
legacy
: stat.version == "VERSION_1" ? version 1
: version 2
}
{ " "+endpoint[0] }
{ isScan ?
Max concurrent scan requests:{" "} {stat.maxConcurrentRequests}
:
Max concurrent search requests:{" "} {stat.maxConcurrentRequests}
}
{stat.numberOfRequests} request(s),
average:{this.renderWaitTimeSecs(stat.avgExecutionTime)},
max: {this.renderWaitTimeSecs(stat.maxExecutionTime)}
{ isScan ? this.renderCollections(stat.rootCollections) : false }
{ (errors && errors.length) ?
{ errors.map(this.renderError) }
: false
}
{ (diagnostics && diagnostics.length) ?
{ diagnostics.map(this.renderDiagnostic) }
: false
}
;
},
renderInstitution: function(isScan, inst) {
return
{inst[0]}
{_.pairs(inst[1]).map(this.renderEndpoint.bind(this, isScan)) }
;
},
renderStatistics: function(stats) {
return
Start date: {new Date(stats.date).toLocaleString()}
Timeout: {" "}{stats.timeout} seconds
{ _.pairs(stats.institutions).map(this.renderInstitution.bind(this, stats.isScan)) }
;
},
setTab: function(idx) {
this.setState({activeTab:idx});
},
render: function() {
return (
Statistics
{ _.pairs(this.state.stats).map(function(st, idx){
var classname = idx === this.state.activeTab ? "active":"";
return -
{st[0]}
;
}.bind(this))
}
{ _.pairs(this.state.stats).map(function(st, idx){
var classname = idx === this.state.activeTab ? "tab-pane active" : "tab-pane";
return
{this.renderStatistics(st[1])}
;
}.bind(this))
}
);
},
});
module.exports = StatisticsPage;