Compare commits
12 Commits
ef192daa93
...
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| c7ddb1a8b0 | |||
|
|
b46e9079d5 | ||
|
|
dc20070bf8 | ||
| 45c9fc814a | |||
|
|
78163441dd | ||
| 407dc13ac4 | |||
|
|
9762be1244 | ||
| 0c06bf16c2 | |||
|
|
971cad7365 | ||
| 1db39e77d3 | |||
|
|
b5e9da0e9b | ||
|
|
34e1ac6264 |
333
.gitea/workflows/ci.yml
Normal file
333
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,333 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
build-deploy:
|
||||
runs-on: act_runner_java
|
||||
if: ${{ github.event.pull_request.merged == true }}
|
||||
outputs:
|
||||
deployment_status: ${{ steps.set_status.outputs.status }}
|
||||
env:
|
||||
JAVA_HOME: /usr/lib/jvm/java-21-openjdk
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up environment
|
||||
run: |
|
||||
echo "PR #${{ github.event.number }} merged into master"
|
||||
echo "Source branch: ${{ github.event.pull_request.head.ref }}"
|
||||
echo "Target branch: ${{ github.event.pull_request.base.ref }}"
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
echo "Running test suite..."
|
||||
|
||||
- name: Setup Maven settings
|
||||
run: |
|
||||
if [ -z "${{ vars.TIMI_NEXUS_USERNAME }}" ] || [ -z "${{ vars.TIMI_NEXUS_PASSWORD }}" ]; then
|
||||
echo "Missing vars.TIMI_NEXUS_USERNAME or vars.TIMI_NEXUS_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p ~/.m2
|
||||
cat > ~/.m2/settings.xml <<EOF
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<servers>
|
||||
<server>
|
||||
<id>timi_nexus</id>
|
||||
<username>${{ vars.TIMI_NEXUS_USERNAME }}</username>
|
||||
<password>${{ vars.TIMI_NEXUS_PASSWORD }}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
EOF
|
||||
|
||||
- name: Build project
|
||||
run: |
|
||||
mvn -B -DskipTests clean package -P prod-linux
|
||||
|
||||
- name: Deploy service
|
||||
if: success()
|
||||
env:
|
||||
CONTAINER_NAME: ${{ vars.CONTAINER_NAME }}
|
||||
CONTAINER_TARGET_PATH: ${{ vars.CONTAINER_TARGET_PATH }}
|
||||
MAX_RETRIES: 3
|
||||
RETRY_DELAY: 10
|
||||
run: |
|
||||
if [ -z "$CONTAINER_NAME" ] || [ -z "$CONTAINER_TARGET_PATH" ]; then
|
||||
echo "Missing production environment variables"
|
||||
echo "Required: CONTAINER_NAME, CONTAINER_TARGET_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
retry_command() {
|
||||
local cmd="$1"
|
||||
local desc="$2"
|
||||
local attempt=1
|
||||
|
||||
while [ $attempt -le $MAX_RETRIES ]; do
|
||||
echo "[$desc] Attempt $attempt/$MAX_RETRIES..."
|
||||
if eval "$cmd"; then
|
||||
echo "OK: $desc succeeded"
|
||||
return 0
|
||||
fi
|
||||
echo "FAIL: $desc failed (attempt $attempt/$MAX_RETRIES)"
|
||||
if [ $attempt -lt $MAX_RETRIES ]; then
|
||||
echo "Retrying in ${RETRY_DELAY}s..."
|
||||
sleep $RETRY_DELAY
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
echo "FAIL: $desc failed after $MAX_RETRIES attempts"
|
||||
return 1
|
||||
}
|
||||
|
||||
version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
|
||||
artifact_id=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.artifactId)
|
||||
jar_file="target/${artifact_id}-${version}.jar"
|
||||
|
||||
if [ ! -f "$jar_file" ]; then
|
||||
echo "Build artifact not found: $jar_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "docker command not found in runner environment"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker inspect "$CONTAINER_NAME" >/dev/null 2>&1; then
|
||||
echo "Docker container not found: $CONTAINER_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
target_jar="${artifact_id}.jar"
|
||||
container_target="${CONTAINER_TARGET_PATH%/}/$target_jar"
|
||||
echo "Deploying $jar_file to container $CONTAINER_NAME:$container_target"
|
||||
|
||||
if ! retry_command "docker cp \"$jar_file\" \"$CONTAINER_NAME:$container_target\"" "Docker copy"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Restarting Docker container: $CONTAINER_NAME"
|
||||
if ! retry_command "docker restart \"$CONTAINER_NAME\"" "Docker restart"; then
|
||||
exit 1
|
||||
fi
|
||||
echo "Deployment completed successfully"
|
||||
|
||||
- name: Create release
|
||||
if: ${{ success() && startsWith(github.event.pull_request.title, 'v') }}
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.RUNNER_TOKEN }}
|
||||
GITEA_SERVER_URL: ${{ github.server_url }}
|
||||
GITEA_INTERNAL_URL: ${{ vars.TIMI_GITEA_INTERNAL_URL }}
|
||||
GITEA_REPOSITORY: ${{ github.repository }}
|
||||
RELEASE_TAG: ${{ github.event.pull_request.title }}
|
||||
RELEASE_TARGET: ${{ github.sha }}
|
||||
MAX_RETRIES: 3
|
||||
RETRY_DELAY: 10
|
||||
run: |
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
echo "Missing secrets.RUNNER_TOKEN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$GITEA_INTERNAL_URL" ]; then
|
||||
api_base_url="$GITEA_INTERNAL_URL"
|
||||
echo "Using internal Gitea URL: $api_base_url"
|
||||
else
|
||||
api_base_url="$GITEA_SERVER_URL"
|
||||
echo "Using public Gitea URL: $api_base_url"
|
||||
fi
|
||||
|
||||
version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
|
||||
artifact_id=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.artifactId)
|
||||
jar_file="target/${artifact_id}-${version}.jar"
|
||||
|
||||
if [ ! -f "$jar_file" ]; then
|
||||
echo "Build artifact not found: $jar_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file_size=$(stat -c%s "$jar_file" 2>/dev/null || stat -f%z "$jar_file" 2>/dev/null || echo "unknown")
|
||||
echo "Found fat jar: $jar_file (size: $file_size bytes)"
|
||||
|
||||
api_url="$api_base_url/api/v1/repos/$GITEA_REPOSITORY/releases"
|
||||
payload=$(cat <<EOF
|
||||
{
|
||||
"tag_name": "$RELEASE_TAG",
|
||||
"name": "$RELEASE_TAG",
|
||||
"target_commitish": "$RELEASE_TARGET",
|
||||
"draft": false,
|
||||
"prerelease": false
|
||||
}
|
||||
EOF
|
||||
)
|
||||
echo "Creating release with tag: $RELEASE_TAG"
|
||||
echo "API URL: $api_url"
|
||||
echo "Target commit: $RELEASE_TARGET"
|
||||
|
||||
release_response_file=$(mktemp /tmp/release_response_XXXXXX.json)
|
||||
trap "rm -f $release_response_file" EXIT
|
||||
|
||||
release_id=""
|
||||
attempt=1
|
||||
while [ $attempt -le $MAX_RETRIES ] && [ -z "$release_id" ]; do
|
||||
echo "[Create release] Attempt $attempt/$MAX_RETRIES..."
|
||||
|
||||
> "$release_response_file"
|
||||
|
||||
http_code=$(curl -sS -w "%{http_code}" -o "$release_response_file" -X POST "$api_url" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
--connect-timeout 30 \
|
||||
--max-time 60 \
|
||||
-d "$payload" 2>/dev/null) || http_code="000"
|
||||
|
||||
response=$(cat "$release_response_file" 2>/dev/null || echo "{}")
|
||||
echo "HTTP Status: $http_code"
|
||||
|
||||
if [ "$http_code" = "201" ]; then
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
release_id=$(echo "$response" | jq -r '.id' 2>/dev/null)
|
||||
else
|
||||
release_id=$(echo "$response" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 | tr -d '\n\r')
|
||||
fi
|
||||
echo "OK: Release created: id=$release_id"
|
||||
elif [ "$http_code" = "409" ]; then
|
||||
echo "Release already exists (HTTP 409), fetching existing release..."
|
||||
existing=$(curl -sS "$api_url" -H "Authorization: token $GITEA_TOKEN" --connect-timeout 30 2>/dev/null || echo "[]")
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
release_id=$(echo "$existing" | jq -r ".[] | select(.tag_name==\"$RELEASE_TAG\") | .id" 2>/dev/null | head -1)
|
||||
else
|
||||
release_id=$(echo "$existing" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 | tr -d '\n\r')
|
||||
fi
|
||||
if [ -n "$release_id" ]; then
|
||||
echo "OK: Found existing release: id=$release_id"
|
||||
else
|
||||
echo "FAIL: Could not find existing release id"
|
||||
fi
|
||||
else
|
||||
echo "FAIL: Create release failed (HTTP $http_code)"
|
||||
if [ $attempt -lt $MAX_RETRIES ]; then
|
||||
echo "Retrying in ${RETRY_DELAY}s..."
|
||||
sleep $RETRY_DELAY
|
||||
fi
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
if [ -z "$release_id" ]; then
|
||||
echo "FAIL: Failed to create or find release after $MAX_RETRIES attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
asset_name=$(basename "$jar_file")
|
||||
echo "Uploading asset: $asset_name (size: $file_size bytes)"
|
||||
upload_url="$api_url/$release_id/assets?name=$asset_name"
|
||||
echo "Upload URL: $upload_url"
|
||||
|
||||
asset_response_file=$(mktemp /tmp/asset_response_XXXXXX.json)
|
||||
trap "rm -f $release_response_file $asset_response_file" EXIT
|
||||
|
||||
upload_success=false
|
||||
attempt=1
|
||||
while [ $attempt -le $MAX_RETRIES ] && [ "$upload_success" = "false" ]; do
|
||||
echo "[Upload asset] Attempt $attempt/$MAX_RETRIES..."
|
||||
|
||||
> "$asset_response_file"
|
||||
|
||||
http_code=$(curl -sS -w "%{http_code}" -o "$asset_response_file" -X POST "$upload_url" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
--connect-timeout 30 \
|
||||
--max-time 300 \
|
||||
-F "attachment=@$jar_file" 2>/dev/null) || http_code="000"
|
||||
|
||||
if [ "$http_code" = "201" ]; then
|
||||
upload_success=true
|
||||
echo "OK: Successfully uploaded: $asset_name"
|
||||
else
|
||||
echo "FAIL: Upload failed (HTTP $http_code)"
|
||||
cat "$asset_response_file" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
if [ "$upload_success" = "false" ] && [ $attempt -lt $MAX_RETRIES ]; then
|
||||
echo "Retrying in ${RETRY_DELAY}s..."
|
||||
sleep $RETRY_DELAY
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
|
||||
if [ "$upload_success" = "false" ]; then
|
||||
echo "FAIL: Failed to upload asset after $MAX_RETRIES attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Mark deployment success
|
||||
id: set_status
|
||||
if: always()
|
||||
run: |
|
||||
echo "status=success" >> $GITHUB_OUTPUT
|
||||
|
||||
notify-on-failure:
|
||||
runs-on: act_runner_java
|
||||
needs: build-deploy
|
||||
if: ${{ always() && github.event.pull_request.merged == true && needs.build-deploy.result == 'failure' }}
|
||||
steps:
|
||||
- name: Notify CI failure
|
||||
env:
|
||||
PR_NUMBER: ${{ github.event.number }}
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
PR_URL: ${{ github.event.pull_request.html_url }}
|
||||
SOURCE_BRANCH: ${{ github.event.pull_request.head.ref }}
|
||||
AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||
COMMIT_SHA: ${{ github.sha }}
|
||||
REPO: ${{ github.repository }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
WEBHOOK_URL: ${{ vars.NOTIFY_WEBHOOK_URL }}
|
||||
run: |
|
||||
echo "========================================="
|
||||
echo "CI Pipeline Failed - Manual Review Required"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "PR: #$PR_NUMBER - $PR_TITLE"
|
||||
echo "Branch: $SOURCE_BRANCH"
|
||||
echo "Author: $AUTHOR"
|
||||
echo "Commit: $COMMIT_SHA"
|
||||
echo ""
|
||||
echo "Actions:"
|
||||
echo " 1. Re-run CI: $SERVER_URL/$REPO/actions"
|
||||
echo " 2. Revert PR: $PR_URL (click 'Revert' button)"
|
||||
echo ""
|
||||
echo "========================================="
|
||||
|
||||
if [ -n "$WEBHOOK_URL" ]; then
|
||||
message="CI 部署失败\n\nPR: #$PR_NUMBER - $PR_TITLE\n分支: $SOURCE_BRANCH\n提交者: $AUTHOR\n\n请检查并决定:\n- 重试 CI\n- 回滚合并"
|
||||
|
||||
payload=$(cat <<EOF
|
||||
{
|
||||
"msgtype": "text",
|
||||
"text": {
|
||||
"content": "$message"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
curl -sS -X POST "$WEBHOOK_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload" || echo "Warning: Failed to send notification"
|
||||
|
||||
echo "OK: Notification sent"
|
||||
else
|
||||
echo "Note: Set vars.NOTIFY_WEBHOOK_URL to enable webhook notifications"
|
||||
fi
|
||||
29
pom.xml
29
pom.xml
@@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||
<artifactId>TimiServerAPI</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>TimiServerAPI</name>
|
||||
<description>imyeyu.com API</description>
|
||||
@@ -23,13 +23,6 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>apache-maven</id>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>dev-windows</id>
|
||||
@@ -112,17 +105,33 @@
|
||||
<configuration>
|
||||
<excludeDevtools>true</excludeDevtools>
|
||||
<mainClass>com.imyeyu.api.TimiServerAPI</mainClass>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>apache-maven</id>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>timi_nexus</id>
|
||||
<url>https://nexus.imyeyu.com/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.spring</groupId>
|
||||
<artifactId>timi-spring</artifactId>
|
||||
<version>0.0.9</version>
|
||||
<version>0.0.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.network</groupId>
|
||||
|
||||
@@ -348,10 +348,10 @@ public class ServerStatus implements TimiJava {
|
||||
private String mountPoint;
|
||||
|
||||
/** 分区总空间 */
|
||||
private long totalBytes;
|
||||
private long total;
|
||||
|
||||
/** 分区已用空间 */
|
||||
private Long usedBytes;
|
||||
private Long used;
|
||||
|
||||
/** 磁盘传输耗时 */
|
||||
private long transferTimeMs;
|
||||
|
||||
@@ -26,17 +26,17 @@ public class DockerController {
|
||||
|
||||
private final DockerService dockerService;
|
||||
|
||||
@GetMapping("/containers")
|
||||
@GetMapping("/container")
|
||||
public List<DockerContainerSummaryView> listContainers() {
|
||||
return dockerService.listContainers();
|
||||
}
|
||||
|
||||
@GetMapping("/containers/{containerId}/status")
|
||||
@GetMapping("/container/{containerId}/status")
|
||||
public DockerContainerStatusView getContainerStatus(@PathVariable String containerId) {
|
||||
return dockerService.getContainerStatus(containerId);
|
||||
}
|
||||
|
||||
@GetMapping("/containers/{containerId}/history")
|
||||
@GetMapping("/container/{containerId}/history")
|
||||
public DockerContainerHistoryView getContainerHistory(@PathVariable String containerId, @RequestParam(required = false) String window) {
|
||||
return dockerService.getContainerHistory(containerId, window);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ public class StatusServiceImplement implements StatusService {
|
||||
SystemStatusDataView.OS os = new SystemStatusDataView.OS();
|
||||
os.setName(serverStatus.getOs().getName());
|
||||
os.setBootAt(serverStatus.getOs().getBootAt());
|
||||
os.setUptimeMs(Math.max(0, serverTime - serverStatus.getOs().getBootAt()));
|
||||
snapshot.setOs(os);
|
||||
}
|
||||
if (selectedMetrics.contains(Metric.CPU)) {
|
||||
@@ -80,8 +79,8 @@ public class StatusServiceImplement implements StatusService {
|
||||
cpu.setModel(serverStatus.getCpu().getName());
|
||||
cpu.setPhysicalCores(serverStatus.getCpu().getCoreCount());
|
||||
cpu.setLogicalCores(serverStatus.getCpu().getLogicalCount());
|
||||
cpu.setUsagePercent(lastDouble(serverStatus.getCpu().getUsed()));
|
||||
cpu.setSystemPercent(lastDouble(serverStatus.getCpu().getSystem()));
|
||||
cpu.setUsageTotal(lastDouble(serverStatus.getCpu().getUsed()));
|
||||
cpu.setUsageSystem(lastDouble(serverStatus.getCpu().getSystem()));
|
||||
cpu.setTemperatureCelsius(serverStatus.getCpu().getTemperature());
|
||||
snapshot.setCpu(cpu);
|
||||
}
|
||||
@@ -91,7 +90,6 @@ public class StatusServiceImplement implements StatusService {
|
||||
Long swapUsedBytes = lastLong(serverStatus.getMemory().getSwapUsed());
|
||||
memory.setTotalBytes(serverStatus.getMemory().getSize());
|
||||
memory.setUsedBytes(usedBytes);
|
||||
memory.setUsagePercent(toPercent(usedBytes, serverStatus.getMemory().getSize()));
|
||||
memory.setSwapTotalBytes(serverStatus.getMemory().getSwapSize());
|
||||
memory.setSwapUsedBytes(swapUsedBytes);
|
||||
snapshot.setMemory(memory);
|
||||
@@ -160,9 +158,9 @@ public class StatusServiceImplement implements StatusService {
|
||||
item.setPartitionType(partition.getPartitionType());
|
||||
item.setUuid(partition.getUuid());
|
||||
item.setMountPoint(partition.getMountPoint());
|
||||
item.setTotalBytes(partition.getTotalBytes());
|
||||
item.setUsedBytes(partition.getUsedBytes());
|
||||
item.setUsagePercent(toPercent(partition.getUsedBytes(), partition.getTotalBytes()));
|
||||
item.setTotal(partition.getTotal());
|
||||
item.setUsed(partition.getUsed());
|
||||
item.setUsagePercent(toPercent(partition.getUsed(), partition.getTotal()));
|
||||
item.setTransferTimeMs(partition.getTransferTimeMs());
|
||||
storagePartitions.add(item);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class UpsServiceImplement implements UpsService {
|
||||
private final UpsStatusTask upsStatusTask;
|
||||
private final UpsStatusStore upsStatusStore;
|
||||
|
||||
@Value("${ups.collect-rate-ms:60000}")
|
||||
@Value("${ups.collect-rate-ms:3000}")
|
||||
private long collectRateMs;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,7 @@ public class UpsStatusTask implements SchedulingConfigurer {
|
||||
private final UpsStatusClient upsStatusClient;
|
||||
private final UpsStatusStore upsStatusStore;
|
||||
|
||||
@Value("${ups.collect-enabled:false}")
|
||||
@Value("${ups.collect-enabled:true}")
|
||||
private boolean collectEnabled;
|
||||
|
||||
@Value("${ups.collect-rate-ms:60000}")
|
||||
|
||||
@@ -38,10 +38,10 @@ public class CpuStatusCollector extends AbstractDequeStatusCollector {
|
||||
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - lastCpuTicks[CentralProcessor.TickType.IRQ.getIndex()];
|
||||
long softIrq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - lastCpuTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
|
||||
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - lastCpuTicks[CentralProcessor.TickType.STEAL.getIndex()];
|
||||
long total = user + nice + sys + idle + ioWait + irq + softIrq + steal;
|
||||
double total = user + nice + sys + idle + ioWait + irq + softIrq + steal;
|
||||
if (0 < total) {
|
||||
putDeque(context, context.getStatus().getCpu().getSystem(), 100D * sys / total);
|
||||
putDeque(context, context.getStatus().getCpu().getUsed(), 100 - 100D * idle / total);
|
||||
putDeque(context, context.getStatus().getCpu().getSystem(), sys / total);
|
||||
putDeque(context, context.getStatus().getCpu().getUsed(), 1 - idle / total);
|
||||
}
|
||||
}
|
||||
lastCpuTicks = ticks;
|
||||
|
||||
@@ -38,13 +38,13 @@ public class StorageStatusCollector implements StatusCollector {
|
||||
item.setPartitionType(partition.getType());
|
||||
item.setUuid(partition.getUuid());
|
||||
item.setMountPoint(partition.getMountPoint());
|
||||
item.setTotalBytes(partition.getSize());
|
||||
item.setTotal(partition.getSize());
|
||||
item.setTransferTimeMs(diskStore.getTransferTime());
|
||||
|
||||
OSFileStore fileStore = matchFileStore(partition, fileStoreMap);
|
||||
if (fileStore != null) {
|
||||
fileStore.updateAttributes();
|
||||
item.setUsedBytes(fileStore.getTotalSpace() - fileStore.getUsableSpace());
|
||||
item.setUsed(fileStore.getTotalSpace() - fileStore.getUsableSpace());
|
||||
}
|
||||
context.getStatus().getStoragePartitions().add(item);
|
||||
}
|
||||
|
||||
@@ -101,9 +101,6 @@ public class SystemStatusDataView {
|
||||
|
||||
/** 启动时间 */
|
||||
private long bootAt;
|
||||
|
||||
/** 运行时长 */
|
||||
private long uptimeMs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,10 +122,10 @@ public class SystemStatusDataView {
|
||||
private int logicalCores;
|
||||
|
||||
/** 总占用 */
|
||||
private Double usagePercent;
|
||||
private Double usageTotal;
|
||||
|
||||
/** 系统占用 */
|
||||
private Double systemPercent;
|
||||
private Double usageSystem;
|
||||
|
||||
/** 温度 */
|
||||
private double temperatureCelsius;
|
||||
@@ -149,9 +146,6 @@ public class SystemStatusDataView {
|
||||
/** 已用内存 */
|
||||
private Long usedBytes;
|
||||
|
||||
/** 使用率 */
|
||||
private Double usagePercent;
|
||||
|
||||
/** 交换分区总量 */
|
||||
private long swapTotalBytes;
|
||||
|
||||
@@ -364,10 +358,10 @@ public class SystemStatusDataView {
|
||||
private String mountPoint;
|
||||
|
||||
/** 分区总空间 */
|
||||
private long totalBytes;
|
||||
private long total;
|
||||
|
||||
/** 已用空间 */
|
||||
private Long usedBytes;
|
||||
private Long used;
|
||||
|
||||
/** 使用率 */
|
||||
private Double usagePercent;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.imyeyu.api.TimiServerAPI;
|
||||
import com.imyeyu.api.modules.blog.entity.Article;
|
||||
import com.imyeyu.api.modules.blog.mapper.ArticleMapper;
|
||||
@@ -118,6 +117,5 @@ public class SpringTest {
|
||||
for (int i = 0; i < icon.size(); i++) {
|
||||
map.put(icon.get(i).getName(), icon.get(i).getSvg());
|
||||
}
|
||||
System.out.println(new Gson().toJson(map));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user