Unverified Commit e16ed024 authored by Licho's avatar Licho Committed by GitHub

Remove paimon and jvm monitor (#3618)

Signed-off-by: 's avatarlicho <lecho.sun@gmail.com> Signed-off-by: 's avatarsunlichao11 <sunlichao11@jd.com> Co-authored-by: 's avatarsunlichao11 <sunlichao11@jd.com>
parent ed895809
......@@ -12,6 +12,9 @@ logs.zip
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# sqlite
dinky.db
# Package Files #
*.jar
*.war
......
......@@ -329,17 +329,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.github.datalinkdc</groupId>
<artifactId>dinky-shaded-paimon</artifactId>
<version>1.0.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
......
......@@ -24,7 +24,6 @@ import static org.dinky.data.constant.MonitorTableConstant.JOB_ID;
import org.dinky.data.constant.MonitorTableConstant;
import org.dinky.data.enums.SseTopic;
import org.dinky.data.vo.MetricsVO;
import org.dinky.utils.PaimonUtil;
import org.dinky.utils.SqliteUtil;
import java.sql.SQLException;
......@@ -90,20 +89,6 @@ public class MetricsContextHolder {
return; // Return early to avoid unnecessary operations
}
pool.execute(() -> {
metricsVOS.add(o);
long current = System.currentTimeMillis();
long duration = current - lastDumpTime.get();
// Temporary cache monitoring information, mainly to prevent excessive buffering of write IO,
// when metricsVOS data reaches 1000 or the time exceeds 15 seconds
if (metricsVOS.size() >= 1000 || duration >= 15000) {
List<MetricsVO> snapshot;
synchronized (this) { // Enter synchronized block only when necessary
snapshot = new ArrayList<>(metricsVOS);
metricsVOS.clear();
lastDumpTime.set(current);
}
PaimonUtil.write(MonitorTableConstant.DINKY_METRICS, snapshot, MetricsVO.class);
}
String topic = StrFormatter.format("{}/{}", SseTopic.METRICS.getValue(), key);
SseSessionContextHolder.sendTopic(topic, o); // Ensure only successfully added metrics are sent
});
......
......@@ -24,8 +24,6 @@ import org.dinky.daemon.task.DaemonTaskConfig;
import org.dinky.data.annotations.GaugeM;
import org.dinky.data.metrics.BaseMetrics;
import org.dinky.data.metrics.MetricsTotal;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.job.handler.SystemMetricsHandler;
import java.lang.reflect.Field;
import java.util.Arrays;
......@@ -63,9 +61,6 @@ public class SystemMetricsTask implements DaemonTask {
@Override
public boolean dealTask() {
if (SystemConfiguration.getInstances().getMetricsSysEnable().getValue()) {
SystemMetricsHandler.refresh();
}
return false;
}
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.utils;
import org.dinky.shaded.paimon.types.DataType;
import org.dinky.shaded.paimon.types.DataTypes;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import cn.hutool.core.map.MapUtil;
public class PaimonTypeUtil {
private static final Map<Class<?>, DataType> TYPE_MAP = MapUtil.<Class<?>, DataType>builder(
String.class, DataTypes.STRING())
.put(Integer.class, DataTypes.INT())
.put(Long.class, DataTypes.BIGINT())
.put(Double.class, DataTypes.DOUBLE())
.put(Float.class, DataTypes.FLOAT())
.put(Boolean.class, DataTypes.BOOLEAN())
.put(Byte.class, DataTypes.TINYINT())
.put(Short.class, DataTypes.SMALLINT())
.put(BigDecimal.class, DataTypes.DECIMAL(30, 4))
.put(Date.class, DataTypes.TIMESTAMP(3))
.put(LocalDateTime.class, DataTypes.TIMESTAMP(3))
.build();
public static DataType classToDataType(Class<?> clazz) {
return TYPE_MAP.getOrDefault(clazz, DataTypes.STRING());
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.utils;
import static org.dinky.data.constant.MonitorTableConstant.DINKY_DB;
import org.dinky.data.annotations.paimon.Option;
import org.dinky.data.annotations.paimon.Options;
import org.dinky.data.annotations.paimon.PartitionKey;
import org.dinky.data.annotations.paimon.PrimaryKey;
import org.dinky.function.constant.PathConstant;
import org.dinky.shaded.paimon.catalog.Catalog;
import org.dinky.shaded.paimon.catalog.CatalogContext;
import org.dinky.shaded.paimon.catalog.CatalogFactory;
import org.dinky.shaded.paimon.catalog.Identifier;
import org.dinky.shaded.paimon.data.BinaryRow;
import org.dinky.shaded.paimon.data.BinaryRowWriter;
import org.dinky.shaded.paimon.data.BinaryString;
import org.dinky.shaded.paimon.data.BinaryWriter;
import org.dinky.shaded.paimon.data.InternalRow;
import org.dinky.shaded.paimon.data.Timestamp;
import org.dinky.shaded.paimon.fs.Path;
import org.dinky.shaded.paimon.predicate.Predicate;
import org.dinky.shaded.paimon.predicate.PredicateBuilder;
import org.dinky.shaded.paimon.reader.RecordReader;
import org.dinky.shaded.paimon.schema.Schema;
import org.dinky.shaded.paimon.table.Table;
import org.dinky.shaded.paimon.table.sink.BatchTableCommit;
import org.dinky.shaded.paimon.table.sink.BatchTableWrite;
import org.dinky.shaded.paimon.table.sink.BatchWriteBuilder;
import org.dinky.shaded.paimon.table.sink.CommitMessage;
import org.dinky.shaded.paimon.table.source.ReadBuilder;
import org.dinky.shaded.paimon.table.source.Split;
import org.dinky.shaded.paimon.table.source.TableRead;
import org.dinky.shaded.paimon.types.DataField;
import org.dinky.shaded.paimon.types.DataType;
import org.dinky.shaded.paimon.types.DataTypeRoot;
import java.io.IOException;
import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.ModifierUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Data
public class PaimonUtil {
private static PaimonUtil instance = new PaimonUtil();
private final Cache<Class<?>, Schema> schemaCache;
private final CatalogContext context;
private final Catalog catalog;
public PaimonUtil() {
schemaCache = CacheUtil.newLRUCache(100);
context = CatalogContext.create(new Path(URLUtil.toURI(URLUtil.url(PathConstant.TMP_PATH + "paimon"))));
catalog = CatalogFactory.createCatalog(context);
try {
catalog.createDatabase(DINKY_DB, true);
} catch (Catalog.DatabaseAlreadyExistException e) {
throw new RuntimeException(e);
}
}
public static <T> void write(String table, List<T> dataList, Class<?> clazz) {
if (CollUtil.isEmpty(dataList)) {
return;
}
Table paimonTable = createOrGetTable(table, clazz);
BatchWriteBuilder writeBuilder = paimonTable.newBatchWriteBuilder();
// 2. Write records in distributed tasks
try (BatchTableWrite write = writeBuilder.newWrite()) {
Schema schema = getSchemaByClass(clazz);
List<DataField> fields = schema.fields();
for (T t : dataList) {
BinaryRow row = new BinaryRow(fields.size());
BinaryRowWriter writer = new BinaryRowWriter(row);
for (int i = 0; i < fields.size(); i++) {
DataField dataField = fields.get(i);
DataType type = dataField.type();
String fieldName = StrUtil.toCamelCase(dataField.name());
Object fieldValue = ReflectUtil.getFieldValue(t, fieldName);
try {
// TODO BinaryWriter.write已被废弃,后续可以考虑改成这种方式
// BinaryWriter.createValueSetter(type).setValue(writer, i, fieldValue);
if (type.getTypeRoot() == DataTypeRoot.VARCHAR) {
BinaryWriter.write(
writer, i, BinaryString.fromString(JSONUtil.toJsonStr(fieldValue)), type, null);
} else if (type.getTypeRoot() == DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE) {
Timestamp timestamp = Timestamp.fromLocalDateTime((LocalDateTime) fieldValue);
BinaryWriter.write(writer, i, timestamp, type, null);
} else {
BinaryWriter.write(writer, i, fieldValue, type, null);
}
} catch (Throwable e) {
String err = StrFormatter.format(
"write table: [{}], data filed [{}], value: [{}] error",
paimonTable.name(),
fieldName,
fieldValue);
throw new RuntimeException(err, e);
}
}
write.write(row);
}
List<CommitMessage> messages = write.prepareCommit();
// 3. Collect all CommitMessages to a global node and commit
try (BatchTableCommit commit = writeBuilder.newCommit()) {
commit.commit(messages);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static <T> List<T> batchReadTable(
String table, Class<T> clazz, Function<PredicateBuilder, List<Predicate>> filter) {
Identifier identifier = getIdentifier(table);
TimeInterval timer = DateUtil.timer();
List<T> dataList = new ArrayList<>();
PredicateBuilder builder = new PredicateBuilder(getSchemaByClass(clazz).rowType());
ReadBuilder readBuilder;
try {
if (!instance.getCatalog().tableExists(identifier)) {
return dataList;
}
readBuilder = instance.getCatalog().getTable(identifier).newReadBuilder();
if (filter != null) {
List<Predicate> predicates = filter.apply(builder);
readBuilder.withFilter(predicates);
}
} catch (Catalog.TableNotExistException e) {
throw new RuntimeException(e);
}
// 2. Plan splits in 'Coordinator' (or named 'Driver')
List<Split> splits = readBuilder.newScan().plan().splits();
// 3. Distribute these splits to different tasks
// 4. Read a split in task
TableRead read = readBuilder.newRead();
try (RecordReader<InternalRow> reader = read.createReader(splits)) {
Schema schema = getSchemaByClass(clazz);
reader.forEachRemaining(x -> {
T t = ReflectUtil.newInstance(clazz);
schema.fields().forEach(f -> {
Object value =
InternalRow.createFieldGetter(f.type(), f.id()).getFieldOrNull(x);
String fieldName = StrUtil.toCamelCase(f.name());
try {
ReflectUtil.setFieldValue(t, fieldName, value);
} catch (Exception ignored) {
}
});
dataList.add(t);
});
} catch (IOException e) {
throw new RuntimeException(e);
}
log.debug(
"paimon read; table: {} ,size: {} ,timer: {}ms",
identifier.getFullName(),
dataList.size(),
timer.intervalMs());
return dataList;
}
public static Table createOrGetTable(String tableName, Class<?> clazz) {
try {
Identifier identifier = Identifier.create(DINKY_DB, tableName);
if (instance.getCatalog().tableExists(identifier)) {
return instance.getCatalog().getTable(identifier);
}
instance.getCatalog().createTable(identifier, getSchemaByClass(clazz), false);
return instance.getCatalog().getTable(identifier);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Schema getSchemaByClass(Class<?> clazz) {
return instance.getSchemaCache().get(clazz, () -> {
List<String> primaryKeys = new ArrayList<>();
List<String> partitionKeys = new ArrayList<>();
Schema.Builder builder = Schema.newBuilder();
Field[] fields = ReflectUtil.getFields(clazz, field -> !ModifierUtil.isStatic(field));
for (Field field : fields) {
String fieldName = StrUtil.toUnderlineCase(field.getName());
if (field.getAnnotations().length > 0) {
if (AnnotationUtil.hasAnnotation(field, PartitionKey.class)) {
partitionKeys.add(fieldName);
}
if (AnnotationUtil.hasAnnotation(field, PrimaryKey.class)) {
primaryKeys.add(fieldName);
}
}
Class<?> type = field.getType();
DataType dataType = PaimonTypeUtil.classToDataType(type);
builder.column(fieldName, dataType);
}
// get options
Options options = AnnotationUtil.getAnnotation(clazz, Options.class);
if (options != null) {
for (Option option : options.value()) {
builder.option(option.key(), option.value());
}
} else {
// default options
Map<String, String> defaultOptions =
MapUtil.builder("file.format", "parquet").build();
builder.options(defaultOptions);
}
// builder schema;
return builder.partitionKeys(partitionKeys).primaryKey(primaryKeys).build();
});
}
public static Identifier getIdentifier(String tableName) {
return Identifier.create(DINKY_DB, tableName);
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { JVMMetric } from '@/pages/Metrics/Server/data';
import { Area, AreaConfig } from '@ant-design/plots';
import React from 'react';
import { Chart } from '@ant-design/plots/es/interface';
type CpuProps = {
data: JVMMetric[];
chartConfig: Chart;
};
type Cpu = {
time: Date;
value: string | number;
};
const CPU: React.FC<CpuProps> = (props) => {
const { data, chartConfig } = props;
const dataList: Cpu[] = data.map((x) => {
return { time: x.time, value: Number(x.jvm.cpuUsed.toFixed(2)) };
});
const config: AreaConfig = {
...chartConfig,
data: dataList,
axis: {
y: {
min: 0,
max: 100
}
},
tooltip: {
name: 'Cpu Used',
channel: 'y',
valueFormatter: (num: Number) => {
return num + ' %';
}
}
};
return <Area {...config} />;
};
export default CPU;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { JVMMetric } from '@/pages/Metrics/Server/data';
import { Area, AreaConfig } from '@ant-design/plots';
import React from 'react';
import { Chart } from '@ant-design/plots/es/interface';
type HeapProps = {
data: JVMMetric[];
max: number;
chartConfig: Chart;
};
type Heap = {
time: Date;
value: string | number;
};
const Heap: React.FC<HeapProps> = (props) => {
const { data, max, chartConfig } = props;
const dataList: Heap[] = data.map((x) => {
return {
time: x.time,
value: parseInt(String(x.jvm.heapUsed / (1024 * 1024)))
};
});
const config: AreaConfig = {
...chartConfig,
data: dataList,
tooltip: {
name: 'Heap Memory',
channel: 'y',
valueFormat: (datum: Number) => {
return datum + ' MB';
}
}
};
return <Area {...config} />;
};
export default Heap;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { JVMMetric } from '@/pages/Metrics/Server/data';
import { Area, AreaConfig } from '@ant-design/plots';
import React from 'react';
import { Chart } from '@ant-design/plots/es/interface';
type NonHeapProps = {
data: JVMMetric[];
max: number;
chartConfig: Chart;
};
type NonHeap = {
time: Date;
value: number;
};
const NonHeap: React.FC<NonHeapProps> = (props) => {
const { data, max, chartConfig } = props;
const dataList: NonHeap[] = data.map((x) => {
return {
time: x.time,
value: parseInt(String(x.jvm.nonHeapMax / (1024 * 1024)))
};
});
const config: AreaConfig = {
...chartConfig,
data: dataList,
axis: {
y: {
min: 0,
max: max
}
},
tooltip: {
name: 'NonHeap Memory',
channel: 'y',
valueFormat: (datum: Number) => {
return datum + ' MB';
}
}
};
return <Area {...config} />;
};
export default NonHeap;
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { JVMMetric } from '@/pages/Metrics/Server/data';
import { Area, AreaConfig } from '@ant-design/plots';
import React from 'react';
import { Chart } from '@ant-design/plots/es/interface';
type ThreadProps = {
data: JVMMetric[];
chartConfig: Chart;
};
type Thread = {
time: Date;
value: string | number;
name: string;
};
const Thread: React.FC<ThreadProps> = (props) => {
const { data, chartConfig } = props;
const dataList: Thread[] = data.map((x) => {
return { time: x.time, value: x.jvm.threadPeakCount, name: 'Peak' };
});
const dataList2: Thread[] = data.map((x) => {
return { time: x.time, value: x.jvm.threadCount, name: 'Count' };
});
const dataListAll = dataList.concat(dataList2);
const config: AreaConfig = {
...chartConfig,
data: dataListAll,
colorField: 'name',
shapeField: 'name',
stack: false,
tooltip: {}
};
return <Area {...config} />;
};
export default Thread;
......@@ -28,48 +28,3 @@ export type MetricsDataType = {
model: string;
heartTime: Date;
};
export type JVMMetric = {
jvm: JVMType;
cpu: CPUType;
mem: MemoryType;
time: Date;
};
export type FlinkMetricsData = Record<string, Record<string, string>>;
export type JvmDataRecord = {
cpuLastValue: number;
heapMax: number;
heapLastValue: number;
nonHeapMax: number;
nonHeapLastValue: number;
threadPeakCount: number;
threadCount: number;
};
type JVMType = {
total: number;
max: number;
free: number;
cpuUsed: number;
nonHeapMax: number;
nonHeapUsed: number;
heapMax: number;
heapUsed: number;
threadPeakCount: number;
threadCount: number;
version: string;
home: string;
};
type CPUType = {
cpuNum: number;
sys: number;
wait: number;
free: number;
};
type MemoryType = {
total: number;
used: number;
free: number;
};
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { CPUIcon, HeapIcon, OutHeapIcon, ThreadIcon } from '@/components/Icons/MetricsIcon';
import useHookRequest from '@/hooks/useHookRequest';
import { SseData } from '@/models/Sse';
import { SSE_TOPIC } from '@/pages/DevOps/constants';
import { MetricsTimeFilter } from '@/pages/DevOps/JobDetail/data';
import { getMetricsData } from '@/pages/DevOps/JobDetail/srvice';
import CPU from '@/pages/Metrics/Server/CPU';
import { JvmDataRecord, JVMMetric, MetricsDataType } from '@/pages/Metrics/Server/data';
import Heap from '@/pages/Metrics/Server/Heap';
import NonHeap from '@/pages/Metrics/Server/OutHeap';
import Thread from '@/pages/Metrics/Server/Thread';
import { useModel } from '@@/exports';
import { ProCard } from '@ant-design/pro-components';
import { Space } from 'antd';
import React, { useEffect, useState } from 'react';
import { Chart } from '@ant-design/plots/es/interface';
import { LineOptions } from '@ant-design/plots/lib/core';
export const imgStyle = {
display: 'block',
width: 24,
height: 24
};
type ServerProp = {
timeRange: MetricsTimeFilter;
};
const Server: React.FC<ServerProp> = (props) => {
const { timeRange } = props;
const [jvmData, setJvmData] = useState<JVMMetric[]>([]);
const processData = (source: JVMMetric[], datas: MetricsDataType[]) => {
datas.forEach((data) => {
const d: JVMMetric = data.content;
d.time = data.heartTime;
source.push(d);
});
return source;
};
useHookRequest<MetricsDataType[], any>(getMetricsData, {
defaultParams: [timeRange, 'local'],
refreshDeps: [timeRange],
onSuccess: (result: MetricsDataType[]) => {
setJvmData(() => processData([], result));
}
});
const { subscribeTopic } = useModel('Sse', (model: any) => ({
subscribeTopic: model.subscribeTopic
}));
useEffect(() => {
if (timeRange.isReal) {
return subscribeTopic([`${SSE_TOPIC.METRICS}/local`], (data: SseData) =>
setJvmData((prevState) => [...processData(prevState, [data.data])])
);
}
}, [timeRange]);
const commonConfig: LineOptions = {
data: [],
autoFit: true,
animation: {
update: {
type: false
}
},
yField: 'value',
xField: (d) => new Date(d.time)
};
const jvmMetric = jvmData[jvmData.length - 1];
const showLastData: JvmDataRecord = jvmMetric
? {
cpuLastValue: Number(jvmMetric.jvm.cpuUsed.toFixed(2)),
heapMax: Number((jvmMetric.jvm.heapMax / (1024 * 1024)).toFixed(0)),
heapLastValue: Number((jvmMetric.jvm.heapUsed / (1024 * 1024)).toFixed(0)),
nonHeapMax: Number((jvmMetric.jvm.nonHeapMax / (1024 * 1024)).toFixed(0)),
nonHeapLastValue: Number((jvmMetric.jvm.nonHeapUsed / (1024 * 1024)).toFixed(0)),
threadPeakCount: jvmMetric.jvm.threadPeakCount,
threadCount: jvmMetric.jvm.threadCount
}
: {
cpuLastValue: 0,
heapMax: 0,
heapLastValue: 0,
nonHeapMax: 0,
nonHeapLastValue: 0,
threadPeakCount: 0,
threadCount: 0
};
const extraDataBuilder = (data: JvmDataRecord) => {
return {
cpuLastValue: data.cpuLastValue + '%',
heapLastValue: data.heapLastValue + ' / ' + data.heapMax + ' MB',
nonHeapLastValue: data.nonHeapLastValue + ' / ' + data.nonHeapMax + ' MB',
threadCount: data.threadCount + ' / ' + data.threadPeakCount
};
};
return (
<>
<ProCard bordered split={'vertical'}>
<ProCard
title={
<Space>
<CPUIcon style={imgStyle} />
CPU
</Space>
}
extra={extraDataBuilder(showLastData).cpuLastValue}
bodyStyle={{ paddingBlock: 0, height: 200 }}
colSpan={'25%'}
>
<CPU data={jvmData} chartConfig={commonConfig} />
</ProCard>
<ProCard
title={
<Space>
<HeapIcon style={imgStyle} />
Heap
</Space>
}
extra={extraDataBuilder(showLastData).heapLastValue}
bodyStyle={{ paddingBlock: 0, height: 200 }}
colSpan={'25%'}
>
<Heap data={jvmData} max={showLastData.heapMax} chartConfig={commonConfig} />
</ProCard>
<ProCard
title={
<Space>
<ThreadIcon style={imgStyle} />
Thread
</Space>
}
extra={extraDataBuilder(showLastData).threadCount}
bodyStyle={{ paddingBlock: 0, height: 200 }}
colSpan={'25%'}
>
<Thread data={jvmData} chartConfig={commonConfig} />
</ProCard>
<ProCard
title={
<Space>
<OutHeapIcon style={imgStyle} />
Out Heap
</Space>
}
extra={extraDataBuilder(showLastData).nonHeapLastValue}
bodyStyle={{ paddingBlock: 0, height: 200 }}
colSpan={'25%'}
>
<NonHeap data={jvmData} max={showLastData.nonHeapMax} chartConfig={commonConfig} />
</ProCard>
</ProCard>
</>
);
};
export default Server;
......@@ -65,11 +65,6 @@ export default () => {
header={{ extra: [<MetricsFilter key={''} onTimeSelect={onTimeSelectChange} />] }}
content={
<>
{showServer.data && (
<ProCard collapsible title={'Dinky Server'} ghost bordered hoverable>
<Server timeRange={timeRange} />
</ProCard>
)}
{/*<Job />*/}
<JobMetricsList timeRange={timeRange} />
</>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment