Hello,

I am a beginner to ASP.NET. I need some directions for this task.

Information about task:

Phase 1 : Assume Server whose health to monitor is GEMINI.
Create two unattended (non UI) Windows Services (or Windows exe) written in C#.
Every specific “duration” the windows services will be invoked.Use app.config file to store this duration value.
Should check the server (GEMINI) if it is up or down.
Check the following various applications under following broad classifications in the server.
Server
IIS
SQL Server
Windows Service ( control panel --> under services u see services running)
Windows Exe
Web Service

If the application is down and the server is down it has to log data into the sql server database.

Thanks in advance!

Ramito

Dani AI

Generated

The project is a classic monitor/agent pattern: two headless Windows services, each scheduled by a configurable interval, iterate the systems defined in your database, perform type-specific health checks, log results and trigger alerts on failures. provided the requirements and correctly highlighted the first design question — what counts as “UP”? Decide per-system checks (ICMP/TCP for host, HTTP for web apps, a simple query for databases, ServiceController or WMI for Windows services, process/WMI for executables, endpoint calls for web services) and treat each type accordingly.

Implementation notes and hardening: run a single worker loop (System.Threading.Timer or an async Task loop) and prevent overlapping runs with a simple in-memory guard or named Mutex. Read interval from configuration and validate it. Execute individual checks in parallel but limit concurrency with SemaphoreSlim to avoid overloading network or the monitored hosts. Always use timeouts and bounded retries (exponential backoff) for flaky networks. For remote Windows-service/process checks prefer WMI or a small remote agent if permissions/firewall prevent direct queries; for local checks use ServiceController.

Logging and DB behavior: log every attempt but keep a “last known state” per monitored item so alerts are sent on state changes or after N consecutive failures (avoids alert storms). Store timestamps in UTC, use parameterized queries or a lightweight ORM, and queue DB writes (producer/consumer) so slow DB I/O doesn’t block checks. Plan indexes and a retention/purge policy to keep the logs manageable.

Alerting and operational tips: send SMS through a reliable gateway with retry/throttle/dedup rules; encrypt sensitive config (DPAPI or protected config sections); run the service with least privilege and test as a console app during development; write clear EventLog entries for install/runtime errors; document required ports and permissions (WMI/RPC/SQL). These practices make the monitor resilient and easier to operate.

Example quick-check snippets:

using System.Net.NetworkInformation;

bool PingHost(string ip, int timeoutMs = 1000)
{
    using (var p = new Ping())
    {
        var r = p.Send(ip, timeoutMs);
        return r != null && r.Status == IPStatus.Success;
    }
}
using System.Net.Sockets;

bool TcpOpen(string host, int port, int timeoutMs = 2000)
{
    using (var c = new TcpClient())
    {
        var t = c.ConnectAsync(host, port);
        return t.Wait(timeoutMs) && c.Connected;
    }
}

Recommended Answers

All 3 Replies

Welcome to daniweb! Please direct windows form application and service application questions to the C# forum. The ASP.NET forum is reserved for web application related questions.

What is your definition of a server being "UP"? A ping response, a successful test to a website, a connection to some service hosted on it...? If my webserver responds to a ping but IIS is crashed I consider the server down.

To see if a service is running you need to add a reference to System.ServiceProcess and use the following code:

using System.ServiceProcess;

namespace daniweb
{
  public static class ServiceStuff
  {
    public static bool IsServiceRunning(string ServiceName)
    {
      try
      {
        using (ServiceController ctrl = new ServiceController(ServiceName))
        {
          return (ctrl.Status == ServiceControllerStatus.Running);
        }
      }
      catch
      {
        return false;
      }
    }
  }
}

I re-read your post and maybe you weren't clear.

I am a beginner to ASP.NET. I need some directions for this task.

Create two unattended (non UI) Windows Services (or Windows exe) written in C#.

ASP.NET is not going to be an unattended Service or Exe. Perhaps you chose the wrong technology (but the right language!) or you did not explain yourself clearly

Well sorry I didnt mention the things clearly.
Well this is what my boss gave me..

PHASE I

Create two unattended (non UI) Windows Services (or Windows exe) written in C#.Net that checks Servers and Applications/Services health (make sure they are up and running).

General Requirements
1. Two windows services to build: one will run on IT Server (Gemini) and the other will run on Rackspace server.

2. Every specific “duration” the windows services will be invoked. Make sure that this duration is configurable.
Spec:
a. Use app.config file to store this duration value. The service will look at this value to determine the length of intermittent duration.

3. Log each check to a database table which includes the time, the “system” being checked and the health of the “system” (either down or up).
a. Create a few tables in HealthMonitor DB:
i. HST_HEALTHSTATUS
Fields:
HST_ID, smallint, PK, identity(1,1)
HST_Name, varchar(50)

Values:
HST_ID=1, HST_Name=Normal
HST_ID=2, HST_Name=Down
ii. STP_SYSTEMTYPE
Fields:
STP_ID, smallint, PK, identity(1,1)
STP_Name, varchar(50)

Values:
STP_ID=1, STP_Name=Server
STP_ID=2, STP_Name=IIS
STP_ID=3, STP_Name=SQL Server
STP_ID=4, STP_Name=Windows Service
STP_ID=5, STP_Name=Windows Exe
STP_ID=6, STP_Name=Web Service
iii. SMH_SYSTEMHEALTH
Fields:
SMH_ID, smallint, PK, identity(1,1)
SMH_Name, varchar(50)
SMH_IPAddress, varchar(50)
SMH_ProcessName, varchar(50)
STP_ID, smallint, FK
HST_ID, smallint, FK
MSL_ID, smallint, FK
SMH_Comment, varchar(500)
SMH_LastDateTimeHealthCheck, datetime

Values:
SMH_ID=1, SMH_Name=Rackspace, SMH_IPAddress=, SMH_ProcessName=None, STP_ID=1, HST_ID=[dynamic],MSL_ID=1, SMH_Comment=[dynamic], SMH_LastDateTimeHealthCheck=[dynamic]

SMH_ID=2, SMH_Name=Gemini, SMH_IPAddress=, SMH_ProcessName=None, STP_ID=1, HST_ID=[dynamic],MSL_ID=2, SMH_Comment=[dynamic], SMH_LastDateTimeHealthCheck=[dynamic]

iv. MSL_MONITORSERVICELOCATION
Fields:
MSL_ID, smallint, PK, identity(1,1)
MSL_Name, varchar(50)
Values:
MSL_ID=1, MSL_Name=Gemini
MSL_ID=2, MSL_Name=Rackspace
v. HMG_HEALTHMONITORLOG
Fields:
HMG_ID, bigint, PK, identity(1,1)
SMH_ID, smallint, FK
HST_ID, smallint, FK
HMG_DateTime, datetime
HMG_Comment, varchar(500)
vi. SAM_SYSTEMADMIN
Fields:
SAM_ID, smallint, PK, identity(1,1)
SAM _EmailAddress, varchar(100)
SAM _MobilePhone, varchar(30)
SAM _Status

4. The windows services will need to loop through all the systems (records) stored in SMH_SYSTEMHEALTH table.
a. The windows service that is running on Rackspace will only loop through systems that are specified as MSL_ID = 2. The windows service that is running on Gemini will only loop through systems that are specified as MSL_ID = 1.
b. Based on its STP_ID, the service will need to check for the health of the system appropriately. For example if STP_ID = 1, then do the ping mechanism to check the health of the system. If the STP_ID = 2, then checks the IIS windows service if it is running. If the STP_ID = 3, then attempts to connect to a database .. etc..
c. For each health check attempts, add a record in HMG table and update the HST_ID and SMH_LastDateTimeHealthCheck fields in SMH table with the appropriate values (insert comment if necessary).
d. For each failure (down) system, SMS text all users that are stored in the ADM table with status = 1.


Let me if it is clear now. Sorry for posting it in ASP.NET forum I should have posted in C#.

I will post it in C# for anything more new doubts.

Thanks in advance.

Ramito

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.