Heartbeat before each performance message

Updated readme
This commit is contained in:
Mike Phares 2025-04-24 17:21:38 -07:00
parent 6eb36f44c5
commit 8311e26759
5 changed files with 206 additions and 53 deletions

View File

@ -10,6 +10,7 @@
"**/node_modules": true "**/node_modules": true
}, },
"cSpell.words": [ "cSpell.words": [
"Gatus" "Gatus",
"Infineon"
] ]
} }

View File

@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.1" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.14" /> <PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.15" />
<PackageReference Include="System.Text.Json" Version="9.0.2" /> <PackageReference Include="System.Text.Json" Version="9.0.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -12,7 +12,39 @@ internal static partial class HelperGatusToMona {
private static string GetFile(AppSettings appSettings) => private static string GetFile(AppSettings appSettings) =>
Path.Combine(appSettings.GatusToMonaConfiguration.Directory, appSettings.GatusConfiguration.FileName); Path.Combine(appSettings.GatusToMonaConfiguration.Directory, appSettings.GatusConfiguration.FileName);
internal static bool UpdateCount(AppSettings appSettings, ILogger<Worker> logger, CancellationToken cancellationToken) { internal static void Heartbeat(AppSettings appSettings, IHttpClientFactory httpClientFactory, ILogger<Worker> logger, State state, CancellationToken cancellationToken) {
_MonIn ??= MonIn.GetInstance(httpClientFactory);
CreateEmptyFile(appSettings);
Task<HttpResponseMessage> httpResponseMessage = _MonIn.SendStatus(appSettings.MonAConfiguration.Site,
appSettings.MonAConfiguration.Resource,
appSettings.MonAConfiguration.StateName,
state);
httpResponseMessage.Wait(cancellationToken);
logger.LogInformation("Line {line}: {OriginalString} => {Resource} : {StateName} ; {state}",
99,
httpResponseMessage.Result.RequestMessage.RequestUri.OriginalString,
appSettings.MonAConfiguration.Resource,
appSettings.MonAConfiguration.StateName,
state);
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
Task<string> body = httpResponseMessage.Result.Content.ReadAsStringAsync(cancellationToken);
body.Wait(cancellationToken);
logger.LogInformation("Line {line}: {Result}",
10,
body.Result);
}
private static void CreateEmptyFile(AppSettings appSettings) {
if (!Directory.Exists(appSettings.GatusToMonaConfiguration.Directory))
_ = Directory.CreateDirectory(appSettings.GatusToMonaConfiguration.Directory);
string file = GetFile(appSettings);
File.WriteAllText(file, string.Empty);
}
internal static bool UpdateCount(AppSettings appSettings, IHttpClientFactory httpClientFactory, ILogger<Worker> logger, CancellationToken cancellationToken) {
_MonIn ??= MonIn.GetInstance(httpClientFactory);
Heartbeat(appSettings, httpClientFactory, logger, State.Up, cancellationToken);
ReadOnlyCollection<string> successMatches = GetSuccessMatches(appSettings, logger, cancellationToken); ReadOnlyCollection<string> successMatches = GetSuccessMatches(appSettings, logger, cancellationToken);
SendPerformanceMessage(appSettings, logger, successMatches, cancellationToken); SendPerformanceMessage(appSettings, logger, successMatches, cancellationToken);
return true; return true;
@ -35,10 +67,15 @@ internal static partial class HelperGatusToMona {
continue; continue;
if (value[^1] is not '0' and not '1') if (value[^1] is not '0' and not '1')
continue; continue;
logger.LogDebug(value); logger.LogInformation("Line {line}: {value}",
39,
value);
if (line.EndsWith('1')) if (line.EndsWith('1'))
results.Add(string.Concat('{', value)); results.Add(string.Concat('{', value));
} }
logger.LogInformation("Line {line}: {results}",
45,
string.Join(Environment.NewLine, results));
return results.AsReadOnly(); return results.AsReadOnly();
} }
@ -67,33 +104,19 @@ internal static partial class HelperGatusToMona {
value, value,
description: string.Empty); description: string.Empty);
httpResponseMessage.Wait(cancellationToken); httpResponseMessage.Wait(cancellationToken);
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK) logger.LogInformation("Line {line}: {OriginalString} => {Resource} : {performanceName} ; {value}",
throw new Exception(httpResponseMessage.Result.StatusCode.ToString()); 76,
Task<string> body = httpResponseMessage.Result.Content.ReadAsStringAsync(cancellationToken); httpResponseMessage.Result.RequestMessage.RequestUri.OriginalString,
body.Wait(cancellationToken);
logger.LogDebug(body.Result);
}
internal static void Heartbeat(AppSettings appSettings, IHttpClientFactory httpClientFactory, ILogger<Worker> logger, State state, CancellationToken cancellationToken) {
_MonIn ??= MonIn.GetInstance(httpClientFactory);
CreateEmptyFile(appSettings);
Task<HttpResponseMessage> httpResponseMessage = _MonIn.SendStatus(appSettings.MonAConfiguration.Site,
appSettings.MonAConfiguration.Resource, appSettings.MonAConfiguration.Resource,
appSettings.MonAConfiguration.StateName, performanceName,
state); value);
httpResponseMessage.Wait(cancellationToken);
if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK) if (httpResponseMessage.Result.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception(httpResponseMessage.Result.StatusCode.ToString()); throw new Exception(httpResponseMessage.Result.StatusCode.ToString());
Task<string> body = httpResponseMessage.Result.Content.ReadAsStringAsync(cancellationToken); Task<string> body = httpResponseMessage.Result.Content.ReadAsStringAsync(cancellationToken);
body.Wait(cancellationToken); body.Wait(cancellationToken);
logger.LogDebug(body.Result); logger.LogInformation("Line {line}: {Result}",
} 86,
body.Result);
private static void CreateEmptyFile(AppSettings appSettings) {
if (!Directory.Exists(appSettings.GatusToMonaConfiguration.Directory))
_ = Directory.CreateDirectory(appSettings.GatusToMonaConfiguration.Directory);
string file = GetFile(appSettings);
File.WriteAllText(file, string.Empty);
} }
} }

166
README.md
View File

@ -1,20 +1,154 @@
# Introduction ---
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project. created: 2024-11-07T00:14:29.000Z
type: note
---
# Getting Started # Gatus
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
1. Installation process
2. Software dependencies
3. Latest releases
4. API references
# Build and Test Gatus is an advanced automated status page that lets you monitor your applications and configure alerts to notify you if there's an issue
TODO: Describe and show how to build your code and run the tests.
# Contribute ## Links
TODO: Explain how other users and developers can contribute to make your code better.
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files: - [gatus.io](https://gatus.io/)
- [ASP.NET Core](https://github.com/aspnet/Home) - [github](https://github.com/TwiN/gatus)
- [Visual Studio Code](https://github.com/Microsoft/vscode) - [techno-tim](https://technotim.live/posts/gatus-uptime-monitoring/#gatus-config)
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
## Install
- [ ] CasaOS
- [x] Docker
- [ ] Home Assistant
- [ ] lxc
- [ ] Snap
- [ ] TTeck
- [ ] Umbrel
- [ ] Yu No Host
## Gatus
- Clone repo from github or local ADO
- Build using go lang
- Copy exe only to server
- Create *.yaml file for configuration
## NSSM - the Non-Sucking Service Manager
- Copy zip to server and extract to directory
- Run a cmd window with administrator access
### ecFIsysadmin-10.95.140.37-messa010ec(OI-Metrology-Viewer)
```bash 1744999536292 = 638805963362920000 = 2025-1.Spring = Fri Apr 18 2025 11:05:35 GMT-0700 (Mountain Standard Time)
mklink /J "D:\web-sites\Gatus\current" "D:\web-sites\Gatus\v5.17.0"
```
```bash 1744999568664 = 638805963686640000 = 2025-1.Spring = Fri Apr 18 2025 11:06:08 GMT-0700 (Mountain Standard Time)
# cd "C:\Users\ecfisysadmin\AppData\Local\IFXApps\nssm-2.24\win64"
C:
cd "C:\Windows\System32\config\systemprofile\AppData\Local\IFXApps\nssm-2.24\win64"
nssm install gatus
nssm edit gatus
```
```yaml NSSM-Application 1743806212388 = 638794030123880000 = 2025-1.Spring = Fri Apr 04 2025 15:36:51 GMT-0700 (Mountain Standard Time)
Path: D:\web-sites\Gatus\current\gatus.exe
Startup Directory: D:\web-sites\Gatus\current
```
```yml NSSM-Details 1743806328796 = 638794031287960000 = 2025-1.Spring = Fri Apr 04 2025 15:38:48 GMT-0700 (Mountain Standard Time)
Startup type: Automatic (Delay Start)
```
```yml NSSM-I/O 1743806328796 = 638794031287960000 = 2025-1.Spring = Fri Apr 04 2025 15:38:48 GMT-0700 (Mountain Standard Time)
Input (stdin):
Output (stdout): D:\web-sites\Gatus\current\logs\service.out.log
Error (stderr): D:\web-sites\Gatus\current\logs\service.error.log
```
```yml NSSM-Environment 1743806359765 = 638794031597650000 = 2025-1.Spring = Fri Apr 04 2025 15:39:19 GMT-0700 (Mountain Standard Time)
GATUS_CONFIG_PATH=./oi-metrology-viewer.yaml
```
```bash Administrator 1743806328796 = 638794031287960000 = 2025-1.Spring = Fri Apr 04 2025 15:38:48 GMT-0700 (Mountain Standard Time)
sc start gatus
sc query gatus
sc stop gatus
sc start gatus
# systemctl start gatus
```
```bash 1745023773786 = 638806205737860000 = 2025-1.Spring = Fri Apr 18 2025 17:49:33 GMT-0700 (Mountain Standard Time)
mklink /J "D:\web-sites\Gatus\.Gatus-to-MonA" "C:\Windows\System32\config\systemProfile\AppData\Local\IFXApps\Gatus-to-MonA"
mkdir "D:/Tmp/Gatus-to-MonA"
```
## Nginx
- Add new server to proxy pass to 8081
- Test nginx
- Restart nginx
## MonA
- Create generic resource type
- On overview page click edit then click update without making any changes
- Wait a hour
- On data page click Edit Resource Name then click update without making any changes
- Wait a day
- On overview page click use for main status (Heartbeat)
- Refresh config page and search for threshold
- Define threshold
## Sdk="Microsoft.NET.Sdk.Worker"
- Build with AOT task
- Copy publish directory to server
- Copy / edit secrets file
- Verify windows event viewer entry for company name
```bash 1743817269373 = 638794140693730000 = 2025-1.Spring = Fri Apr 04 2025 18:41:08 GMT-0700 (Mountain Standard Time)
sc.exe create "Gatus-to-MonA" binpath="C:\Windows\System32\config\systemprofile\AppData\Local\IFXApps\Gatus-to-MonA\Gatus-to-MonA.exe"
```
## MonA Instances
- [MES_APC_GATUS](https://mona.auc.infineon.com/auc/systems/563556/dependencies?config=true)
- messa013ec.infineon.com
- [MES_EAF_GATUS](https://mona.auc.infineon.com/auc/systems/563493/dependencies?config=true)
- messa08ec.infineon.com
- [MES_EAF_STAGE_GATUS](https://mona.auc.infineon.com/auc/systems/563516/dependencies?config=true)
- mestsa07ec.infineon.com
- [MES_FAB_APPROVAL_SYSTEM_GATUS](https://mona.auc.infineon.com/auc/systems/563517/dependencies?config=true)
- messa016ec.infineon.com
- https://messa016ec.infineon.com
- [MES_FAB_TIME_GATUS](https://mona.auc.infineon.com/auc/systems/563518/dependencies?config=true)
- messa004.infineon.com
- [MES_INFINITY_QS_SI_GATUS](https://mona.auc.infineon.com/auc/systems/563519/dependencies?config=true)
- messa04ec.infineon.com
- [MES_OPEN_INSIGHT_GATUS](https://mona.auc.infineon.com/auc/systems/563520/dependencies?config=true)
- GATUS_CONFIG_PATH=./oi.yaml
- messa01ec.infineon.com
- http://messa014.infineon.com/api/heartbeat
- http://messa014.infineon.com/API/RemoteHealthCheck/Mona/MonaEngines/DB-EN1
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN10
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN11
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN12
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN2
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN3
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN4
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN5
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN6
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN7
- http://messa014.infineon.com/api/RemoteHealthCheck/Mona/MonaEngines/DB-EN9
- [MES_OPEN_INSIGHT_DEV_GATUS](https://mona.auc.infineon.com/auc/systems/563521/dependencies?config=true)
- mestsa01ec.infineon.com
- [MES_OI_METROLOGY_VIEWER_GATUS](https://mona.auc.infineon.com/auc/systems/557090/dependencies?config=true)
- messa010ec.infineon.com
- [MES_OI_WEB_SERVICES_GATUS](https://mona.auc.infineon.com/auc/systems/563522/dependencies?config=true)
- messa020ec.infineon.com
- ~~messa014.infineon.com~~
- https://messa014.infineon.com/scan
- https://messa014.infineon.com:50184
- https://messa014.infineon.com:5022
- [LEO_EAF_GATUS](https://mona.auc.infineon.com/auc/systems/563522/dependencies?config=true)
- leosaec17.infineon.com

View File

@ -8,7 +8,6 @@ namespace Gatus.To.MonA;
public partial class Worker : BackgroundService { public partial class Worker : BackgroundService {
private bool? _First;
private readonly bool _IsWindowsService; private readonly bool _IsWindowsService;
private readonly ILogger<Worker> _Logger; private readonly ILogger<Worker> _Logger;
private readonly AppSettings _AppSettings; private readonly AppSettings _AppSettings;
@ -20,7 +19,6 @@ public partial class Worker : BackgroundService {
_HttpClientFactory = httpClientFactory; _HttpClientFactory = httpClientFactory;
logger.LogInformation(string.Join(Environment.NewLine, collection)); logger.LogInformation(string.Join(Environment.NewLine, collection));
try { logger.LogInformation("<{folder}>", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); } catch (Exception) { } try { logger.LogInformation("<{folder}>", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); } catch (Exception) { }
_First = null;
_IsWindowsService = collection.Contains(nameof(WindowsServiceLifetime)); _IsWindowsService = collection.Contains(nameof(WindowsServiceLifetime));
} }
@ -42,23 +40,20 @@ public partial class Worker : BackgroundService {
} }
} }
while (_IsWindowsService && !cancellationToken.IsCancellationRequested) { while (_IsWindowsService && !cancellationToken.IsCancellationRequested) {
try {
BodyInner(cancellationToken); BodyInner(cancellationToken);
await Task.Delay(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay, cancellationToken); await Task.Delay(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay, cancellationToken);
} catch (Exception ex) { _Logger.LogError(ex, "Unexpected Error!"); }
} }
} }
private void BodyInner(CancellationToken cancellationToken) { private void BodyInner(CancellationToken cancellationToken) {
_Logger.LogInformation("A) Next execute will be at {date}", DateTime.Now.AddMilliseconds(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay).ToString("yyyy-MM-dd hh:mm:ss.fff tt")); _Logger.LogInformation("A) Next execute will be at {date}", DateTime.Now.AddMilliseconds(_AppSettings.GatusToMonaConfiguration.MillisecondsDelay).ToString("yyyy-MM-dd hh:mm:ss.fff tt"));
if (_First is null || _First.Value) {
_First = false;
if (_AppSettings.GatusToMonaConfiguration.Helper == nameof(Helpers.HelperGatusToMona))
Helpers.HelperGatusToMona.Heartbeat(_AppSettings, _HttpClientFactory, _Logger, Infineon.Monitoring.MonA.State.Up, cancellationToken);
}
if (!Directory.Exists(_AppSettings.GatusToMonaConfiguration.Directory)) if (!Directory.Exists(_AppSettings.GatusToMonaConfiguration.Directory))
_ = Directory.CreateDirectory(_AppSettings.GatusToMonaConfiguration.Directory); _ = Directory.CreateDirectory(_AppSettings.GatusToMonaConfiguration.Directory);
else { else {
_ = _AppSettings.GatusToMonaConfiguration.Helper switch { _ = _AppSettings.GatusToMonaConfiguration.Helper switch {
nameof(Helpers.HelperGatusToMona) => Helpers.HelperGatusToMona.UpdateCount(_AppSettings, _Logger, cancellationToken), nameof(Helpers.HelperGatusToMona) => Helpers.HelperGatusToMona.UpdateCount(_AppSettings, _HttpClientFactory, _Logger, cancellationToken),
_ => throw new NotSupportedException() _ => throw new NotSupportedException()
}; };
} }