Skip to content

Commit

Permalink
Database size plugin - pill that displays current mongoDB database size
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvoy committed Jan 30, 2020
1 parent 24084c4 commit 1d6ada1
Show file tree
Hide file tree
Showing 21 changed files with 906 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,24 @@ For remote overrides, the following extended settings must be configured:
Enabled [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) so other websites can make request to your Nightscout site, uses these extended settings:
* `CORS_ALLOW_ORIGIN` (`*`) - The list of sites that are allow to make requests

##### `dbsize` (Database Size)
Show size of Nightscout Database, as a percentage of declared available space or in MiB.

Many deployments of Nightscout use free tier of MongoDB on Heroku, which is limited in size. After some time, as volume of stored data grows, it may happen that this limit is reached and system is unable to store new data. This plugin provides pill that indicates size of Database and shows (when configured) alarms regarding reaching space limit.

**IMPORTANT:** This plugin can only check how much space database already takes, _but cannot infer_ max size available on server for it. To have correct alarms and realistic percentage, `DBSIZE_MAX` need to be properly set - according to your mongoDB hosting configuration.

**NOTE:** It may happen that new data cannot be saved to database (due to size limits) even when this plugin reports that storage is not 100% full. MongoDB pre-allocate data in advance, and database file is always made bigger than total real data size. To avoid premature alarms, this plugin refers to data size instead of file size, but sets warning thresholds low. It may happen, that file size of database will take 100% of allowed space but there will be plenty of place inside to store the data. But it may also happen, with file size is at its max, that data size will be ~70% of file size, and there will be no place left. That may happen because data inside file is fragmented and free space _holes_ are too small for new entries. In such case calling `db.repairDatabase()` on mongoDB is recommended to compact and repack data (currently only doable with third-party mongoDB tools, but action is planned to be added in _Admin Tools_ section in future releases).

All sizes are expressed as integers, in _Mebibytes_ `1 MiB == 1024 KiB == 1024*1024 B`

* `ENABLE` - `dbsize` should be added to the list of plugins, for example: `ENABLE="dbsize"`.
* `DBSIZE_MAX` (`496`) - Maximal allowed size of database on your mongoDB server, default value is for standard Heroku mongoDB free tier
* `DBSIZE_WARN` (`300`) - Size threshold to show first warning about size, when database reach this size - pill will show size in yellow. Recommended ~60% of `DBSIZE_MAX`
* `DBSIZE_URGENT` (`370`) - When database reach this size, it is urgent to do backup and clean up old data, pill turns red. Recommended ~75% of `DBSIZE_MAX`
* `DBSIZE_ENABLE_ALERTS` (`false`) - Set to `true` to enable notifications about database size.
* `DBSIZE_IN_MIB` (`false`) - Set to `true` to display size of database in MiB-s instead of default percentage.

#### Extended Settings
Some plugins support additional configuration using extra environment variables. These are prefixed with the name of the plugin and a `_`. For example setting `MYPLUGIN_EXAMPLE_VALUE=1234` would make `extendedSettings.exampleValue` available to the `MYPLUGIN` plugin.

Expand Down
87 changes: 87 additions & 0 deletions assets/fonts/Nightscout Plugin Icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"metadata": {
"name": "Nightscout Plugin Icons",
"lastOpened": 0,
"created": 1580075608590
},
"iconSets": [
{
"selection": [
{
"order": 2,
"id": 0,
"name": "database",
"prevSize": 32,
"code": 59649,
"tempChar": ""
}
],
"id": 2,
"metadata": {
"name": "Plugin Icons",
"importSize": {
"width": 16,
"height": 18
}
},
"height": 1024,
"prevSize": 32,
"icons": [
{
"id": 0,
"paths": [
"M455.111 0c-251.449 0-455.111 101.831-455.111 227.556s203.662 227.556 455.111 227.556 455.111-101.831 455.111-227.556-203.662-227.556-455.111-227.556zM0 341.333v170.667c0 125.724 203.662 227.556 455.111 227.556s455.111-101.831 455.111-227.556v-170.667c0 125.724-203.662 227.556-455.111 227.556s-455.111-101.831-455.111-227.556zM0 625.778v170.667c0 125.724 203.662 227.556 455.111 227.556s455.111-101.831 455.111-227.556v-170.667c0 125.724-203.662 227.556-455.111 227.556s-455.111-101.831-455.111-227.556z"
],
"attrs": [
{}
],
"width": 910,
"isMulticolor": false,
"isMulticolor2": false,
"grid": 0,
"tags": [
"plugins"
]
}
],
"invisible": false,
"colorThemes": []
}
],
"preferences": {
"showGlyphs": true,
"showQuickUse": true,
"showQuickUse2": true,
"showSVGs": true,
"fontPref": {
"prefix": "plugicon-",
"metadata": {
"fontFamily": "pluginicons",
"majorVersion": 1,
"minorVersion": 0
},
"metrics": {
"emSize": 1024,
"baseline": 6.25,
"whitespace": 50
},
"embed": false,
"showSelector": false,
"showMetrics": false,
"showMetadata": false,
"showVersion": false
},
"imagePref": {
"prefix": "icon-",
"png": true,
"useClassSelector": true,
"color": 0,
"bgColor": 16777215,
"classSelector": ".icon"
},
"historySize": 50,
"showCodes": true,
"gridSize": 16
},
"uid": -1
}
28 changes: 28 additions & 0 deletions assets/fonts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
How to upgrade icons in icon-fonts on Nightscout
================================================

This guide is fol developers regarding how to add new icon to Nightscout.

Nightscout use icon fonts to render icons. Each icon is glyph (like - letter, or more like emoji character) inside custom made font file.
That way we have nice, vector icons, that are small, scalable, looks good on each platform, and are easy to embed inside CSS.

To extend existing icon set.:

1. Prepare minimalist, black & white icon in SVG tool of choice, and optimize it (you can use Inkscape) to be small in size and render good at small sizes.
2. Use https://icomoon.io/app and import accompanied JSON project file
3. Add SVG as new glyph. Remember to take care to set proper character code and CSS name
4. Save new version of JSON project file and store in this folder
5. Generate font, download zip file and unpack into this folder (update existing files)
6. Update `statc/css/main.css` file
* In section of `@font-face` with `font-family: 'pluginicons'`
* update part after `data:application/font-woff;charset=utf-8;base64,` with Base64-encoded content of previously generated WOFF font.
* update part after `data:application/font-svg;charset=utf-8;base64,` with Base64-encoded content of previously generated CSS font and
* copy/update all entries `.plugicon-****:before { content: "****"; }` from generated font `style.css` into `statc/css/main.css`

Hints
-----

* You can find many useful online tools to encode file into Base64, like: https://base64.guru/converter/encode/file
* Do not split Base64 output - it should be one LONG line
* Since update process is **manual** and generated fonts & updated CSS sections are **binary** - try to avoid **git merge conflicts** by speaking with other developers if you plan to add new icon
* When in doubt - check `git log` and reach last contributor for guidelines :)
7 changes: 7 additions & 0 deletions assets/fonts/pluginicons-v1.0/Read Me.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Open *demo.html* to see a list of all the glyphs in your font along with their codes/ligatures.

To use the generated font in desktop programs, you can install the TTF font. In order to copy the character associated with each icon, refer to the text box at the bottom right corner of each glyph in demo.html. The character inside this text box may be invisible; but it can still be copied. See this guide for more info: https://icomoon.io/#docs/local-fonts

You won't need any of the files located under the *demo-files* directory when including the generated font in your own projects.

You can import *selection.json* back to the IcoMoon app using the *Import Icons* button (or via Main Menu → Manage Projects) to retrieve your icon selection.
152 changes: 152 additions & 0 deletions assets/fonts/pluginicons-v1.0/demo-files/demo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
body {
padding: 0;
margin: 0;
font-family: sans-serif;
font-size: 1em;
line-height: 1.5;
color: #555;
background: #fff;
}
h1 {
font-size: 1.5em;
font-weight: normal;
}
small {
font-size: .66666667em;
}
a {
color: #e74c3c;
text-decoration: none;
}
a:hover, a:focus {
box-shadow: 0 1px #e74c3c;
}
.bshadow0, input {
box-shadow: inset 0 -2px #e7e7e7;
}
input:hover {
box-shadow: inset 0 -2px #ccc;
}
input, fieldset {
font-family: sans-serif;
font-size: 1em;
margin: 0;
padding: 0;
border: 0;
}
input {
color: inherit;
line-height: 1.5;
height: 1.5em;
padding: .25em 0;
}
input:focus {
outline: none;
box-shadow: inset 0 -2px #449fdb;
}
.glyph {
font-size: 16px;
width: 15em;
padding-bottom: 1em;
margin-right: 4em;
margin-bottom: 1em;
float: left;
overflow: hidden;
}
.liga {
width: 80%;
width: calc(100% - 2.5em);
}
.talign-right {
text-align: right;
}
.talign-center {
text-align: center;
}
.bgc1 {
background: #f1f1f1;
}
.fgc1 {
color: #999;
}
.fgc0 {
color: #000;
}
p {
margin-top: 1em;
margin-bottom: 1em;
}
.mvm {
margin-top: .75em;
margin-bottom: .75em;
}
.mtn {
margin-top: 0;
}
.mtl, .mal {
margin-top: 1.5em;
}
.mbl, .mal {
margin-bottom: 1.5em;
}
.mal, .mhl {
margin-left: 1.5em;
margin-right: 1.5em;
}
.mhmm {
margin-left: 1em;
margin-right: 1em;
}
.mls {
margin-left: .25em;
}
.ptl {
padding-top: 1.5em;
}
.pbs, .pvs {
padding-bottom: .25em;
}
.pvs, .pts {
padding-top: .25em;
}
.unit {
float: left;
}
.unitRight {
float: right;
}
.size1of2 {
width: 50%;
}
.size1of1 {
width: 100%;
}
.clearfix:before, .clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.hidden-true {
display: none;
}
.textbox0 {
width: 3em;
background: #f1f1f1;
padding: .25em .5em;
line-height: 1.5;
height: 1.5em;
}
#testDrive {
display: block;
padding-top: 24px;
line-height: 1.5;
}
.fs0 {
font-size: 16px;
}
.fs1 {
font-size: 32px;
}

30 changes: 30 additions & 0 deletions assets/fonts/pluginicons-v1.0/demo-files/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if (!('boxShadow' in document.body.style)) {
document.body.setAttribute('class', 'noBoxShadow');
}

document.body.addEventListener("click", function(e) {
var target = e.target;
if (target.tagName === "INPUT" &&
target.getAttribute('class').indexOf('liga') === -1) {
target.select();
}
});

(function() {
var fontSize = document.getElementById('fontSize'),
testDrive = document.getElementById('testDrive'),
testText = document.getElementById('testText');
function updateTest() {
testDrive.innerHTML = testText.value || String.fromCharCode(160);
if (window.icomoonLiga) {
window.icomoonLiga(testDrive);
}
}
function updateSize() {
testDrive.style.fontSize = fontSize.value + 'px';
}
fontSize.addEventListener('change', updateSize, false);
testText.addEventListener('input', updateTest, false);
testText.addEventListener('change', updateTest, false);
updateSize();
}());
52 changes: 52 additions & 0 deletions assets/fonts/pluginicons-v1.0/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>IcoMoon Demo</title>
<meta name="description" content="An Icon Font Generated By IcoMoon.io">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="demo-files/demo.css">
<link rel="stylesheet" href="style.css"></head>
<body>
<div class="bgc1 clearfix">
<h1 class="mhmm mvm"><span class="fgc1">Font Name:</span> pluginicons <small class="fgc1">(Glyphs:&nbsp;1)</small></h1>
</div>
<div class="clearfix mhl ptl">
<h1 class="mvm mtn fgc1">Grid Size: Unknown</h1>
<div class="glyph fs1">
<div class="clearfix bshadow0 pbs">
<span class="plugicon-database"></span>
<span class="mls"> plugicon-database</span>
</div>
<fieldset class="fs0 size1of1 clearfix hidden-false">
<input type="text" readonly value="e901" class="unit size1of2" />
<input type="text" maxlength="1" readonly value="&#xe901;" class="unitRight size1of2 talign-right" />
</fieldset>
<div class="fs0 bshadow0 clearfix hidden-true">
<span class="unit pvs fgc1">liga: </span>
<input type="text" readonly value="" class="liga unitRight" />
</div>
</div>
</div>

<!--[if gt IE 8]><!-->
<div class="mhl clearfix mbl">
<h1>Font Test Drive</h1>
<label>
Font Size: <input id="fontSize" type="number" class="textbox0 mbm"
min="8" value="48" />
px
</label>
<input id="testText" type="text" class="phl size1of1 mvl"
placeholder="Type some text to test..." value=""/>
<div id="testDrive" class="plugicon-" style="font-family: pluginicons">&nbsp;
</div>
</div>
<!--<![endif]-->
<div class="bgc1 clearfix">
<p class="mhl">Generated by <a href="https://icomoon.io/app">IcoMoon</a></p>
</div>

<script src="demo-files/demo.js"></script>
</body>
</html>
Binary file not shown.
Loading

0 comments on commit 1d6ada1

Please sign in to comment.