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.

200 lines
6.5 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. * make sure PostgreSQL server is installed and running, create
  29. database "hc":
  30. $ psql --user postgres
  31. postgres=# create database hc;
  32. * create database tables, triggers, superuser:
  33. $ cd ~/webapps/healthchecks
  34. $ ./manage.py migrate
  35. $ ./manage.py ensuretriggers
  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. ## Database Configuration
  43. Database configuration is stored in `hc/settings.py` and can be overriden
  44. in `hc/local_settings.py`. The default database engine is SQLite. To use
  45. PostgreSQL, create `hc/local_settings.py` if it does not exist, and put the
  46. following in it, changing it as neccessary:
  47. DATABASES = {
  48. 'default': {
  49. 'ENGINE': 'django.db.backends.postgresql',
  50. 'NAME': 'your-database-name-here',
  51. 'USER': 'your-database-user-here',
  52. 'PASSWORD': 'your-database-password-here',
  53. 'TEST': {'CHARSET': 'UTF8'}
  54. }
  55. }
  56. For MySQL:
  57. DATABASES = {
  58. 'default': {
  59. 'ENGINE': 'django.db.backends.mysql',
  60. 'NAME': 'your-database-name-here',
  61. 'USER': 'your-database-user-here',
  62. 'PASSWORD': 'your-database-password-here',
  63. 'TEST': {'CHARSET': 'UTF8'}
  64. }
  65. }
  66. You can also use `hc/local_settings.py` to read database
  67. configuration from environment variables like so:
  68. import os
  69. DATABASES = {
  70. 'default': {
  71. 'ENGINE': os.env['DB_ENGINE'],
  72. 'NAME': os.env['DB_NAME'],
  73. 'USER': os.env['DB_USER'],
  74. 'PASSWORD': os.env['DB_PASSWORD'],
  75. 'TEST': {'CHARSET': 'UTF8'}
  76. }
  77. }
  78. ## Sending Emails
  79. healthchecks must be able to send email messages, so it can send out login
  80. links and alerts to users. You will likely need to tweak email configuration
  81. before emails will work. healthchecks uses
  82. [djmail](http://bameda.github.io/djmail/) for sending emails asynchronously.
  83. Djmail is a BSD Licensed, simple and nonobstructive django email middleware.
  84. It can be configured to use any regular Django email backend behind the
  85. scenes. For example, the healthchecks.io site uses
  86. [django-ses-backend](https://github.com/piotrbulinski/django-ses-backend/)
  87. and the email configuration in `hc/local_settings.py` looks as follows:
  88. DJMAIL_REAL_BACKEND = 'django_ses_backend.SESBackend'
  89. AWS_SES_ACCESS_KEY_ID = "put-access-key-here"
  90. AWS_SES_SECRET_ACCESS_KEY = "put-secret-access-key-here"
  91. AWS_SES_REGION_NAME = 'us-east-1'
  92. AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
  93. ## Sending Status Notifications
  94. healtchecks comes with a `sendalerts` management command, which continuously
  95. polls database for any checks changing state, and sends out notifications as
  96. needed. Within an activated virtualenv, you can manually run
  97. the `sendalerts` command like so:
  98. $ ./manage.py sendalerts
  99. In a production setup, you will want to run this command from a process
  100. manager like [supervisor](http://supervisord.org/) or systemd.
  101. ## Database Cleanup
  102. With time and use the healthchecks database will grow in size. You may
  103. decide to prune old data: inactive user accounts, old checks not assigned
  104. to users, records of outgoing email messages and records of received pings.
  105. There are separate Django management commands for each task:
  106. * Remove old records from `api_ping` table. For each check, keep 100 most
  107. recent pings:
  108. ````
  109. $ ./manage.py prunepings
  110. ````
  111. * Remove checks older than 2 hours that are not assigned to users. Such
  112. checks are by-products of random visitors and robots loading the welcome
  113. page and never setting up an account:
  114. ```
  115. $ ./manage.py prunechecks
  116. ```
  117. * Remove records of sent email messages older than 7 days.
  118. ````
  119. $ ./manage.py pruneemails
  120. ````
  121. * Remove user accounts that match either of these conditions:
  122. * Account was created more than a month ago, and user has never logged in.
  123. These can happen when user enters invalid email address when signing up.
  124. * Last login was more than a month ago, and the account has no checks.
  125. Assume the user doesn't intend to use the account any more and would
  126. probably *want* it removed.
  127. ```
  128. $ ./manage.py pruneusers
  129. ```
  130. When you first try these commands on your data, it is a good idea to
  131. test them on a copy of your database, not on the live database right away.
  132. In a production setup, you should also have regular, automated database
  133. backups set up.
  134. ## Integrations
  135. ### Pushover
  136. To enable Pushover integration, you will need to:
  137. * register a new application on https://pushover.net/apps/build
  138. * enable subscriptions in your application and make sure to enable the URL
  139. subscription type
  140. * add the application token and subscription URL to `hc/local_settings.py`, as
  141. `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL`