Allow to set limits for ingest and egress processes
This commit is contained in:
parent
c263f1f0d4
commit
db1b5227fb
87
src/misc/controls/Limits.js
Normal file
87
src/misc/controls/Limits.js
Normal file
@ -0,0 +1,87 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Trans } from '@lingui/macro';
|
||||
import Grid from '@mui/material/Grid';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Typography from '@mui/material/Typography';
|
||||
|
||||
function init(settings) {
|
||||
const initSettings = {
|
||||
cpu_usage: 0,
|
||||
memory_mbytes: 0,
|
||||
waitfor_seconds: 5,
|
||||
...settings,
|
||||
};
|
||||
|
||||
return initSettings;
|
||||
}
|
||||
|
||||
export default function Control(props) {
|
||||
const settings = init(props.settings);
|
||||
|
||||
// Set the defaults
|
||||
React.useEffect(() => {
|
||||
props.onChange(settings, true);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const handleChange = (what) => (event) => {
|
||||
const value = event.target.value;
|
||||
|
||||
settings[what] = value;
|
||||
|
||||
props.onChange(settings, false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={12} md={4}>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
type="number"
|
||||
inputProps={{ min: 0, max: 100 }}
|
||||
label={<Trans>CPU Limit (percent)</Trans>}
|
||||
value={settings.cpu_usage}
|
||||
onChange={handleChange('cpu_usage')}
|
||||
/>
|
||||
<Typography variant="caption">
|
||||
<Trans>CPU usage limit in percent (0-100%), 0 for unlimited</Trans>
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4}>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
type="number"
|
||||
inputProps={{ min: 0 }}
|
||||
label={<Trans>Memory Limit (megabytes)</Trans>}
|
||||
value={settings.memory_mbytes}
|
||||
onChange={handleChange('memory_mbytes')}
|
||||
/>
|
||||
<Typography variant="caption">
|
||||
<Trans>Memory usage limit in megabytes, 0 for unlimited.</Trans>
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4}>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
type="number"
|
||||
inputProps={{ min: 0 }}
|
||||
label={<Trans>Threshold (seconds)</Trans>}
|
||||
value={settings.waitfor_seconds}
|
||||
onChange={handleChange('waitfor_seconds')}
|
||||
/>
|
||||
<Typography variant="caption">
|
||||
<Trans>Number of seconds the limits are allowed to be exceeded.</Trans>
|
||||
</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
|
||||
Control.defaulProps = {
|
||||
settings: {},
|
||||
onChange: function (settings, automatic) {},
|
||||
};
|
||||
@ -285,6 +285,11 @@ const defaultIngestMetadata = {
|
||||
enable: true,
|
||||
interval: 60,
|
||||
},
|
||||
limits: {
|
||||
cpu_usage: 0,
|
||||
memory_mbytes: 0,
|
||||
waitfor_seconds: 5,
|
||||
},
|
||||
},
|
||||
player: {},
|
||||
meta: {
|
||||
@ -311,6 +316,11 @@ const defaultEgressMetadata = {
|
||||
source: {
|
||||
source: 'hls+memfs',
|
||||
},
|
||||
limits: {
|
||||
cpu_usage: 0,
|
||||
memory_mbytes: 0,
|
||||
waitfor_seconds: 5,
|
||||
},
|
||||
},
|
||||
outputs: [],
|
||||
settings: {},
|
||||
|
||||
@ -1571,7 +1571,7 @@ class Restreamer {
|
||||
return await this._deleteProcess(channel.id + '_snapshot');
|
||||
}
|
||||
|
||||
// Upsert the ingest process
|
||||
// Update/Insert the ingest process
|
||||
async UpsertIngest(channelid, global, inputs, outputs, control) {
|
||||
const channel = this.GetChannel(channelid);
|
||||
if (!channel) {
|
||||
@ -1589,6 +1589,11 @@ class Restreamer {
|
||||
reconnect: control.process.reconnect,
|
||||
reconnect_delay_seconds: parseInt(control.process.delay),
|
||||
stale_timeout_seconds: parseInt(control.process.staleTimeout),
|
||||
limits: {
|
||||
cpu_usage: parseInt(control.limits.cpu_usage),
|
||||
memory_mbytes: parseInt(control.limits.memory_mbytes),
|
||||
waitfor_seconds: parseInt(control.limits.waitfor_seconds),
|
||||
},
|
||||
};
|
||||
|
||||
for (let i in inputs) {
|
||||
@ -2618,6 +2623,11 @@ class Restreamer {
|
||||
reconnect: control.process.reconnect,
|
||||
reconnect_delay_seconds: parseInt(control.process.delay),
|
||||
stale_timeout_seconds: parseInt(control.process.staleTimeout),
|
||||
limits: {
|
||||
cpu_usage: parseInt(control.limits.cpu_usage),
|
||||
memory_mbytes: parseInt(control.limits.memory_mbytes),
|
||||
waitfor_seconds: parseInt(control.limits.waitfor_seconds),
|
||||
},
|
||||
};
|
||||
|
||||
for (let i in outputs) {
|
||||
|
||||
@ -22,6 +22,7 @@ import Dialog from '../../misc/modals/Dialog';
|
||||
import H from '../../utils/help';
|
||||
import HLSControl from '../../misc/controls/HLS';
|
||||
import LicenseControl from '../../misc/controls/License';
|
||||
import LimitsControl from '../../misc/controls/Limits';
|
||||
import MetadataControl from '../../misc/controls/Metadata';
|
||||
import NotifyContext from '../../contexts/Notify';
|
||||
import Paper from '../../misc/Paper';
|
||||
@ -556,6 +557,17 @@ export default function Edit(props) {
|
||||
<Grid item xs={12}>
|
||||
<ProcessControl settings={$data.control.process} onChange={handleControlChange('process')} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Typography variant="h3">
|
||||
<Trans>Limits</Trans>
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<LimitsControl settings={$data.control.limits} onChange={handleControlChange('limits')} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabPanel>
|
||||
<TabPanel value={$tab} index="meta" className="panel">
|
||||
|
||||
@ -10,6 +10,7 @@ import useMediaQuery from '@mui/material/useMediaQuery';
|
||||
import Backdrop from '@mui/material/Backdrop';
|
||||
import Button from '@mui/material/Button';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Tab from '@mui/material/Tab';
|
||||
import Tabs from '@mui/material/Tabs';
|
||||
@ -24,6 +25,7 @@ import * as M from '../../utils/metadata';
|
||||
import EncodingSelect from '../../misc/EncodingSelect';
|
||||
import FilterSelect from '../../misc/FilterSelect';
|
||||
import H from '../../utils/help';
|
||||
import LimitsControl from '../../misc/controls/Limits';
|
||||
import NotifyContext from '../../contexts/Notify';
|
||||
import Paper from '../../misc/Paper';
|
||||
import PaperHeader from '../../misc/PaperHeader';
|
||||
@ -327,7 +329,7 @@ export default function Add(props) {
|
||||
</Button>
|
||||
</div>
|
||||
</Tooltip>
|
||||
</Grid>
|
||||
</Grid>,
|
||||
);
|
||||
} else {
|
||||
serviceList.push(
|
||||
@ -338,7 +340,7 @@ export default function Add(props) {
|
||||
<Typography>{s.name}</Typography>
|
||||
</div>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -448,6 +450,17 @@ export default function Add(props) {
|
||||
<Grid item xs={12}>
|
||||
<ProcessControl settings={$settings.control.process} onChange={handleControlChange('process')} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Typography variant="h2">
|
||||
<Trans>Limits</Trans>
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<LimitsControl settings={$settings.control.limits} onChange={handleControlChange('limits')} />
|
||||
</Grid>
|
||||
</TabContent>
|
||||
</TabPanel>
|
||||
<TabPanel value={$tab} index="encoding" className="panel">
|
||||
|
||||
@ -8,6 +8,7 @@ import makeStyles from '@mui/styles/makeStyles';
|
||||
import Backdrop from '@mui/material/Backdrop';
|
||||
import Button from '@mui/material/Button';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Link from '@mui/material/Link';
|
||||
import Tab from '@mui/material/Tab';
|
||||
@ -24,6 +25,7 @@ import Dialog from '../../misc/modals/Dialog';
|
||||
import EncodingSelect from '../../misc/EncodingSelect';
|
||||
import FilterSelect from '../../misc/FilterSelect';
|
||||
import H from '../../utils/help';
|
||||
import LimitsControl from '../../misc/controls/Limits';
|
||||
import NotifyContext from '../../contexts/Notify';
|
||||
import Paper from '../../misc/Paper';
|
||||
import PaperHeader from '../../misc/PaperHeader';
|
||||
@ -460,6 +462,17 @@ export default function Edit(props) {
|
||||
<Grid item xs={12}>
|
||||
<ProcessControl settings={$settings.control.process} onChange={handleControlChange('process')} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Divider />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Typography variant="h2">
|
||||
<Trans>Limits</Trans>
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<LimitsControl settings={$settings.control.limits} onChange={handleControlChange('limits')} />
|
||||
</Grid>
|
||||
<Grid item xs={12}>
|
||||
<Grid container spacing={1} className={classes.gridContainer}>
|
||||
{$unsavedChanges === true && (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user