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.

248 lines
8.2 KiB

10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
8 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](/static/img/screenshots/welcome.png?raw=true "Welcome Page")
  5. ![Screenshot of My Checks page](/static/img/my_checks.png?raw=true "My Checks Page")
  6. ![Screenshot of Period/Grace dialog](/static/img/period_grace.png?raw=true "Period/Grace Dialog")
  7. ![Screenshot of Cron dialog](/static/img/cron.png?raw=true "Cron Dialog")
  8. ![Screenshot of Integrations page](/static/img/channels.png?raw=true "Integrations Page")
  9. 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.
  10. It is live here: [http://healthchecks.io/](http://healthchecks.io/)
  11. The building blocks are:
  12. * Python 2 or Python 3
  13. * Django 1.11
  14. * PostgreSQL or MySQL
  15. ## Setting Up for Development
  16. These are instructions for setting up healthchecks Django app
  17. in development environment.
  18. * prepare directory for project code and virtualenv:
  19. $ mkdir -p ~/webapps
  20. $ cd ~/webapps
  21. * prepare virtual environment
  22. (with virtualenv you get pip, we'll use it soon to install requirements):
  23. $ virtualenv --python=python3 hc-venv
  24. $ source hc-venv/bin/activate
  25. * check out project code:
  26. $ git clone https://github.com/healthchecks/healthchecks.git
  27. * install requirements (Django, ...) into virtualenv:
  28. $ pip install -r healthchecks/requirements.txt
  29. * healthchecks is configured to use a SQLite database by default. To use
  30. PostgreSQL or MySQL database, create and edit `hc/local_settings.py` file.
  31. There is a template you can copy and edit as needed:
  32. $ cd ~/webapps/healthchecks
  33. $ cp hc/local_settings.py.example hc/local_settings.py
  34. * create database tables and the superuser account:
  35. $ cd ~/webapps/healthchecks
  36. $ ./manage.py migrate
  37. $ ./manage.py createsuperuser
  38. * run development server:
  39. $ ./manage.py runserver
  40. The site should now be running at `http://localhost:8080`
  41. To log into Django administration site as a super user,
  42. visit `http://localhost:8080/admin`
  43. ## Configuration
  44. Site configuration is kept in `hc/settings.py`. Additional configuration
  45. is loaded from `hc/local_settings.py` file, if it exists. You
  46. can create this file (should be right next to `settings.py` in the filesystem)
  47. and override settings as needed.
  48. Some useful settings keys to override are:
  49. `SITE_ROOT` is used to build fully qualified URLs for pings, and for use in
  50. emails and notifications. Example:
  51. SITE_ROOT = "https://my-monitoring-project.com"
  52. `SITE_NAME` has the default value of "healthchecks.io" and is used throughout
  53. the templates. Replace it with your own name to personalize your installation.
  54. Example:
  55. SITE_NAME = "My Monitoring Project"
  56. `REGISTRATION_OPEN` controls whether site visitors can create new accounts.
  57. Set it to `False` if you are setting up a private healthchecks instance, but
  58. it needs to be publicly accessible (so, for example, your cloud services
  59. can send pings).
  60. If you close new user registration, you can still selectively invite users
  61. to your team account.
  62. ## Database Configuration
  63. Database configuration is stored in `hc/settings.py` and can be overriden
  64. in `hc/local_settings.py`. The default database engine is SQLite. To use
  65. PostgreSQL, create `hc/local_settings.py` if it does not exist, and put the
  66. following in it, changing it as neccessary:
  67. DATABASES = {
  68. 'default': {
  69. 'ENGINE': 'django.db.backends.postgresql',
  70. 'NAME': 'your-database-name-here',
  71. 'USER': 'your-database-user-here',
  72. 'PASSWORD': 'your-database-password-here',
  73. 'TEST': {'CHARSET': 'UTF8'}
  74. }
  75. }
  76. For MySQL:
  77. DATABASES = {
  78. 'default': {
  79. 'ENGINE': 'django.db.backends.mysql',
  80. 'NAME': 'your-database-name-here',
  81. 'USER': 'your-database-user-here',
  82. 'PASSWORD': 'your-database-password-here',
  83. 'TEST': {'CHARSET': 'UTF8'}
  84. }
  85. }
  86. You can also use `hc/local_settings.py` to read database
  87. configuration from environment variables like so:
  88. import os
  89. DATABASES = {
  90. 'default': {
  91. 'ENGINE': os.environ['DB_ENGINE'],
  92. 'NAME': os.environ['DB_NAME'],
  93. 'USER': os.environ['DB_USER'],
  94. 'PASSWORD': os.environ['DB_PASSWORD'],
  95. 'TEST': {'CHARSET': 'UTF8'}
  96. }
  97. }
  98. ## Sending Emails
  99. healthchecks must be able to send email messages, so it can send out login
  100. links and alerts to users. Put your SMTP server configuration in
  101. `hc/local_settings.py` like so:
  102. EMAIL_HOST = "your-smtp-server-here.com"
  103. EMAIL_PORT = 587
  104. EMAIL_HOST_USER = "username"
  105. EMAIL_HOST_PASSWORD = "password"
  106. EMAIL_USE_TLS = True
  107. For more information, have a look at Django documentation,
  108. [Sending Email](https://docs.djangoproject.com/en/1.10/topics/email/) section.
  109. ## Sending Status Notifications
  110. healtchecks comes with a `sendalerts` management command, which continuously
  111. polls database for any checks changing state, and sends out notifications as
  112. needed. Within an activated virtualenv, you can manually run
  113. the `sendalerts` command like so:
  114. $ ./manage.py sendalerts
  115. In a production setup, you will want to run this command from a process
  116. manager like [supervisor](http://supervisord.org/) or systemd.
  117. ## Database Cleanup
  118. With time and use the healthchecks database will grow in size. You may
  119. decide to prune old data: inactive user accounts, old checks not assigned
  120. to users, records of outgoing email messages and records of received pings.
  121. There are separate Django management commands for each task:
  122. * Remove old records from `api_ping` table. For each check, keep 100 most
  123. recent pings:
  124. ````
  125. $ ./manage.py prunepings
  126. ````
  127. * Remove checks older than 2 hours that are not assigned to users. Such
  128. checks are by-products of random visitors and robots loading the welcome
  129. page and never setting up an account:
  130. ```
  131. $ ./manage.py prunechecks
  132. ```
  133. * Remove old records of sent notifications. For each check, remove
  134. notifications that are older than the oldest stored ping for same check.
  135. ````
  136. $ ./manage.py prunenotifications
  137. ````
  138. * Remove user accounts that match either of these conditions:
  139. * Account was created more than 6 months ago, and user has never logged in.
  140. These can happen when user enters invalid email address when signing up.
  141. * Last login was more than 6 months ago, and the account has no checks.
  142. Assume the user doesn't intend to use the account any more and would
  143. probably *want* it removed.
  144. ```
  145. $ ./manage.py pruneusers
  146. ```
  147. When you first try these commands on your data, it is a good idea to
  148. test them on a copy of your database, not on the live database right away.
  149. In a production setup, you should also have regular, automated database
  150. backups set up.
  151. ## Integrations
  152. ### Pushover
  153. To enable Pushover integration, you will need to:
  154. * register a new application on https://pushover.net/apps/build
  155. * enable subscriptions in your application and make sure to enable the URL
  156. subscription type
  157. * add the application token and subscription URL to `hc/local_settings.py`, as
  158. `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL`
  159. ### Telegram
  160. * Create a Telegram bot by talking to the
  161. [BotFather](https://core.telegram.org/bots#6-botfather). Set the bot's name,
  162. description, user picture, and add a "/start" command.
  163. * After creating the bot you will have the bot's name and token. Add them
  164. to your `hc/local_settings.py` file as `TELEGRAM_BOT_NAME` and
  165. `TELEGRAM_TOKEN` fields.
  166. * Now the tricky part: when a Telegram user talks to your bot,
  167. Telegram will use a webhook to forward received messages to your healthchecks
  168. instance. For this to work, your healthchecks instance needs to be publicly
  169. accessible over HTTPS. Using the
  170. [setWebhook](https://core.telegram.org/bots/api#setwebhook) API call
  171. set the bot's webhook to `https://yourdomain.com/integrations/telegram/bot/`.