duration of scan

This commit is contained in:
Volodymyr Smirnov 2020-10-27 21:40:34 +02:00
parent 2a933ebe6b
commit b3fc7ff2d9
9 changed files with 40 additions and 4 deletions

View File

@ -1,9 +1,12 @@
using System;
namespace MalwareMultiScan.Api.Data.Models
{
public class ScanResultEntry
{
public bool Completed { get; set; }
public bool? Succeeded { get; set; }
public long Duration { get; set; }
public string[] Threats { get; set; }
}
}

View File

@ -46,7 +46,7 @@ namespace MalwareMultiScan.Api.Services
$"with threats {string.Join(",", message.Threats)}");
await _scanResultService.UpdateScanResultForBackend(
message.Id, message.Backend, true,
message.Id, message.Backend, message.Duration, true,
message.Succeeded, message.Threats);
});

View File

@ -68,10 +68,11 @@ namespace MalwareMultiScan.Api.Services
/// </summary>
/// <param name="resultId">Result id.</param>
/// <param name="backendId">Backend id.</param>
/// <param name="duration">Duration of scan.</param>
/// <param name="completed">If the scan has been completed.</param>
/// <param name="succeeded">If the scan has been succeeded.</param>
/// <param name="threats">List of found threats.</param>
public async Task UpdateScanResultForBackend(string resultId, string backendId,
public async Task UpdateScanResultForBackend(string resultId, string backendId, long duration,
bool completed = false, bool succeeded = false, string[] threats = null)
{
await _collection.UpdateOneAsync(
@ -80,6 +81,7 @@ namespace MalwareMultiScan.Api.Services
{
Completed = completed,
Succeeded = succeeded,
Duration = duration,
Threats = threats ?? new string[] { }
}));
}

View File

@ -1,3 +1,5 @@
using System;
namespace MalwareMultiScan.Backends.Messages
{
public class ScanResultMessage
@ -7,5 +9,7 @@ namespace MalwareMultiScan.Backends.Messages
public bool Succeeded { get; set; }
public string[] Threats { get; set; }
public long Duration { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using EasyNetQ;
@ -61,6 +62,10 @@ namespace MalwareMultiScan.Scanner.Services
Id = message.Id,
Backend = _backend.Id
};
var stopwatch = new Stopwatch();
stopwatch.Start();
try
{
@ -80,6 +85,12 @@ namespace MalwareMultiScan.Scanner.Services
_logger.LogError(
exception, "Scanning failed with exception");
}
finally
{
stopwatch.Stop();
}
result.Duration = stopwatch.ElapsedMilliseconds / 1000;
_logger.LogInformation(
$"Sending scan results with status {result.Succeeded}");

View File

@ -1,3 +1,7 @@
.git
*.Dockerfile
Dockerfile
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs

View File

@ -4,12 +4,16 @@ export default class ScanResultEntryFlattened implements ScanResultEntry {
readonly id: string;
readonly completed: boolean;
readonly succeeded: boolean | null;
readonly duration: number;
readonly threats: string[];
constructor(id: string, completed: boolean, succeeded: boolean | null, threats: string[]) {
constructor(id: string, completed: boolean, succeeded: boolean | null, duration: number, threats: string[]) {
this.id = id;
this.completed = completed;
this.succeeded = succeeded;
this.duration = duration;
this.threats = threats;
}
}

View File

@ -1,5 +1,6 @@
export default interface ScanResultEntry {
readonly completed: boolean,
readonly succeeded: boolean | null,
readonly duration: number,
readonly threats: string[]
}

View File

@ -10,6 +10,11 @@
</div>
</template>
<template #cell(duration)="data">
<b-badge v-if="data.item.completed" variant="primary">{{ data.value }} seconds</b-badge>
<b-badge v-if="!data.item.completed" variant="secondary">pending</b-badge>
</template>
<template #cell(threats)="data">
<div class="text-success" v-if="data.item.succeeded && !data.item.threats.length">No threats have been detected</div>
<div class="text-danger" v-if="data.item.succeeded === false">Scan failed to complete due to the error or timeout</div>
@ -52,7 +57,8 @@ export default Vue.extend({
flattenedData(): ScanResultEntryFlattened[] {
return Object
.entries((this.data as ScanResult).results)
.map(([k, v]) => new ScanResultEntryFlattened(k, v.completed, v.succeeded, v.threats))
.map(([k, v]) => new ScanResultEntryFlattened(
k, v.completed, v.succeeded, v.duration, v.threats))
}
},
@ -63,6 +69,7 @@ export default Vue.extend({
fields: [
{key: 'id', label: 'Backend'},
{key: 'completed', label: 'Completed'},
{key: 'duration', label: 'Duration'},
{key: 'threats', label: 'Threats'},
],