Simplify, handle 0 case, lint and code style
This commit is contained in:
parent
d8e45a2fbc
commit
5bea3b55f4
@ -24,5 +24,3 @@ This can be generated via the Technitium DNS Dashboard, and should be generated
|
|||||||
#### Range
|
#### Range
|
||||||
|
|
||||||
`range` value determines how far back of statistics to pull data for. The value comes directly from Technitium API documentation found [here](https://github.com/TechnitiumSoftware/DnsServer/blob/master/APIDOCS.md#dashboard-api-calls), defined as `"type"`. The value can be one of: `LastHour`, `LastDay`, `LastWeek`, `LastMonth`, `LastYear`.
|
`range` value determines how far back of statistics to pull data for. The value comes directly from Technitium API documentation found [here](https://github.com/TechnitiumSoftware/DnsServer/blob/master/APIDOCS.md#dashboard-api-calls), defined as `"type"`. The value can be one of: `LastHour`, `LastDay`, `LastWeek`, `LastMonth`, `LastYear`.
|
||||||
|
|
||||||
**NOTE:** The value of `Custom` as specified in the API documentation is _NOT_ supported.
|
|
||||||
|
|||||||
@ -51,76 +51,69 @@ export default function Component({ service }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPercentage = (count, total) => {
|
function toPercent(value, total) {
|
||||||
return ((count / total) * 100).toPrecision(3);
|
return t("common.percent", {
|
||||||
};
|
value: !Number.isNaN(value / total) ? value / total : 0,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
const noErrorPercent = getPercentage(statsData.totalNoError, statsData.totalQueries);
|
});
|
||||||
const failurePercent = getPercentage(statsData.totalServerFailure, statsData.totalQueries);
|
}
|
||||||
const nxDomainPercent = getPercentage(statsData.totalNxDomain, statsData.totalQueries);
|
|
||||||
const refusedPercent = getPercentage(statsData.totalRefused, statsData.totalQueries);
|
|
||||||
const authoritativePercent = getPercentage(statsData.totalAuthoritative, statsData.totalQueries);
|
|
||||||
const recursivePercent = getPercentage(statsData.totalRecursive, statsData.totalQueries);
|
|
||||||
const cachedPercent = getPercentage(statsData.totalCached, statsData.totalQueries);
|
|
||||||
const blockedPercent = getPercentage(statsData.totalBlocked, statsData.totalQueries);
|
|
||||||
const droppedPercent = getPercentage(statsData.totalDropped, statsData.totalQueries);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="technitium.totalQueries" value={`${t("common.number", { value: statsData.totalQueries })}`} />
|
<Block label="technitium.totalQueries" value={`${t("common.number", { value: statsData.totalQueries })}`} />
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalNoError"
|
label="technitium.totalNoError"
|
||||||
value={`${t("common.number", { value: statsData.totalNoError })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalNoError })} (${toPercent(
|
||||||
value: noErrorPercent,
|
statsData.totalNoError / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalServerFailure"
|
label="technitium.totalServerFailure"
|
||||||
value={`${t("common.number", { value: statsData.totalServerFailure })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalServerFailure })} (${toPercent(
|
||||||
value: failurePercent,
|
statsData.totalServerFailure / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalNxDomain"
|
label="technitium.totalNxDomain"
|
||||||
value={`${t("common.number", { value: statsData.totalNxDomain })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalNxDomain })} (${toPercent(
|
||||||
value: nxDomainPercent,
|
statsData.totalNxDomain / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalRefused"
|
label="technitium.totalRefused"
|
||||||
value={`${t("common.number", { value: statsData.totalRefused })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalRefused })} (${toPercent(
|
||||||
value: refusedPercent,
|
statsData.totalRefused / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalAuthoritative"
|
label="technitium.totalAuthoritative"
|
||||||
value={`${t("common.number", { value: statsData.totalAuthoritative })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalAuthoritative })} (${toPercent(
|
||||||
value: authoritativePercent,
|
statsData.totalAuthoritative / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalRecursive"
|
label="technitium.totalRecursive"
|
||||||
value={`${t("common.number", { value: statsData.totalRecursive })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalRecursive })} (${toPercent(
|
||||||
value: recursivePercent,
|
statsData.totalRecursive / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalCached"
|
label="technitium.totalCached"
|
||||||
value={`${t("common.number", { value: statsData.totalCached })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalCached })} (${toPercent(
|
||||||
value: cachedPercent,
|
statsData.totalCached / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalBlocked"
|
label="technitium.totalBlocked"
|
||||||
value={`${t("common.number", { value: statsData.totalBlocked })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalBlocked })} (${toPercent(
|
||||||
value: blockedPercent,
|
statsData.totalBlocked / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block
|
<Block
|
||||||
label="technitium.totalDropped"
|
label="technitium.totalDropped"
|
||||||
value={`${t("common.number", { value: statsData.totalDropped })} (${t("common.percent", {
|
value={`${t("common.number", { value: statsData.totalDropped })} (${toPercent(
|
||||||
value: droppedPercent,
|
statsData.totalDropped / statsData.totalQueries,
|
||||||
})})`}
|
)})`}
|
||||||
/>
|
/>
|
||||||
<Block label="technitium.totalClients" value={`${t("common.number", { value: statsData.totalClients })}`} />
|
<Block label="technitium.totalClients" value={`${t("common.number", { value: statsData.totalClients })}`} />
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user