mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-21 01:48:54 +01:00
feat(service): add Service entity with properties for service management
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -137,3 +137,4 @@ dist
|
|||||||
# Vite logs files
|
# Vite logs files
|
||||||
vite.config.js.timestamp-*
|
vite.config.js.timestamp-*
|
||||||
vite.config.ts.timestamp-*
|
vite.config.ts.timestamp-*
|
||||||
|
node.txt
|
||||||
@@ -13,4 +13,4 @@ export class HostsLog {
|
|||||||
|
|
||||||
@CreateDateColumn()
|
@CreateDateColumn()
|
||||||
created_at: Date;
|
created_at: Date;
|
||||||
}
|
}
|
||||||
25
src/entity/service.entity.ts
Normal file
25
src/entity/service.entity.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
|
||||||
|
@Entity({name: 'services'})
|
||||||
|
export class Service {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
host: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
alive: boolean;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
ping_type: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
type: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
notify: boolean;
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import { Follow } from "../entity/follow.entity";
|
|||||||
import { Guild } from "../entity/guild.entity";
|
import { Guild } from "../entity/guild.entity";
|
||||||
import dayjs, { Dayjs } from "dayjs";
|
import dayjs, { Dayjs } from "dayjs";
|
||||||
import { Canvas } from "canvas";
|
import { Canvas } from "canvas";
|
||||||
|
import { Service } from "../entity/service.entity";
|
||||||
|
|
||||||
type Nofity = {time: Date, name : string, alive : boolean, type : InfraType, host: string};
|
type Nofity = {time: Date, name : string, alive : boolean, type : InfraType, host: string};
|
||||||
|
|
||||||
@@ -134,12 +135,14 @@ export class StatusService {
|
|||||||
private hostsLogRepo: Repository<HostsLog>;
|
private hostsLogRepo: Repository<HostsLog>;
|
||||||
private followRepo: Repository<Follow>;
|
private followRepo: Repository<Follow>;
|
||||||
private guildRepo: Repository<Guild>;
|
private guildRepo: Repository<Guild>;
|
||||||
|
private serviceRepo: Repository<Service>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
this.hostsLogRepo = AppDataSource.getRepository(HostsLog);
|
this.hostsLogRepo = AppDataSource.getRepository(HostsLog);
|
||||||
this.followRepo = AppDataSource.getRepository(Follow);
|
this.followRepo = AppDataSource.getRepository(Follow);
|
||||||
this.guildRepo = AppDataSource.getRepository(Guild);
|
this.guildRepo = AppDataSource.getRepository(Guild);
|
||||||
|
this.serviceRepo = AppDataSource.getRepository(Service);
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await this.fetch()
|
await this.fetch()
|
||||||
|
|||||||
77
test.js
77
test.js
@@ -1,77 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
var canvas_1 = require("canvas");
|
|
||||||
var dayjs = require("dayjs");
|
|
||||||
var fs_1 = require("fs");
|
|
||||||
function createUptimeBar(uptimes) {
|
|
||||||
var now = dayjs();
|
|
||||||
var week = now.clone().subtract(1, 'week');
|
|
||||||
var canvas = new canvas_1.Canvas(100, 2, "image");
|
|
||||||
var ctx = canvas.getContext('2d');
|
|
||||||
ctx.fillStyle = "#27FF00";
|
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
||||||
var maxTime = (now.unix() - week.unix());
|
|
||||||
var ranges = [];
|
|
||||||
var minTime = null;
|
|
||||||
uptimes.map(function (element, index) {
|
|
||||||
var positionForMaxTime = (element.date.unix() - week.unix());
|
|
||||||
var percent = Math.round((positionForMaxTime / maxTime) * 100);
|
|
||||||
if (ranges.length == 0 && minTime == null) {
|
|
||||||
if (element.up && minTime == null) {
|
|
||||||
ranges.push({
|
|
||||||
min: 0,
|
|
||||||
max: percent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
minTime = percent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!element.up) {
|
|
||||||
minTime = percent;
|
|
||||||
if (minTime != null && index == uptimes.length - 1) {
|
|
||||||
ranges.push({
|
|
||||||
min: minTime,
|
|
||||||
max: 100
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (minTime) {
|
|
||||||
ranges.push({
|
|
||||||
min: minTime,
|
|
||||||
max: percent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ctx.fillStyle = '#ff0000';
|
|
||||||
ranges.map(function (value) {
|
|
||||||
ctx.fillRect(value.min, 0, value.max - value.min, canvas.height);
|
|
||||||
});
|
|
||||||
(0, fs_1.writeFile)('test.png', canvas.toBuffer('image/png'), function (err) {
|
|
||||||
if (err)
|
|
||||||
throw err;
|
|
||||||
console.log('Image saved!');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
createUptimeBar([
|
|
||||||
{
|
|
||||||
up: true,
|
|
||||||
date: dayjs().subtract(6, 'day')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
up: false,
|
|
||||||
date: dayjs().subtract(3, 'day')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
up: true,
|
|
||||||
date: dayjs().subtract(1, 'day')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
up: false,
|
|
||||||
date: dayjs().subtract(1, 'hour')
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
81
test.ts
81
test.ts
@@ -1,81 +0,0 @@
|
|||||||
import { Canvas } from "canvas";
|
|
||||||
import * as dayjs from "dayjs";
|
|
||||||
import { Dayjs } from "dayjs";
|
|
||||||
import { writeFile } from "fs";
|
|
||||||
|
|
||||||
function createUptimeBar(uptimes: { up: boolean, date: Dayjs }[]) {
|
|
||||||
const now = dayjs();
|
|
||||||
const week = now.clone().subtract(1, 'week');
|
|
||||||
|
|
||||||
const canvas = new Canvas(100, 2, "image");
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
|
|
||||||
ctx.fillStyle = "#27FF00";
|
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
const maxTime = (now.unix() - week.unix());
|
|
||||||
const ranges: { min: number, max: number }[] = [];
|
|
||||||
|
|
||||||
let minTime: number | null = null;
|
|
||||||
uptimes.map((element, index) => {
|
|
||||||
const positionForMaxTime = (element.date.unix() - week.unix());
|
|
||||||
const percent = Math.round((positionForMaxTime / maxTime) * 100);
|
|
||||||
|
|
||||||
if (ranges.length == 0 && minTime == null) {
|
|
||||||
if (element.up && minTime == null) {
|
|
||||||
ranges.push({
|
|
||||||
min: 0,
|
|
||||||
max: percent
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
minTime = percent;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!element.up) {
|
|
||||||
minTime = percent;
|
|
||||||
|
|
||||||
if(minTime != null && index == uptimes.length - 1) {
|
|
||||||
ranges.push({
|
|
||||||
min: minTime,
|
|
||||||
max: 100
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (minTime) {
|
|
||||||
ranges.push({
|
|
||||||
min: minTime,
|
|
||||||
max: percent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ctx.fillStyle = '#ff0000';
|
|
||||||
ranges.map((value) => {
|
|
||||||
ctx.fillRect(value.min, 0, value.max - value.min, canvas.height);
|
|
||||||
});
|
|
||||||
|
|
||||||
writeFile('test.png', canvas.toBuffer('image/png'), (err) => {
|
|
||||||
if (err) throw err;
|
|
||||||
console.log('Image saved!');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
createUptimeBar([
|
|
||||||
{
|
|
||||||
up: true,
|
|
||||||
date: dayjs().subtract(6, 'day')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
up: false,
|
|
||||||
date: dayjs().subtract(3, 'day')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
up: true,
|
|
||||||
date: dayjs().subtract(1, 'day')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
up: false,
|
|
||||||
date: dayjs().subtract(1, 'hour')
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
Reference in New Issue
Block a user