This project involves the development of a server monitoring and notification system with multiple components, including a server statistics collection service, message processing and anomaly detection service, and a SignalR event consumer service.
Develop a C# process that collects and publishes server statistics, specifically memory usage, available memory, and CPU usage.
- Collect server statistics (memory usage, available memory, and CPU usage) at regular intervals, specified by a configurable period
SamplingIntervalSeconds, using theSystem.Diagnosticsnamespace. - Encapsulate the collected statistics (memory usage, available memory, CPU usage, and timestamp) into a statistics object.
- Publish the statistics object to a message queue under the topic
ServerStatistics.<ServerIdentifier>, where<ServerIdentifier>is a configurable option. - Implement an abstraction for message queuing to ensure the code is not tightly coupled to RabbitMQ.
public class ServerStatistics
{
public double MemoryUsage { get; set; } // in MB
public double AvailableMemory { get; set; } // in MB
public double CpuUsage { get; set; }
public DateTime Timestamp { get; set; }
}Code Snippet: Server Statistics Configuration (appsettings.json)
{
"ServerStatisticsConfig": {
"SamplingIntervalSeconds": 60,
"ServerIdentifier": "linux1"
}
}Develop a C# process that receives server statistics from the message queue, persists the data to a MongoDB instance, and sends alerts if anomalies or high usage is detected.
Receive messages from the message queue with the topic ServerStatistics.* and deserialize them into objects containing memory usage, available memory, CPU usage, server's identifier, and timestamp. Persist the deserialized data to a MongoDB instance. Implement anomaly detection logic based on configurable threshold percentages specified in appsettings.json. Send an "Anomaly Alert" via SignalR if a sudden increase (anomaly) in memory usage or CPU usage is detected. Send a "High Usage Alert" via SignalR if the calculated memory usage percentage or CPU usage exceeds the specified "Usage Threshold". Implement abstractions for MongoDB and message queuing to ensure the code is not tightly coupled to specific implementations.
Equations for Alert Calculation For Anomaly Alert:
- Memory Usage Anomaly Alert:
if (CurrentMemoryUsage > (PreviousMemoryUsage * (1 + MemoryUsageAnomalyThresholdPercentage))) - CPU Usage Anomaly Alert:
if (CurrentCpuUsage > (PreviousCpuUsage * (1 + CpuUsageAnomalyThresholdPercentage)))For High Usage Alert: - Memory High Usage Alert:
if ((CurrentMemoryUsage / (CurrentMemoryUsage + CurrentAvailableMemory)) > MemoryUsageThresholdPercentage) - CPU High Usage Alert:
if (CurrentCpuUsage > CpuUsageThresholdPercentage)
Code Snippet: Anomaly Detection Service Configuration (appsettings.json)
{
"AnomalyDetectionConfig": {
"MemoryUsageAnomalyThresholdPercentage": 0.4,
"CpuUsageAnomalyThresholdPercentage": 0.5,
"MemoryUsageThresholdPercentage": 0.8,
"CpuUsageThresholdPercentage": 0.9
},
"SignalRConfig": {
"SignalRUrl": "<YourSignalRHubURL>"
}
}Develop a C# process that connects to a SignalR hub and prints received events to the console.
Establish a connection to a SignalR hub. Subscribe to events and print them to the console as they are received.
Code Snippet: SignalR Event Consumer Service Configuration (appsettings.json)
{
"SignalRConfig": {
"SignalRUrl": "<YourSignalRHubURL>"
}
}Develop a reusable class library for interacting with RabbitMQ, thereby abstracting the RabbitMQ client and making it easier to switch to a different message queuing system in the future.
Implement a class for publishing messages to a RabbitMQ exchange. Implement a class for consuming messages from a RabbitMQ queue. Both classes should utilize an interface, making the library extensible and not tightly coupled to RabbitMQ.


