monitor_website
Do you need to monitor your website ? Of course you could pay some services for that but you can also do it yourself. Maybe you tried doing yourself with Autoit but found it was hard. In Rebol it’s easy and it’s a great example of its powerfull concision in expressivity and networking. In fact I didn’t write these examples below myself but found them on Dr. Dobbs:

  • Create a network agent that checks your website is up every 10 minutes
  • Create a network agent that checks a website has changed every hour

Source codes are reproduced below with little adaptations:

1. How to create a network agent that checks your website is up every 10 minutes


Rebol[
  title: "checks your website is up every 10 minutes"
  author: "http://www.ddj.com/184404172"
  version: 1.0.0
]

str-url: ask "url to monitor? "
url: to-url str-url
str-email: ask "email to notify? "
email: to-email str-email

forever [
   if error? try [
      read url
   ] [
       ;pre-requisite: you must setup your email see here
       send email "Site is down."
   ]
   wait 0:10
]

If you want to measure how long your site takes to load, replace the single instruction


read url

by these instructions:


      start: now/time
      read url
      print now/time - start

2. How to create a network agent that checks a website has changed every hour


Rebol[
  title: "checks a website has changed every hour"
  author: "http://www.ddj.com/184404172"
  version: 1.0.0
]

str-url: ask "url to monitor? "
url: to-url str-url
str-email: ask "email to notify? "
email: to-email str-email
old-sum: checksum read url

until [
   wait 1:00
   old-sum  checksum read url
]
send email "Web site changed!"

3. To monitor several websites


REBOL [
    Title: "Time Web Pages"
    Date: 18-Dec-1997
    File: %timewebs.r
    Source: rebol.org
    Purpose: {Time how long it takes to get each of the web pages listed in a block.}
    Comment: {
        Although REBOL stores time to the 1000th of a second,
        most systems don't return this information... We will
        find a way to add it in the future.
    }
    library: [
        level: 'beginner
        platform: 'all
        type: 'tool
        domain: [web other-net DB]
        tested-under: none
        support: none
        license: none
        see-also: none
    ]
    Version: 1.0.0
    Author: "Anonymous"
]

sites: [
    http://www.pacific.net
    http://www.rebol.com
    http://www.sassenrath.com
    http://www.cucug.org
    http://www.cnn.com
    http://www.cnet.com
]

times: copy [] ; store times and sizes in this block

;Gather timings:

foreach site sites [
    start: now/time
    size: length? read site
    insert tail times now/time - start
    insert tail times size
]

;Print time, site, and home page size for each site:

foreach site sites [
    print [first times site second times]
    times: skip times 2
]

Bookmark and Share

Recent Articles