monitor.vue 18.1 KB
Newer Older
wanli's avatar
wanli committed
1 2
<template>
  <div class="app-container">
wanli's avatar
wanli committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    <div style="margin-top: 10px">
      <grid-layout
        :layout.sync="layout"
        :col-num="12"
        :row-height="30"
        :is-draggable="draggable"
        :is-resizable="resizable"
        :vertical-compact="true"
        :use-css-transforms="true"
        @layout-created="layoutCreatedEvent"
        @layout-before-mount="layoutBeforeMountEvent"
        @layout-mounted="layoutMountedEvent"
        @layout-ready="layoutReadyEvent"
        @layout-updated="layoutUpdatedEvent"
wanli's avatar
wanli committed
17
      >
wanli's avatar
wanli committed
18 19 20 21 22 23 24 25 26 27 28
        <grid-item
          :x="0"
          :y="0"
          :w="6"
          :h="5"
          i="1"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
29
        >
wanli's avatar
wanli committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
          <p class="item-title">DEVICE</p>
          <div style="padding: 15px">
            <el-select
              size="mini"
              v-model="device"
              @change="onSelectChange"
              placeholder="请选择设备"
            >
              <el-option
                v-for="(item, index) in deviceList"
                :key="index"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </div>
        </grid-item>
        <grid-item
          :x="6"
          :y="0"
          :w="6"
          :h="5"
          i="2"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
58
        >
wanli's avatar
wanli committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
          <p class="item-title">SYSTEM</p>
          <el-table
            element-loading-text="Loading"
            :data="system"
            size="mini"
            border
            stripe
            fit
            highlight-current-row
          >
            <el-table-column
              prop="host"
              label="host"
              min-width="150"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="path"
              label="path"
              min-width="150"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              prop="timestamp"
              label="timestamp"
              min-width="150"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column label="imei" min-width="150" show-overflow-tooltip>
              <template slot-scope="scope">{{ scope.row.imei }}</template>
            </el-table-column>
            <el-table-column
              label="free_size"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.free_size }}(KB)</template
              >
            </el-table-column>
          </el-table>
        </grid-item>
        <grid-item
          :x="0"
          :y="5"
          :w="6"
          :h="5"
          i="3"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
112
        >
wanli's avatar
wanli committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
          <p class="item-title">EVM</p>
          <el-table
            element-loading-text="Loading"
            :data="evmList"
            size="mini"
            border
            stripe
            fit
            highlight-current-row
          >
            <el-table-column
              label="heap_map_size"
              min-width="150"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.heap_map_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column
              label="heap_total_size"
              min-width="150"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.heap_total_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column
              label="heap_used_size"
              min-width="150"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.heap_used_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column
              label="stack_total_size"
              min-width="150"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.stack_total_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column
              label="stack_used_size"
              min-width="150"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.stack_used_size }}(KB)</template
              >
            </el-table-column>
          </el-table>
        </grid-item>
        <grid-item
          :x="6"
          :y="5"
          :w="6"
          :h="5"
          i="4"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
181
        >
wanli's avatar
wanli committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
          <p class="item-title">LVGL</p>
          <el-table
            element-loading-text="Loading"
            :data="lvglList"
            size="mini"
            border
            stripe
            fit
            highlight-current-row
          >
            <el-table-column
              label="total_size"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.total_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column
              prop="free_cnt"
              label="free_cnt"
              min-width="100"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              label="free_size"
              min-width="120"
              show-overflow-tooltip
            >
              <template slot-scope="scope"
                >{{ scope.row.free_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column label="free_biggest_size" min-width="120">
              <template slot-scope="scope"
                >{{ scope.row.free_biggest_size }}(KB)</template
              >
            </el-table-column>
            <el-table-column label="used_cnt" min-width="100">
              <template slot-scope="scope">{{ scope.row.used_cnt }}</template>
            </el-table-column>
            <el-table-column label="used_pct" min-width="100">
              <template slot-scope="scope"
                >{{ scope.row.used_pct }}(%)</template
              >
            </el-table-column>
            <el-table-column label="frag_pct" min-width="100">
              <template slot-scope="scope"
                >{{ scope.row.frag_pct }}(%)</template
              >
            </el-table-column>
          </el-table>
        </grid-item>
        <grid-item
          :x="0"
          :y="10"
          :w="12"
wanli's avatar
wanli committed
240
          :h="10"
wanli's avatar
wanli committed
241 242 243 244 245 246
          i="5"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
247
        >
wanli's avatar
wanli committed
248 249 250 251 252 253 254 255 256 257
          <div style="width: 100%; height: 100%; overflow-y: auto">
            <p class="item-title">APP</p>
            <el-table
              element-loading-text="Loading"
              :data="imageList"
              size="mini"
              border
              stripe
              fit
              highlight-current-row
wanli's avatar
wanli committed
258
            >
wanli's avatar
wanli committed
259 260 261 262 263 264 265 266 267 268
              <el-table-column
                prop="uri"
                label="uri"
                min-width="150"
                show-overflow-tooltip
              ></el-table-column>
              <el-table-column
                label="length"
                min-width="150"
                show-overflow-tooltip
wanli's avatar
wanli committed
269
              >
wanli's avatar
wanli committed
270 271 272 273 274 275 276 277
                <template slot-scope="scope"
                  >{{ scope.row.length }}(KB)</template
                >
              </el-table-column>
              <el-table-column
                label="png_file_size"
                min-width="150"
                show-overflow-tooltip
wanli's avatar
wanli committed
278
              >
wanli's avatar
wanli committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                <template slot-scope="scope"
                  >{{ scope.row.png_file_size }}(KB)</template
                >
              </el-table-column>
              <el-table-column
                prop="png_total_count"
                label="png_total_count"
                min-width="150"
                show-overflow-tooltip
              ></el-table-column>
              <el-table-column
                label="png_uncompressed_size"
                min-width="150"
                show-overflow-tooltip
              >
                <template slot-scope="scope"
                  >{{ scope.row.png_uncompressed_size }}(KB)</template
                >
              </el-table-column>
            </el-table>
          </div>
wanli's avatar
wanli committed
300 301 302
        </grid-item>
        <grid-item
          :x="0"
wanli's avatar
wanli committed
303
          :y="20"
wanli's avatar
wanli committed
304 305 306 307 308 309 310 311
          :w="12"
          :h="7"
          i="6"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
312
        >
wanli's avatar
wanli committed
313 314 315 316
          <EvmChart :chartData="evm"></EvmChart>
        </grid-item>
        <grid-item
          :x="0"
wanli's avatar
wanli committed
317
          :y="27"
wanli's avatar
wanli committed
318 319 320 321 322 323 324 325
          :w="12"
          :h="7"
          i="7"
          @resize="resizeEvent"
          @move="moveEvent"
          @resized="resizedEvent"
          @container-resized="containerResizedEvent"
          @moved="movedEvent"
wanli's avatar
wanli committed
326
        >
wanli's avatar
wanli committed
327 328 329 330
          <LvglChart :chartData="lvgl"></LvglChart>
        </grid-item>
      </grid-layout>
    </div>
wanli's avatar
wanli committed
331 332 333
  </div>
</template>
<script>
wanli's avatar
wanli committed
334 335 336 337
import { getWatchList, getMonitorData } from "@/api/index";
import EvmChart from "./components/EvmChart";
import LvglChart from "./components/LvglChart";
import { GridLayout, GridItem } from "vue-grid-layout";
wanli's avatar
wanli committed
338
import { wsNotify } from "@/utils/eventBus.js";
wanli's avatar
wanli committed
339
export default {
wanli's avatar
wanli committed
340
  name: "Monitor",
wanli's avatar
wanli committed
341 342
  data() {
    return {
wanli's avatar
wanli committed
343
      watchs: [],
wanli's avatar
wanli committed
344 345
      device: null,
      devices: {},
wanli's avatar
wanli committed
346
      deviceList: null,
wanli's avatar
wanli committed
347
      system: [],
wanli's avatar
wanli committed
348 349 350 351 352 353
      evm: {},
      evmList: [],
      lvgl: {},
      lvglList: [],
      image: {},
      imageList: [],
wanli's avatar
wanli committed
354 355
      socket: null,
      form: {
wanli's avatar
wanli committed
356 357 358 359 360 361 362 363 364 365 366 367
        system: ["free_size"],
        lvgl: ["total_size", "free_size", "free_biggest_size"],
        evm: [
          "total_size",
          "free_size",
          "heap_map_size",
          "heap_total_size",
          "heap_used_size",
          "stack_total_size",
          "stack_used_size",
        ],
        image: ["png_uncompressed_size", "png_file_size", "length"],
wanli's avatar
wanli committed
368
      },
wanli's avatar
wanli committed
369 370 371 372 373
      layout: [
        { x: 0, y: 0, w: 6, h: 5, i: "0", static: false },
        { x: 6, y: 0, w: 6, h: 5, i: "1", static: true },
        { x: 0, y: 5, w: 6, h: 5, i: "2", static: false },
        { x: 6, y: 5, w: 6, h: 5, i: "3", static: false },
wanli's avatar
wanli committed
374 375 376
        { x: 0, y: 10, w: 12, h: 10, i: "4", static: false },
        { x: 0, y: 20, w: 12, h: 7, i: "5", static: false },
        { x: 0, y: 27, w: 12, h: 7, i: "6", static: false },
wanli's avatar
wanli committed
377 378 379
      ],
      draggable: true,
      resizable: true,
wanli's avatar
wanli committed
380 381
    };
  },
wanli's avatar
wanli committed
382 383 384 385 386 387
  components: {
    GridLayout,
    GridItem,
    EvmChart,
    LvglChart,
  },
wanli's avatar
wanli committed
388
  methods: {
wanli's avatar
wanli committed
389
    moveEvent(i, newX, newY) {
wanli's avatar
wanli committed
390 391 392
      const msg = "MOVE i=" + i + ", X=" + newX + ", Y=" + newY;
      console.log(msg);
    },
wanli's avatar
wanli committed
393
    movedEvent(i, newX, newY) {
wanli's avatar
wanli committed
394 395 396
      const msg = "MOVED i=" + i + ", X=" + newX + ", Y=" + newY;
      console.log(msg);
    },
wanli's avatar
wanli committed
397
    resizeEvent(i, newH, newW, newHPx, newWPx) {
wanli's avatar
wanli committed
398 399 400 401 402 403 404 405 406 407 408 409 410
      const msg =
        "RESIZE i=" +
        i +
        ", H=" +
        newH +
        ", W=" +
        newW +
        ", H(px)=" +
        newHPx +
        ", W(px)=" +
        newWPx;
      console.log(msg);
    },
wanli's avatar
wanli committed
411
    resizedEvent(i, newX, newY, newHPx, newWPx) {
wanli's avatar
wanli committed
412 413 414 415 416 417 418 419 420 421 422 423 424
      const msg =
        "RESIZED i=" +
        i +
        ", X=" +
        newX +
        ", Y=" +
        newY +
        ", H(px)=" +
        newHPx +
        ", W(px)=" +
        newWPx;
      console.log(msg);
    },
wanli's avatar
wanli committed
425
    containerResizedEvent(i, newH, newW, newHPx, newWPx) {
wanli's avatar
wanli committed
426 427 428 429 430 431 432 433 434 435 436 437 438
      const msg =
        "CONTAINER RESIZED i=" +
        i +
        ", H=" +
        newH +
        ", W=" +
        newW +
        ", H(px)=" +
        newHPx +
        ", W(px)=" +
        newWPx;
      console.log(msg);
    },
wanli's avatar
wanli committed
439
    layoutCreatedEvent(newLayout) {
wanli's avatar
wanli committed
440 441
      console.log("Created layout: ", newLayout);
    },
wanli's avatar
wanli committed
442
    layoutBeforeMountEvent(newLayout) {
wanli's avatar
wanli committed
443 444
      console.log("beforeMount layout: ", newLayout);
    },
wanli's avatar
wanli committed
445
    layoutMountedEvent(newLayout) {
wanli's avatar
wanli committed
446 447
      console.log("Mounted layout: ", newLayout);
    },
wanli's avatar
wanli committed
448
    layoutReadyEvent(newLayout) {
wanli's avatar
wanli committed
449 450
      console.log("Ready layout: ", newLayout);
    },
wanli's avatar
wanli committed
451
    layoutUpdatedEvent(newLayout) {
wanli's avatar
wanli committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
      console.log("Updated layout: ", newLayout);
    },
    fetchData() {
      this.isLoading = true;
      getWatchList()
        .then((res) => {
          if (res.code == 200) this.watchs = res.data;
        })
        .catch((err) => {
          this.$message.warning(err.msg);
        })
        .finally(() => {
          this.isLoading = false;
        });
    },
    queryData() {
      getMonitorData({
        watch: this.device,
      })
        .then((res) => {
          if (res.type == "object") {
            this.evmList = res.data.evm;
            this.lvglList = res.data.lvgl;
            this.imageList = res.data.image;
          }
        })
        .catch((err) => {
          this.$message.warning(err.msg);
        });
    },
    onChange(res) {
      if (!res) return null;

      var t = this.watchs.find((item) => {
        return item.id == res;
      });
      if (t) this.device = t.imei;

      // 清空之前数据
      this.resetData();
    },
    onSubmit() {
      this.queryData();
    },
    onReset(formName) {
      this.$refs[formName].resetFields();
      this.fetchData();
    },
wanli's avatar
wanli committed
500
    sendMsg() {
wanli's avatar
wanli committed
501 502 503 504
      let message = JSON.stringify({
        type: "auth",
        token: this.$store.getters.token,
      });
wanli's avatar
wanli committed
505 506 507
      this.socket.send(message);
    },
    handleMessage(msg) {
wanli's avatar
wanli committed
508
      if (msg.type !== "report" || !msg.imei) return false;
wanli's avatar
wanli committed
509

wanli's avatar
wanli committed
510
      if (!this.deviceList) {
wanli's avatar
wanli committed
511
        this.deviceList = [];
wanli's avatar
wanli committed
512 513
      }
      if (!this.deviceList.includes(msg.imei)) {
wanli's avatar
wanli committed
514
        this.deviceList.push(msg.imei);
wanli's avatar
wanli committed
515
      }
wanli's avatar
wanli committed
516 517 518
      if (!this.device) {
        if (this.deviceList && this.deviceList.length) this.device = this.deviceList[0];
        else this.device = msg.imei;
wanli's avatar
wanli committed
519
      }
wanli's avatar
wanli committed
520

wanli's avatar
wanli committed
521
      this.devices[msg.imei] = msg;
wanli's avatar
wanli committed
522
      this.processData(msg);
wanli's avatar
wanli committed
523
      this.resetData();
wanli's avatar
wanli committed
524 525
    },
    processData(msg) {
wanli's avatar
wanli committed
526
      if (!msg) return null;
wanli's avatar
wanli committed
527
      Object.keys(msg).forEach((item) => {
wanli's avatar
wanli committed
528
        if (this.form[item]) {
wanli's avatar
wanli committed
529 530 531
          var keys = this.form[item];
          for (var i = 0; i < keys.length; i++) {
            var k = keys[i];
wanli's avatar
wanli committed
532
            if (item == "image") {
wanli's avatar
wanli committed
533 534
              for (var j = 0; j < msg[item].length; j++) {
                msg[item][j][k] = Math.ceil(msg[item][j][k] / 1024);
wanli's avatar
wanli committed
535 536
              }
            } else {
wanli's avatar
wanli committed
537
              msg[item][k] = Math.ceil(msg[item][k] / 1024);
wanli's avatar
wanli committed
538 539 540
            }
          }
        }
wanli's avatar
wanli committed
541
      });
wanli's avatar
wanli committed
542 543 544 545 546 547 548 549 550
    },
    onSelectChange(res) {
      this.device = res;
      this.processData(this.devices[this.device]);
      this.resetData();
      console.log(res);
    },
    resetData() {
      wsNotify.eventBus.$emit("resize");
wanli's avatar
wanli committed
551

wanli's avatar
wanli committed
552 553 554
      this.evmList = [{ ...this.devices[this.device].evm }];
      this.lvglList = [{ ...this.devices[this.device].lvgl }];
      this.system = [{ imei: this.devices[this.device].imei, ...this.devices[this.device].system, ...this.devices[this.device].request }];
wanli's avatar
wanli committed
555

wanli's avatar
wanli committed
556 557
      // 这里需要特殊处理下,先判断uri是否存在,不存在则添加,存在则更新
      let uris = [];
wanli's avatar
wanli committed
558 559
      this.imageList.forEach((img) => {
        uris.push(img.uri);
wanli's avatar
wanli committed
560
      });
wanli's avatar
wanli committed
561 562
      this.devices[this.device].image &&
        this.devices[this.device].image.forEach((item) => {
wanli's avatar
wanli committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576
          if (!uris.includes(item.uri)) {
            this.imageList.push(item);
          }
        });
      // this.imageList = msg.image;

      if (this.devices[this.device]) {
        if (this.devices[this.device].evm)
          this.evm = this.devices[this.device].evm;
        if (this.devices[this.device].lvgl)
          this.lvgl = this.devices[this.device].lvgl;
        if (this.devices[this.device].image)
          this.image = this.devices[this.device].image;
      }
wanli's avatar
wanli committed
577
    },
wanli's avatar
wanli committed
578 579 580
  },
  mounted() {},
  created() {
wanli's avatar
wanli committed
581 582 583 584 585 586
    this.socket = wsNotify;
    wsNotify.eventBus.$on("open", (message) => {
      this.sendMsg();
      this.$nextTick(() => {
        console.log(message);
      });
wanli's avatar
wanli committed
587
      // 这里启动一个定时器,10秒钟后,如果没有消息进来,说明当前没有在线设备
wanli's avatar
wanli committed
588 589 590 591 592 593 594 595 596 597 598
    });
    wsNotify.eventBus.$on("close", (message) => {
      this.$nextTick(() => {
        console.log(message);
      });
    });
    wsNotify.eventBus.$on("message", (message) => {
      this.$nextTick(() => {
        this.handleMessage(message);
      });
    });
wanli's avatar
wanli committed
599 600 601 602 603 604 605 606 607
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  & > div.page-wrapper {
    margin: 10px 0px;
  }
}
wanli's avatar
wanli committed
608 609

.vue-grid-layout {
wanli's avatar
wanli committed
610
  background: none;
wanli's avatar
wanli committed
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
}
.vue-grid-item:not(.vue-grid-placeholder) {
  background: #fff;
  border: 0px solid #eee;
}
.vue-grid-item .resizing {
  opacity: 0.9;
}
.vue-grid-item .static {
  background: #cce;
}
.vue-grid-item .text {
  font-size: 24px;
  text-align: center;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  height: 100%;
  width: 100%;
}
.vue-grid-item .item-title {
  margin-left: 15px;
}
.vue-grid-item .no-drag {
  height: 100%;
  width: 100%;
}
.vue-grid-item .minMax {
  font-size: 12px;
}
.vue-grid-item .add {
  cursor: pointer;
}
.vue-draggable-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  top: 0;
  left: 0;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>")
    no-repeat;
  background-position: bottom right;
  padding: 0 8px 8px 0;
  background-repeat: no-repeat;
  background-origin: content-box;
  box-sizing: border-box;
  cursor: pointer;
}
wanli's avatar
wanli committed
662
</style>