You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
7.6 KiB

10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
  1. # healthchecks
  2. [![Build Status](https://travis-ci.org/healthchecks/healthchecks.svg?branch=master)](https://travis-ci.org/healthchecks/healthchecks)
  3. [![Coverage Status](https://coveralls.io/repos/healthchecks/healthchecks/badge.svg?branch=master&service=github)](https://coveralls.io/github/healthchecks/healthchecks?branch=master)
  4. ![Screenshot of Welcome page](/stuff/screenshots/welcome.png?raw=true "Welcome Page")
  5. ![Screenshot of My Checks page](/stuff/screenshots/my_checks.png?raw=true "My Checks Page")
  6. ![Screenshot of Period/Grace dialog](/stuff/screenshots/period_grace.png?raw=true "Period/Grace Dialog")
  7. ![Screenshot of Channels page](/stuff/screenshots/channels.png?raw=true "Channels Page")
  8. healthchecks is a watchdog for your cron jobs. It's a web server that listens for pings from your cron jobs, plus a web interface.
  9. It is live here: [http://healthchecks.io/](http://healthchecks.io/)
  10. The building blocks are:
  11. * Python 2 or Python 3
  12. * Django 1.9
  13. * PostgreSQL or MySQL
  14. ## Setting Up for Development
  15. These are instructions for setting up HealthChecks Django app
  16. in development environment.
  17. * prepare directory for project code and virtualenv:
  18. $ mkdir -p ~/webapps
  19. $ cd ~/webapps
  20. * prepare virtual environment
  21. (with virtualenv you get pip, we'll use it soon to install requirements):
  22. $ virtualenv --python=python3 hc-venv
  23. $ source hc-venv/bin/activate
  24. * check out project code:
  25. $ git clone https://github.com/healthchecks/healthchecks.git
  26. * install requirements (Django, ...) into virtualenv:
  27. $ pip install -r healthchecks/requirements.txt
  28. * healthchecks is configured to use a SQLite database by default. To use
  29. PostgreSQL or MySQL database, create and edit `hc/local_settings.py` file.
  30. There is a template you can copy and edit as needed:
  31. $ cd ~/webapps/healthchecks
  32. $ cp hc/local_settings.py.example hc/local_settings.py
  33. * create database tables and the superuser account:
  34. $ cd ~/webapps/healthchecks
  35. $ ./manage.py migrate
  36. $ ./manage.py createsuperuser
  37. * run development server:
  38. $ ./manage.py runserver
  39. The site should now be running at `http://localhost:8080`
  40. To log into Django administration site as a super user,
  41. visit `http://localhost:8080/admin`
  42. ## Configuration
  43. Site configuration is kept in `hc/settings.py`. Additional configuration
  44. is loaded from `hc/local_settings.py` file, if it exists. You
  45. can create this file (should be right next to `settings.py` in the filesystem)
  46. and override settings as needed.
  47. Some useful settings keys to override are:
  48. `SITE_ROOT` is used to build fully qualified URLs for pings, and for use in
  49. emails and notifications. Example:
  50. SITE_ROOT = "https://my-monitoring-project.com"
  51. `SITE_NAME` has the default value of "healthchecks.io" and is used throughout
  52. the templates. Replace it with your own name to personalize your installation.
  53. Example:
  54. SITE_NAME = "My Monitoring Project"
  55. ## Database Configuration
  56. Database configuration is stored in `hc/settings.py` and can be overriden
  57. in `hc/local_settings.py`. The default database engine is SQLite. To use
  58. PostgreSQL, create `hc/local_settings.py` if it does not exist, and put the
  59. following in it, changing it as neccessary:
  60. DATABASES = {
  61. 'default': {
  62. 'ENGINE': 'django.db.backends.postgresql',
  63. 'NAME': 'your-database-name-here',
  64. 'USER': 'your-database-user-here',
  65. 'PASSWORD': 'your-database-password-here',
  66. 'TEST': {'CHARSET': 'UTF8'}
  67. }
  68. }
  69. For MySQL:
  70. DATABASES = {
  71. 'default': {
  72. 'ENGINE': 'django.db.backends.mysql',
  73. 'NAME': 'your-database-name-here',
  74. 'USER': 'your-database-user-here',
  75. 'PASSWORD': 'your-database-password-here',
  76. 'TEST': {'CHARSET': 'UTF8'}
  77. }
  78. }
  79. You can also use `hc/local_settings.py` to read database
  80. configuration from environment variables like so:
  81. import os
  82. DATABASES = {
  83. 'default': {
  84. 'ENGINE': os.env['DB_ENGINE'],
  85. 'NAME': os.env['DB_NAME'],
  86. 'USER': os.env['DB_USER'],
  87. 'PASSWORD': os.env['DB_PASSWORD'],
  88. 'TEST': {'CHARSET': 'UTF8'}
  89. }
  90. }
  91. ## Sending Emails
  92. healthchecks must be able to send email messages, so it can send out login
  93. links and alerts to users. You will likely need to tweak email configuration
  94. before emails will work. healthchecks uses
  95. [djmail](http://bameda.github.io/djmail/) for sending emails asynchronously.
  96. Djmail is a BSD Licensed, simple and nonobstructive django email middleware.
  97. It can be configured to use any regular Django email backend behind the
  98. scenes. For example, the healthchecks.io site uses
  99. [django-ses-backend](https://github.com/piotrbulinski/django-ses-backend/)
  100. and the email configuration in `hc/local_settings.py` looks as follows:
  101. DEFAULT_FROM_EMAIL = '[email protected]'
  102. DJMAIL_REAL_BACKEND = 'django_ses_backend.SESBackend'
  103. AWS_SES_ACCESS_KEY_ID = "put-access-key-here"
  104. AWS_SES_SECRET_ACCESS_KEY = "put-secret-access-key-here"
  105. AWS_SES_REGION_NAME = 'us-east-1'
  106. AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
  107. ## Sending Status Notifications
  108. healtchecks comes with a `sendalerts` management command, which continuously
  109. polls database for any checks changing state, and sends out notifications as
  110. needed. Within an activated virtualenv, you can manually run
  111. the `sendalerts` command like so:
  112. $ ./manage.py sendalerts
  113. In a production setup, you will want to run this command from a process
  114. manager like [supervisor](http://supervisord.org/) or systemd.
  115. ## Database Cleanup
  116. With time and use the healthchecks database will grow in size. You may
  117. decide to prune old data: inactive user accounts, old checks not assigned
  118. to users, records of outgoing email messages and records of received pings.
  119. There are separate Django management commands for each task:
  120. * Remove old records from `api_ping` table. For each check, keep 100 most
  121. recent pings:
  122. ````
  123. $ ./manage.py prunepings
  124. ````
  125. * Remove checks older than 2 hours that are not assigned to users. Such
  126. checks are by-products of random visitors and robots loading the welcome
  127. page and never setting up an account:
  128. ```
  129. $ ./manage.py prunechecks
  130. ```
  131. * Remove records of sent email messages older than 7 days.
  132. ````
  133. $ ./manage.py pruneemails
  134. ````
  135. * Remove old records of sent notifications. For each check, remove
  136. notifications that are older than the oldest stored ping for same check.
  137. ````
  138. $ ./manage.py prunenotifications
  139. ````
  140. * Remove user accounts that match either of these conditions:
  141. * Account was created more than 6 months ago, and user has never logged in.
  142. These can happen when user enters invalid email address when signing up.
  143. * Last login was more than 6 months ago, and the account has no checks.
  144. Assume the user doesn't intend to use the account any more and would
  145. probably *want* it removed.
  146. ```
  147. $ ./manage.py pruneusers
  148. ```
  149. When you first try these commands on your data, it is a good idea to
  150. test them on a copy of your database, not on the live database right away.
  151. In a production setup, you should also have regular, automated database
  152. backups set up.
  153. ## Integrations
  154. ### Pushover
  155. To enable Pushover integration, you will need to:
  156. * register a new application on https://pushover.net/apps/build
  157. * enable subscriptions in your application and make sure to enable the URL
  158. subscription type
  159. * add the application token and subscription URL to `hc/local_settings.py`, as
  160. `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL`