mirror of
https://git.adityakumar.xyz/monitor.git/
synced 2024-11-09 20:19:44 +00:00
initial commit
This commit is contained in:
commit
fde7ce49be
12 changed files with 2163 additions and 0 deletions
19
.direnv/bin/nix-direnv-reload
Executable file
19
.direnv/bin/nix-direnv-reload
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
if [[ ! -d "/home/user/dev/monitor" ]]; then
|
||||
echo "Cannot find source directory; Did you move it?"
|
||||
echo "(Looking for "/home/user/dev/monitor")"
|
||||
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# rebuild the cache forcefully
|
||||
_nix_direnv_force_reload=1 direnv exec "/home/user/dev/monitor" true
|
||||
|
||||
# Update the mtime for .envrc.
|
||||
# This will cause direnv to reload again - but without re-building.
|
||||
touch "/home/user/dev/monitor/.envrc"
|
||||
|
||||
# Also update the timestamp of whatever profile_rc we have.
|
||||
# This makes sure that we know we are up to date.
|
||||
touch -r "/home/user/dev/monitor/.envrc" "/home/user/dev/monitor/.direnv"/*.rc
|
1
.direnv/flake-inputs/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
Symbolic link
1
.direnv/flake-inputs/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
|
1
.direnv/flake-inputs/a0jhvi8hbgb016p73a2mpfna699387is-source
Symbolic link
1
.direnv/flake-inputs/a0jhvi8hbgb016p73a2mpfna699387is-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/a0jhvi8hbgb016p73a2mpfna699387is-source
|
1
.direnv/flake-inputs/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
Symbolic link
1
.direnv/flake-inputs/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
|
1
.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
Symbolic link
1
.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
|
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/75fzkiz8z119lqmay567h8x3xqdcrq6k-nix-shell-env
|
1997
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
1997
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
File diff suppressed because it is too large
Load diff
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use flake
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
result
|
61
flake.lock
Normal file
61
flake.lock
Normal file
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1725634671,
|
||||
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
47
flake.nix
Normal file
47
flake.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs = {
|
||||
url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
};
|
||||
flake-utils = {
|
||||
url = "github:numtide/flake-utils";
|
||||
};
|
||||
};
|
||||
outputs = { nixpkgs, flake-utils, self, ... }: flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
buildInputs = with pkgs; [
|
||||
(python3.withPackages(ps: with ps; [
|
||||
ipython
|
||||
requests
|
||||
]))
|
||||
];
|
||||
monitor = pkgs.stdenv.mkDerivation {
|
||||
name = "monitor";
|
||||
propagatedBuildInputs = buildInputs;
|
||||
dontUnpack = true;
|
||||
installPhase = "install -Dm755 ${./monitor.py} $out/bin/monitor";
|
||||
};
|
||||
in rec {
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = buildInputs;
|
||||
shellHook = "";
|
||||
};
|
||||
|
||||
systemd.services.monitor = {
|
||||
enable = true;
|
||||
description = "Monitor website uptime";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
unitConfig = {
|
||||
Type = "sinmple";
|
||||
};
|
||||
serviceConfig = {
|
||||
execStart = "${self.monitor}";
|
||||
};
|
||||
};
|
||||
packages.default = monitor;
|
||||
}
|
||||
);
|
||||
}
|
32
monitor.py
Normal file
32
monitor.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
|
||||
def check_website(url):
|
||||
try:
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
log_status(f"{url} is up and running.")
|
||||
else:
|
||||
log_status(f"{url} is down. Status code: {response.status_code}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
|
||||
def log_status(message):
|
||||
with open("/home/user/.logs/monitor.log", "a+") as log_file:
|
||||
log_file.write(f"{datetime.now()} - {message}\n")
|
||||
|
||||
|
||||
websites = [
|
||||
"https://adityakumar.xyz",
|
||||
"https://blog.adityakumar.xyz",
|
||||
"https://git.adityakumar.xyz",
|
||||
"https://forgejo.adityakumar.xyz",
|
||||
"https://dsa.adityakumar.xyz",
|
||||
]
|
||||
|
||||
for website in websites:
|
||||
check_website(website)
|
Loading…
Reference in a new issue