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.

232 lines
7.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. * 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. `REGISTRATION_OPEN` controls whether site visitors can create new accounts.
  56. Set it to `False` if you are setting up a private healthchecks instance, but
  57. it needs to be publicly accessible (so, for example, your cloud services
  58. can send pings).
  59. If you close new user registration, you can still selectively invite users
  60. to your team account.
  61. ## Database Configuration
  62. Database configuration is stored in `hc/settings.py` and can be overriden
  63. in `hc/local_settings.py`. The default database engine is SQLite. To use
  64. PostgreSQL, create `hc/local_settings.py` if it does not exist, and put the
  65. following in it, changing it as neccessary:
  66. DATABASES = {
  67. 'default': {
  68. 'ENGINE': 'django.db.backends.postgresql',
  69. 'NAME': 'your-database-name-here',
  70. 'USER': 'your-database-user-here',
  71. 'PASSWORD': 'your-database-password-here',
  72. 'TEST': {'CHARSET': 'UTF8'}
  73. }
  74. }
  75. For MySQL:
  76. DATABASES = {
  77. 'default': {
  78. 'ENGINE': 'django.db.backends.mysql',
  79. 'NAME': 'your-database-name-here',
  80. 'USER': 'your-database-user-here',
  81. 'PASSWORD': 'your-database-password-here',
  82. 'TEST': {'CHARSET': 'UTF8'}
  83. }
  84. }
  85. You can also use `hc/local_settings.py` to read database
  86. configuration from environment variables like so:
  87. import os
  88. DATABASES = {
  89. 'default': {
  90. 'ENGINE': os.environ['DB_ENGINE'],
  91. 'NAME': os.environ['DB_NAME'],
  92. 'USER': os.environ['DB_USER'],
  93. 'PASSWORD': os.environ['DB_PASSWORD'],
  94. 'TEST': {'CHARSET': 'UTF8'}
  95. }
  96. }
  97. ## Sending Emails
  98. healthchecks must be able to send email messages, so it can send out login
  99. links and alerts to users. Put your SMTP server configuration in
  100. `hc/local_settings.py` like so:
  101. EMAIL_HOST = "your-smtp-server-here.com"
  102. EMAIL_PORT = 587
  103. EMAIL_HOST_USER = "username"
  104. EMAIL_HOST_PASSWORD = "password"
  105. EMAIL_USE_TLS = True
  106. For more information, have a look at Django documentation,
  107. [Sending Email](https://docs.djangoproject.com/en/1.10/topics/email/) section.
  108. ## Sending Status Notifications
  109. healtchecks comes with a `sendalerts` management command, which continuously
  110. polls database for any checks changing state, and sends out notifications as
  111. needed. Within an activated virtualenv, you can manually run
  112. the `sendalerts` command like so:
  113. $ ./manage.py sendalerts
  114. In a production setup, you will want to run this command from a process
  115. manager like [supervisor](http://supervisord.org/) or systemd.
  116. ## Database Cleanup
  117. With time and use the healthchecks database will grow in size. You may
  118. decide to prune old data: inactive user accounts, old checks not assigned
  119. to users, records of outgoing email messages and records of received pings.
  120. There are separate Django management commands for each task:
  121. * Remove old records from `api_ping` table. For each check, keep 100 most
  122. recent pings:
  123. ````
  124. $ ./manage.py prunepings
  125. ````
  126. * Remove checks older than 2 hours that are not assigned to users. Such
  127. checks are by-products of random visitors and robots loading the welcome
  128. page and never setting up an account:
  129. ```
  130. $ ./manage.py prunechecks
  131. ```
  132. * Remove records of sent email messages older than 7 days.
  133. ````
  134. $ ./manage.py pruneemails
  135. ````
  136. * Remove old records of sent notifications. For each check, remove
  137. notifications that are older than the oldest stored ping for same check.
  138. ````
  139. $ ./manage.py prunenotifications
  140. ````
  141. * Remove user accounts that match either of these conditions:
  142. * Account was created more than 6 months ago, and user has never logged in.
  143. These can happen when user enters invalid email address when signing up.
  144. * Last login was more than 6 months ago, and the account has no checks.
  145. Assume the user doesn't intend to use the account any more and would
  146. probably *want* it removed.
  147. ```
  148. $ ./manage.py pruneusers
  149. ```
  150. When you first try these commands on your data, it is a good idea to
  151. test them on a copy of your database, not on the live database right away.
  152. In a production setup, you should also have regular, automated database
  153. backups set up.
  154. ## Integrations
  155. ### Pushover
  156. To enable Pushover integration, you will need to:
  157. * register a new application on https://pushover.net/apps/build
  158. * enable subscriptions in your application and make sure to enable the URL
  159. subscription type
  160. * add the application token and subscription URL to `hc/local_settings.py`, as
  161. `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL`