Skip to content

Commit

Permalink
Add Initial Monitor Check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukhendu2002 committed Mar 16, 2024
1 parent 228b1c0 commit 101d300
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
8 changes: 5 additions & 3 deletions client/src/components/SiteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ interface CardProps {
id: string;
name: string;
url: string;
uptime: number;
responseTime: number;
}

const SiteCard = ({ id, name, url }: CardProps) => {
const SiteCard = ({ id, name, url, uptime, responseTime }: CardProps) => {
return (
<Card className="w-64 h-50">
<CardHeader className="flex flex-col">
Expand All @@ -27,11 +29,11 @@ const SiteCard = ({ id, name, url }: CardProps) => {
<CardContent>
<div className="flex justify-between">
<p>Uptime</p>
<p>100%</p>
<p>{uptime ? 100 : 0}%</p>
</div>
<div className="flex justify-between">
<p>Response Time</p>
<p>0.2s</p>
<p>{responseTime}ms</p>
</div>
</CardContent>
<CardFooter className="flex justify-end">
Expand Down
10 changes: 10 additions & 0 deletions client/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ const Dashboard: React.FC<AuthNavProps> = ({ onLogout }) => {
id={site._id.toString()}
name={site.name}
url={site.url}
// uptime = last monitoringHistory.uptime
uptime={
site?.monitoringHistory[site?.monitoringHistory.length - 1]
?.uptime
}
responseTime={
site?.monitoringHistory[site?.monitoringHistory.length - 1]
?.responseTime
}
/>
))
)}
Expand Down Expand Up @@ -300,6 +309,7 @@ const Dashboard: React.FC<AuthNavProps> = ({ onLogout }) => {
<Label htmlFor="performance">Performance</Label>
<Checkbox
id="performance"
disabled
checked={monitoringCheck.performance}
onCheckedChange={() =>
setMonitoringCheck({
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Landing = () => {
<section className="space-y-4 pb-8 pt-2 md:pb-12 md:pt-10 lg:py-32">
<div className="container flex max-w-[64rem] flex-col items-center gap-4 text-center">
<Link
to="#"
to="https://twitter.com/Sukhendu_2002"
className="rounded-2xl bg-muted px-4 py-1.5 text-sm font-medium"
target="_blank"
>
Expand All @@ -31,14 +31,14 @@ const Landing = () => {
<Link to="/signup" className={cn(buttonVariants({ size: "lg" }))}>
Get Started for Free
</Link>
<a
{/* <a
href="#"
target="_blank"
rel="noreferrer"
className={cn(buttonVariants({ variant: "outline", size: "lg" }))}
>
GitHub
</a>
</a> */}
</div>
</div>
</section>
Expand Down
3 changes: 3 additions & 0 deletions server/src/controllers/website.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Website = require("../models/website.model");
const checkSSL = require("../services/monitoring/ssl");
const { getDomainInfo } = require("../services/monitoring/domain");
const monitorWebsites = require("../services/monitoring.service");

const createWebsite = async (req, res) => {
const { name, url, monitoringSchedule, monitoringSettings, notifications } =
Expand All @@ -23,6 +24,8 @@ const createWebsite = async (req, res) => {
notifications,
});
await website.save();
await monitorWebsites([website]);

res.status(201).json({
success: true,
data: website,
Expand Down
16 changes: 3 additions & 13 deletions server/src/services/monitoring.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const monitorWebsites = async (websites) => {
responseTime = 0;
}
}

if (website.info.ssl.valid === false) {
const sslCheck = await checkSSL(website.url);
ssl = sslCheck;
Expand All @@ -58,11 +57,10 @@ const monitorWebsites = async (websites) => {
});
website.info.ssl = ssl;
await website.save();

if (
responseTime > website.monitoringSettings.alertThresholds.responseTime
) {
if (notifications.email) {
if (notifications?.email) {
const user = await User.findById(website.owner);
sendEmailAlert(
user.email,
Expand All @@ -73,11 +71,7 @@ const monitorWebsites = async (websites) => {
website.name
} is slow. Response time: ${responseTime}ms</p>
<p>Current time: ${new Date()}</p>
<p>
Unsubscribe from these notifications <a href="${
process.env.CLIENT_URL
}/unsubscribe/${user._id}">here</a>
</p>`
`
);
console.log(
`Website ${website.name} is slow. Sending notifications to owner.`
Expand All @@ -92,11 +86,7 @@ const monitorWebsites = async (websites) => {
` <h1>Hello ${user.name}</h1>
<p>Your website ${website.name} is down.</p>
<p>Current time: ${new Date()}</p>
<p>
Unsubscribe from these notifications <a href="${
process.env.CLIENT_URL
}/unsubscribe/${user._id}">here</a>
</p>`
`
);
console.log(
`Website ${website.name} is down. Sending notifications to owner.`
Expand Down

0 comments on commit 101d300

Please sign in to comment.