Skip to content
Snippets Groups Projects
Commit f78c10f2 authored by Dmytro Bogatov's avatar Dmytro Bogatov :two_hearts:
Browse files

Docs.

parent 89ece02f
Branches
No related tags found
No related merge requests found
......@@ -89,6 +89,9 @@ Configuration spec:
PingService: # Settings for ping service of the app
Enabled: true # Whether to use the service
Interval: 60 # How many seconds to wait between re-runs of the service
PingService: # Settings for health service of the app
Enabled: true # Whether to use the service
Interval: 60 # How many seconds to wait between re-runs of the service
DemoService: # Settings for demo service of the app
Enabled: true # Whether to use the service
Interval: 30 # How many seconds to wait between re-runs of the service
......
......
......@@ -8,8 +8,16 @@ using StatusMonitor.Shared.Models.Entities;
namespace StatusMonitor.Daemons.Services
{
/// <summary>
/// Produces overall health report of the system
/// </summary>
public interface IHealthService
{
/// <summary>
/// Returns a health report of the whole system at the moment
/// Analyzes only public metrics
/// </summary>
/// <returns>Overall health report of the system</returns>
Task<HealthReport> ProduceHealthReportAsync();
}
......@@ -44,7 +52,7 @@ namespace StatusMonitor.Daemons.Services
MetricType = (Metrics)mt.Type,
MetricLabel = (AutoLabels)mt.AutoLabel.Id
})
.ToArrayAsync()
.ToListAsync()
};
_logger.LogDebug($"Health report created. Health level: {report.Health}");
......
......
......@@ -23,12 +23,20 @@ namespace StatusMonitor.Shared.Models.Entities
/// </summary>
public class AutoLabel : Label
{
/// <summary>
/// Returns the highest available health value for the metric
/// </summary>
/// <returns>Highest available health value for the metric</returns>
public static int MaxHealthValue()
{
return 2;
}
public int DamageUnit()
/// <summary>
/// Returns health value of this particular label
/// </summary>
/// <returns>Health value of this particular label</returns>
public int HealthValue()
{
switch ((AutoLabels)Id)
{
......
......
......@@ -8,10 +8,17 @@ using StatusMonitor.Shared.Extensions;
namespace StatusMonitor.Shared.Models.Entities
{
/// <summary>
/// An elementary piece of health data.
/// Stores the label of a metric.
/// </summary>
public class HealthReportDataPoint
{
[JsonIgnore]
[NotMapped]
/// <summary>
/// Type of the metric
/// </summary>
public Metrics MetricType
{
get
......@@ -31,11 +38,19 @@ namespace StatusMonitor.Shared.Models.Entities
}
}
/// <summary>
/// String alias of the metric's type
/// Should not be used directly
/// Serves as a column in DB
/// </summary>
public string Type { get; set; }
[JsonIgnore]
[NotMapped]
/// <summary>
/// Label of the metric
/// </summary>
public AutoLabels MetricLabel
{
get
......@@ -56,13 +71,25 @@ namespace StatusMonitor.Shared.Models.Entities
}
[JsonProperty("Label")]
/// <summary>
/// String alias of the metric's label
/// Should not be used directly
/// Serves as a column in DB
/// </summary>
public string Label { get; set; }
public string Source { get; set; }
}
/// <summary>
/// Entity that encapsulates the overall health of the system at the moment
/// </summary>
public class HealthReport
{
/// <summary>
/// Percentage that encapsulates numeric value of the health
/// Computed as a weighted average of individual healths, which are derived from the auto labels
/// </summary>
public int Health
{
get
......@@ -77,7 +104,7 @@ namespace StatusMonitor.Shared.Models.Entities
0,
(sum, element) =>
sum +
new AutoLabel { Id = element.Key.AsInt() }.DamageUnit() * element.Count()
new AutoLabel { Id = element.Key.AsInt() }.HealthValue() * element.Count()
)
)
/
......@@ -94,6 +121,10 @@ namespace StatusMonitor.Shared.Models.Entities
}
[NotMapped]
/// <summary>
/// Collection of individual health pieces.
/// Wrapper around HealthData which is a JSON of this property
/// </summary>
public IEnumerable<HealthReportDataPoint> Data
{
get
......@@ -107,9 +138,17 @@ namespace StatusMonitor.Shared.Models.Entities
}
[JsonIgnore]
/// <summary>
/// JSONified value of Data
/// Should not be used directly
/// Serves as a column in DB
/// </summary>
public string HealthData { get; set; } = JsonConvert.SerializeObject(new List<HealthReportDataPoint>());
[Key]
/// <summary>
/// Timestamp when this health report was generated
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
}
......@@ -12,8 +12,15 @@ using StatusMonitor.Shared.Models;
namespace StatusMonitor.Web.Services
{
/// <summary>
/// Generates SVG badges
/// </summary>
public interface IBadgeService
{
/// <summary>
/// Generates overall health of the system badge
/// </summary>
/// <returns>Badge indicating overall health of the system</returns>
Task<Badge> GetHealthBadgeAsync();
}
......@@ -37,7 +44,7 @@ namespace StatusMonitor.Web.Services
Title = "System health",
Message = $"{healthReport.Health.ToString("D2")}%",
Status =
healthReport.Health == 100 ?
healthReport.Health >= 90 ?
BadgeStatus.Success :
(healthReport.Health >= 70 ?
BadgeStatus.Neutural :
......@@ -50,7 +57,7 @@ namespace StatusMonitor.Web.Services
}
/// <summary>
/// Special action result that returns sitemap
/// Special action result that returns badge
/// </summary>
public class BadgeResult : IActionResult
{
......@@ -123,15 +130,37 @@ namespace StatusMonitor.Web.Services
}
}
/// <summary>
/// Badge model
/// </summary>
public class Badge
{
/// <summary>
/// Leftmost text
/// </summary>
public string Title { get; set; }
/// <summary>
/// Rightmost text
/// </summary>
public string Message { get; set; }
/// <summary>
/// Semantic meaning of the badge (good/bad)
/// </summary>
public BadgeStatus Status { get; set; }
/// <summary>
/// Width in px of the title
/// </summary>
public int TitleWidth { get; set; }
/// <summary>
/// Width in px of the message
/// </summary>
public int MessageWidth { get; set; }
/// <summary>
/// HEX color representation of the badge semantic meaning
/// </summary>
/// <returns></returns>
public string HexColor
{
get
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment