Skip to content

Instantly share code, notes, and snippets.

@aligoren
Created March 28, 2017 12:51
Show Gist options
  • Save aligoren/236b3e6cb343e78e9f8707e5ce38157c to your computer and use it in GitHub Desktop.
Save aligoren/236b3e6cb343e78e9f8707e5ce38157c to your computer and use it in GitHub Desktop.
👾 🍨 Diojarn, one of the simple and lightweight uptime service written in Go

Files

  • diojarn.go => Main file. It detects databases, checks URL is valid, make connection between other files.
  • database.go => Database file. It creates/deletes databases, adds columns to them.
  • ping.go => Ping file. It sends ping (ICMP) packet to target URL and returns datas like response time, response code, date, URL status (up or down)
  • server.go => Server file. It opens a web server in local network, displays websites and their data in their databases.

Algorithm

  • Main file (diojarn.go)

    • Read config file
    • Detect database in "databases/" or specified directory FOR LOOP
      • Compare database names with websites in config file
        • If all database names are equal, return True
        • Else, return False
      • Check return value
        • If False, create database with that name
        • Else, do nothing
    • Send website to Ping file (ping.go)
      • Check URL is valid
        • If True, do nothing
        • Else, return error
      • Send packet
        • Get response code, response time, date and URL status (up or down)
        • Send it to Main file (diojarn.go) with URL
    • Get values from Ping file (ping.go)
      • Send them to Database file (database.go)
        • Open database named URL
          • Add columns using returned values (response code, response time etc.)
  • Run server (server.go)

    • Get database from Main file (diojarn.go)
      • Send it to JavaScript chart script
    • Stay alive, loop baby.

What to use?

Ideas

  • Send SMS to user when returned error (like site is down or 404 code received) using Twilio API
  • Terminal chart? Maybe?
  • Send mails.. Yeah people still using them.
@saldanac
Copy link

nice work :) ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment