Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc92c80b43 | ||
|
|
724644c8eb | ||
|
|
23768dbe0e | ||
|
|
ace23b954e | ||
|
|
a4fc8c047a | ||
|
|
5a2639f96c | ||
|
|
fbd94ae1e6 |
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.17
|
1.0.23
|
||||||
|
|||||||
@@ -1 +1,79 @@
|
|||||||
"# monster_monitor_v2"
|
# Monster Monitor v2
|
||||||
|
|
||||||
|
Windows-приложение (WinForms, .NET Framework 4.7.2) для мониторинга процесса `ss.exe`, поддержки SSH-туннеля и контроля состояния сервисов с логированием в UI.
|
||||||
|
|
||||||
|
## Возможности
|
||||||
|
|
||||||
|
- мониторинг и автоподдержка процесса `ss.exe`;
|
||||||
|
- управление SSH-туннелем;
|
||||||
|
- предотвращение засыпания системы во время работы;
|
||||||
|
- логирование событий в консоль приложения;
|
||||||
|
- хранение настроек в локальном профиле пользователя;
|
||||||
|
- автообновление через GitHub Releases (с проверкой раз в час);
|
||||||
|
- поддержка proxy для запросов к GitHub API и скачивания релизов.
|
||||||
|
|
||||||
|
## Требования
|
||||||
|
|
||||||
|
- Windows 10+;
|
||||||
|
- .NET Framework 4.7.2 (target `net472`);
|
||||||
|
- доступ к GitHub (напрямую или через proxy).
|
||||||
|
|
||||||
|
## Сборка и запуск
|
||||||
|
|
||||||
|
Из корня репозитория:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
dotnet build .\src\MonsterMonitor\MonsterMonitor.csproj
|
||||||
|
dotnet run --project .\src\MonsterMonitor\MonsterMonitor.csproj
|
||||||
|
```
|
||||||
|
|
||||||
|
Или откройте `src/MonsterMonitor.sln` в Visual Studio и запустите проект `MonsterMonitor`.
|
||||||
|
|
||||||
|
## Настройки
|
||||||
|
|
||||||
|
Настройки сохраняются в:
|
||||||
|
|
||||||
|
`%LOCALAPPDATA%\MonsterMonitor\settings.ini`
|
||||||
|
|
||||||
|
Основные параметры:
|
||||||
|
|
||||||
|
- `SshHost`, `SshPort`, `SshUsername`, `SshPasswordProtected`;
|
||||||
|
- `RemotePort`, `LocalPort`;
|
||||||
|
- `MaxPingFailures`, `ReconnectTimeoutSec`;
|
||||||
|
- `SsProcessPath`, `SsArguments`;
|
||||||
|
- `Proxy` — адрес proxy для GitHub-запросов (пример: `http://host:port`).
|
||||||
|
|
||||||
|
Часть паролей хранится в защищенном виде через DPAPI.
|
||||||
|
|
||||||
|
## Автообновление
|
||||||
|
|
||||||
|
Приложение проверяет новые версии в GitHub репозитории:
|
||||||
|
|
||||||
|
- owner: `monster1025`
|
||||||
|
- repo: `monster_monitor_v2`
|
||||||
|
|
||||||
|
Логика:
|
||||||
|
|
||||||
|
1. Определяется текущая версия приложения.
|
||||||
|
2. Получается последняя версия релиза из GitHub.
|
||||||
|
3. Если версия новее текущей — скачивается `.zip`-ассет релиза.
|
||||||
|
4. Обновление подготавливается в директории приложения:
|
||||||
|
- `.\update\<version>\update.zip`
|
||||||
|
- `.\update\<version>\extracted`
|
||||||
|
- `.\update\<version>\apply_update.bat`
|
||||||
|
5. Пользователю предлагается перезапустить приложение для применения обновления.
|
||||||
|
|
||||||
|
Периодичность проверки: каждые 60 минут (и первичная проверка после старта приложения).
|
||||||
|
|
||||||
|
## Интерфейс
|
||||||
|
|
||||||
|
- Главное окно:
|
||||||
|
- кнопка `Настройки`;
|
||||||
|
- кнопка `Выход`;
|
||||||
|
- консоль логов (уровни: Debug/Info/Warn/Error).
|
||||||
|
- При сворачивании окно уходит в трей.
|
||||||
|
|
||||||
|
## Примечания
|
||||||
|
|
||||||
|
- Для автообновления релиз должен содержать `.zip`-ассет с файлами приложения.
|
||||||
|
- Если `/releases/latest` недоступен, используется fallback на список релизов `/releases`.
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ git tag -m "Version v%VERSION%: %~1" -a v%VERSION%
|
|||||||
git push origin v%VERSION%
|
git push origin v%VERSION%
|
||||||
|
|
||||||
git push --tags
|
git push --tags
|
||||||
|
git push
|
||||||
GOTO End
|
GOTO End
|
||||||
pause
|
pause
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>7.3</LangVersion>
|
||||||
<RootNamespace>MonsterMonitor</RootNamespace>
|
<RootNamespace>MonsterMonitor</RootNamespace>
|
||||||
<AssemblyName>devenv</AssemblyName>
|
<AssemblyName>devenv</AssemblyName>
|
||||||
<AssemblyVersion>1.0.17</AssemblyVersion>
|
<AssemblyVersion>1.0.23</AssemblyVersion>
|
||||||
<Version>1.0.17</Version>
|
<Version>1.0.23</Version>
|
||||||
<FileVersion>1.0.17</FileVersion>
|
<FileVersion>1.0.23</FileVersion>
|
||||||
<InformationalVersion>1.0.17</InformationalVersion>
|
<InformationalVersion>1.0.23</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MonsterMonitor.UI;
|
using MonsterMonitor.UI;
|
||||||
|
|
||||||
@@ -6,9 +7,21 @@ namespace MonsterMonitor
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
private const string SingleInstanceMutexName = @"Global\MonsterMonitor_v2_SingleInstance";
|
||||||
|
private const string ActivateEventName = @"Global\MonsterMonitor_v2_Activate";
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
|
var createdNew = false;
|
||||||
|
using (var mutex = new Mutex(true, SingleInstanceMutexName, out createdNew))
|
||||||
|
{
|
||||||
|
if (!createdNew)
|
||||||
|
{
|
||||||
|
TrySignalExistingInstance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Application.ThreadException += (sender, args) =>
|
Application.ThreadException += (sender, args) =>
|
||||||
{
|
{
|
||||||
MessageBox.Show(
|
MessageBox.Show(
|
||||||
@@ -29,7 +42,38 @@ namespace MonsterMonitor
|
|||||||
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new MainForm());
|
using (var activateEvent = new EventWaitHandle(false, EventResetMode.AutoReset, ActivateEventName))
|
||||||
|
{
|
||||||
|
var form = new MainForm();
|
||||||
|
ThreadPool.RegisterWaitForSingleObject(
|
||||||
|
activateEvent,
|
||||||
|
(state, timedOut) =>
|
||||||
|
{
|
||||||
|
var mainForm = state as MainForm;
|
||||||
|
mainForm?.RestoreAndActivateFromExternalSignal();
|
||||||
|
},
|
||||||
|
form,
|
||||||
|
Timeout.Infinite,
|
||||||
|
false);
|
||||||
|
|
||||||
|
Application.Run(form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TrySignalExistingInstance()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var activateEvent = EventWaitHandle.OpenExisting(ActivateEventName))
|
||||||
|
{
|
||||||
|
activateEvent.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Если не удалось отправить сигнал, просто завершаем второй инстанс.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace MonsterMonitor.Services
|
|||||||
private readonly SsConfigService _ssConfig;
|
private readonly SsConfigService _ssConfig;
|
||||||
private ProcessMonitorService _processMonitor;
|
private ProcessMonitorService _processMonitor;
|
||||||
private SshTunnelService _sshTunnel;
|
private SshTunnelService _sshTunnel;
|
||||||
|
private IAuthMonitor _authMonitor;
|
||||||
|
|
||||||
public AppController(LogService log, PowerManagementService power)
|
public AppController(LogService log, PowerManagementService power)
|
||||||
{
|
{
|
||||||
@@ -25,10 +26,12 @@ namespace MonsterMonitor.Services
|
|||||||
_power.PreventSleep();
|
_power.PreventSleep();
|
||||||
_processMonitor = new ProcessMonitorService(_log);
|
_processMonitor = new ProcessMonitorService(_log);
|
||||||
_sshTunnel = new SshTunnelService(_log);
|
_sshTunnel = new SshTunnelService(_log);
|
||||||
|
_authMonitor = new AuthMonitor(settings);
|
||||||
|
|
||||||
_ssConfig.EnsureConfig(settings);
|
_ssConfig.EnsureConfig(settings);
|
||||||
_processMonitor.Start(settings.SsProcessPath, settings.SsArguments);
|
_processMonitor.Start(settings.SsProcessPath, settings.SsArguments);
|
||||||
_sshTunnel.Start(settings);
|
_sshTunnel.Start(settings);
|
||||||
|
_ = _authMonitor.StartMonitor();
|
||||||
|
|
||||||
_log.Info("Сервисы приложения запущены.");
|
_log.Info("Сервисы приложения запущены.");
|
||||||
}
|
}
|
||||||
@@ -38,6 +41,9 @@ namespace MonsterMonitor.Services
|
|||||||
_sshTunnel?.Dispose();
|
_sshTunnel?.Dispose();
|
||||||
_sshTunnel = null;
|
_sshTunnel = null;
|
||||||
|
|
||||||
|
_authMonitor?.StopMonitor();
|
||||||
|
_authMonitor = null;
|
||||||
|
|
||||||
_processMonitor?.Dispose();
|
_processMonitor?.Dispose();
|
||||||
_processMonitor = null;
|
_processMonitor = null;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MonsterMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
@@ -20,6 +21,8 @@ namespace MonsterMonitor.Services
|
|||||||
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
|
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
|
||||||
|
|
||||||
private readonly AppSettings _settings;
|
private readonly AppSettings _settings;
|
||||||
|
private CancellationTokenSource _monitorCancellation;
|
||||||
|
private Task _monitorTask;
|
||||||
|
|
||||||
public AuthMonitor(AppSettings settings)
|
public AuthMonitor(AppSettings settings)
|
||||||
{
|
{
|
||||||
@@ -36,12 +39,39 @@ namespace MonsterMonitor.Services
|
|||||||
|
|
||||||
public async Task StartMonitor()
|
public async Task StartMonitor()
|
||||||
{
|
{
|
||||||
_ = Task.Run(async () => await CheckProcess());
|
StopMonitor();
|
||||||
|
_monitorCancellation = new CancellationTokenSource();
|
||||||
|
_monitorTask = Task.Run(async () => await CheckProcess(_monitorCancellation.Token));
|
||||||
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CheckProcess()
|
public void StopMonitor()
|
||||||
{
|
{
|
||||||
while (true)
|
if (_monitorCancellation == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_monitorCancellation.Cancel();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_monitorTask?.Wait(TimeSpan.FromSeconds(1));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Ignore shutdown errors.
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_monitorCancellation.Dispose();
|
||||||
|
_monitorCancellation = null;
|
||||||
|
_monitorTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CheckProcess(CancellationToken token)
|
||||||
|
{
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -70,7 +100,14 @@ namespace MonsterMonitor.Services
|
|||||||
MessageBox.Show(ex.Message + ex.StackTrace);
|
MessageBox.Show(ex.Message + ex.StackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(3));
|
try
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(3), token);
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,5 +115,6 @@ namespace MonsterMonitor.Services
|
|||||||
public interface IAuthMonitor
|
public interface IAuthMonitor
|
||||||
{
|
{
|
||||||
Task StartMonitor();
|
Task StartMonitor();
|
||||||
|
void StopMonitor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,16 @@ namespace MonsterMonitor.Services
|
|||||||
public void Start(AppSettings settings)
|
public void Start(AppSettings settings)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
Connect();
|
try
|
||||||
|
{
|
||||||
|
Connect();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Error("Не удалось запустить SSH-туннель с первого раза: " + ex.Message);
|
||||||
|
ReconnectSoon();
|
||||||
|
}
|
||||||
|
|
||||||
StartMonitor();
|
StartMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using MonsterMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
using MonsterMonitor.Services;
|
using MonsterMonitor.Services;
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace MonsterMonitor.UI
|
namespace MonsterMonitor.UI
|
||||||
{
|
{
|
||||||
public sealed class MainForm : Form
|
public sealed class MainForm : Form
|
||||||
{
|
{
|
||||||
|
private const int EmGetFirstVisibleLine = 0x00CE;
|
||||||
|
private const int EmLineScroll = 0x00B6;
|
||||||
|
|
||||||
private readonly RichTextBox _console = new RichTextBox();
|
private readonly RichTextBox _console = new RichTextBox();
|
||||||
private readonly Button _btnSettings = new Button();
|
private readonly Button _btnSettings = new Button();
|
||||||
private readonly Button _btnExit = new Button();
|
private readonly Button _btnExit = new Button();
|
||||||
@@ -25,7 +30,7 @@ namespace MonsterMonitor.UI
|
|||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
Text = string.Format("Monster Monitor v{0}", Application.ProductVersion);
|
Text = string.Format("Monster Monitor v{0}", System.Windows.Forms.Application.ProductVersion);
|
||||||
Width = 980;
|
Width = 980;
|
||||||
Height = 620;
|
Height = 620;
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
@@ -135,6 +140,33 @@ namespace MonsterMonitor.UI
|
|||||||
Activate();
|
Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RestoreAndActivateFromExternalSignal()
|
||||||
|
{
|
||||||
|
if (InvokeRequired)
|
||||||
|
{
|
||||||
|
BeginInvoke(new Action(RestoreAndActivateFromExternalSignal));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Info("Получен сигнал активации от второго инстанса.");
|
||||||
|
|
||||||
|
if (!Visible)
|
||||||
|
{
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WindowState == FormWindowState.Minimized)
|
||||||
|
{
|
||||||
|
WindowState = FormWindowState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Небольшой трюк для надежного вывода окна на передний план.
|
||||||
|
TopMost = true;
|
||||||
|
Activate();
|
||||||
|
TopMost = false;
|
||||||
|
Focus();
|
||||||
|
}
|
||||||
|
|
||||||
private void ExitApplication()
|
private void ExitApplication()
|
||||||
{
|
{
|
||||||
_allowClose = true;
|
_allowClose = true;
|
||||||
@@ -159,20 +191,65 @@ namespace MonsterMonitor.UI
|
|||||||
|
|
||||||
private void AppendLog(LogEntry entry)
|
private void AppendLog(LogEntry entry)
|
||||||
{
|
{
|
||||||
|
if (_console.Text.Length > 100000)
|
||||||
|
{
|
||||||
|
_console.ResetText();
|
||||||
|
}
|
||||||
|
System.Windows.Forms.Application.DoEvents();
|
||||||
|
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action<LogEntry>(AppendLog), entry);
|
BeginInvoke(new Action<LogEntry>(AppendLog), entry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
System.Windows.Forms.Application.DoEvents();
|
||||||
|
|
||||||
|
var wasNearBottom = IsConsoleNearBottom();
|
||||||
|
var firstVisibleLineBeforeAppend = GetFirstVisibleLine(_console);
|
||||||
|
|
||||||
_console.SelectionStart = _console.TextLength;
|
_console.SelectionStart = _console.TextLength;
|
||||||
_console.SelectionLength = 0;
|
_console.SelectionLength = 0;
|
||||||
_console.SelectionColor = GetColor(entry.Level);
|
_console.SelectionColor = GetColor(entry.Level);
|
||||||
_console.AppendText($"[{entry.Timestamp:HH:mm:ss}] [{entry.Level}] {entry.Message}{Environment.NewLine}");
|
_console.AppendText($"[{entry.Timestamp:HH:mm:ss}] [{entry.Level}] {entry.Message}{Environment.NewLine}");
|
||||||
_console.SelectionColor = _console.ForeColor;
|
_console.SelectionColor = _console.ForeColor;
|
||||||
_console.ScrollToCaret();
|
System.Windows.Forms.Application.DoEvents();
|
||||||
|
|
||||||
|
if (wasNearBottom)
|
||||||
|
{
|
||||||
|
_console.ScrollToCaret();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
System.Windows.Forms.Application.DoEvents();
|
||||||
|
|
||||||
|
var firstVisibleLineAfterAppend = GetFirstVisibleLine(_console);
|
||||||
|
var linesToRestore = firstVisibleLineBeforeAppend - firstVisibleLineAfterAppend;
|
||||||
|
if (linesToRestore != 0)
|
||||||
|
{
|
||||||
|
SendMessage(_console.Handle, EmLineScroll, IntPtr.Zero, (IntPtr)linesToRestore);
|
||||||
|
}
|
||||||
|
System.Windows.Forms.Application.DoEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsConsoleNearBottom()
|
||||||
|
{
|
||||||
|
if (_console.TextLength == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bottomLeftPoint = new Point(1, Math.Max(0, _console.ClientSize.Height - 1));
|
||||||
|
var lastVisibleCharIndex = _console.GetCharIndexFromPosition(bottomLeftPoint);
|
||||||
|
return lastVisibleCharIndex >= _console.TextLength - 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetFirstVisibleLine(RichTextBox richTextBox)
|
||||||
|
{
|
||||||
|
return SendMessage(richTextBox.Handle, EmGetFirstVisibleLine, IntPtr.Zero, IntPtr.Zero).ToInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
|
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
private void ConfigureUpdateTimer()
|
private void ConfigureUpdateTimer()
|
||||||
{
|
{
|
||||||
_updateTimer.Interval = (int)TimeSpan.FromHours(1).TotalMilliseconds;
|
_updateTimer.Interval = (int)TimeSpan.FromHours(1).TotalMilliseconds;
|
||||||
|
|||||||
Reference in New Issue
Block a user