2022-05-18 10:39:11 +00:00
|
|
|
part of 'server_details_screen.dart';
|
2021-04-10 03:04:23 +00:00
|
|
|
|
|
|
|
class _Chart extends StatelessWidget {
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final HetznerMetricsCubit cubit = context.watch<HetznerMetricsCubit>();
|
|
|
|
final Period period = cubit.state.period;
|
|
|
|
final HetznerMetricsState state = cubit.state;
|
2021-04-10 03:04:23 +00:00
|
|
|
List<Widget> charts;
|
|
|
|
if (state is HetznerMetricsLoading) {
|
|
|
|
charts = [
|
|
|
|
Container(
|
|
|
|
height: 200,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text('basis.loading'.tr()),
|
|
|
|
)
|
|
|
|
];
|
|
|
|
} else if (state is HetznerMetricsLoaded) {
|
|
|
|
charts = [
|
2022-05-24 18:55:39 +00:00
|
|
|
const Legend(color: Colors.red, text: 'CPU %'),
|
|
|
|
const SizedBox(height: 20),
|
2021-10-13 21:49:24 +00:00
|
|
|
getCpuChart(state),
|
2021-04-10 03:04:23 +00:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
BrandText.small('Public Network interface packets per sec'),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(width: 10),
|
|
|
|
const Legend(color: Colors.red, text: 'IN'),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
const Legend(color: Colors.green, text: 'OUT'),
|
2021-04-10 03:04:23 +00:00
|
|
|
],
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 20),
|
2021-10-13 21:49:24 +00:00
|
|
|
getPpsChart(state),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 1),
|
2021-04-10 03:04:23 +00:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
BrandText.small('Public Network interface bytes per sec'),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(width: 10),
|
|
|
|
const Legend(color: Colors.red, text: 'IN'),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
const Legend(color: Colors.green, text: 'OUT'),
|
2021-04-10 03:04:23 +00:00
|
|
|
],
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 20),
|
2021-04-10 03:04:23 +00:00
|
|
|
getBandwidthChart(state),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
throw 'wrong state';
|
|
|
|
}
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 5),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
2022-05-24 18:55:39 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10),
|
2021-04-10 03:04:23 +00:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
BrandRadioTile(
|
|
|
|
isChecked: period == Period.month,
|
|
|
|
text: 'providers.server.chart.month'.tr(),
|
|
|
|
onPress: () => cubit.changePeriod(Period.month),
|
|
|
|
),
|
|
|
|
BrandRadioTile(
|
|
|
|
isChecked: period == Period.day,
|
|
|
|
text: 'providers.server.chart.day'.tr(),
|
|
|
|
onPress: () => cubit.changePeriod(Period.day),
|
|
|
|
),
|
|
|
|
BrandRadioTile(
|
|
|
|
isChecked: period == Period.hour,
|
|
|
|
text: 'providers.server.chart.hour'.tr(),
|
|
|
|
onPress: () => cubit.changePeriod(Period.hour),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
...charts,
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget getCpuChart(final HetznerMetricsLoaded state) {
|
|
|
|
final data = state.cpu;
|
2021-04-10 03:04:23 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
return SizedBox(
|
2021-04-10 03:04:23 +00:00
|
|
|
height: 200,
|
2022-05-25 12:21:56 +00:00
|
|
|
child: CpuChart(
|
|
|
|
data: data,
|
|
|
|
period: state.period,
|
|
|
|
start: state.start,
|
|
|
|
),
|
2021-04-10 03:04:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget getPpsChart(final HetznerMetricsLoaded state) {
|
|
|
|
final ppsIn = state.ppsIn;
|
|
|
|
final ppsOut = state.ppsOut;
|
2021-04-10 03:04:23 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
return SizedBox(
|
2021-04-10 03:04:23 +00:00
|
|
|
height: 200,
|
|
|
|
child: NetworkChart(
|
2022-05-25 12:21:56 +00:00
|
|
|
listData: [ppsIn, ppsOut],
|
|
|
|
period: state.period,
|
|
|
|
start: state.start,
|
2021-04-10 03:04:23 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget getBandwidthChart(final HetznerMetricsLoaded state) {
|
|
|
|
final ppsIn = state.bandwidthIn;
|
|
|
|
final ppsOut = state.bandwidthOut;
|
2021-04-10 03:04:23 +00:00
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
return SizedBox(
|
2021-04-10 03:04:23 +00:00
|
|
|
height: 200,
|
|
|
|
child: NetworkChart(
|
2022-05-25 12:21:56 +00:00
|
|
|
listData: [ppsIn, ppsOut],
|
|
|
|
period: state.period,
|
|
|
|
start: state.start,
|
2021-04-10 03:04:23 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Legend extends StatelessWidget {
|
|
|
|
const Legend({
|
|
|
|
required this.color,
|
|
|
|
required this.text,
|
2022-06-05 22:40:34 +00:00
|
|
|
final super.key,
|
|
|
|
});
|
2021-04-10 03:04:23 +00:00
|
|
|
|
|
|
|
final String text;
|
|
|
|
final Color color;
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
_ColoredBox(color: color),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
BrandText.small(text),
|
|
|
|
],
|
|
|
|
);
|
2021-04-10 03:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _ColoredBox extends StatelessWidget {
|
|
|
|
const _ColoredBox({
|
|
|
|
required this.color,
|
2022-06-05 22:40:34 +00:00
|
|
|
});
|
2021-04-10 03:04:23 +00:00
|
|
|
|
|
|
|
final Color color;
|
|
|
|
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) => Container(
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
decoration: BoxDecoration(
|
2021-04-10 03:04:23 +00:00
|
|
|
color: color.withOpacity(0.3),
|
|
|
|
border: Border.all(
|
|
|
|
color: color,
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-04-10 03:04:23 +00:00
|
|
|
}
|