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.

223 lines
7.1 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. Put your SMTP server configuration in
  94. `hc/local_settings.py` like so:
  95. EMAIL_HOST = "your-smtp-server-here.com"
  96. EMAIL_PORT = 587
  97. EMAIL_HOST_USER = "username"
  98. EMAIL_HOST_PASSWORD = "password"
  99. EMAIL_USE_TLS = True
  100. For more information, have a look at Django documentation,
  101. [Sending Email](https://docs.djangoproject.com/en/1.10/topics/email/) section.
  102. ## Sending Status Notifications
  103. healtchecks comes with a `sendalerts` management command, which continuously
  104. polls database for any checks changing state, and sends out notifications as
  105. needed. Within an activated virtualenv, you can manually run
  106. the `sendalerts` command like so:
  107. $ ./manage.py sendalerts
  108. In a production setup, you will want to run this command from a process
  109. manager like [supervisor](http://supervisord.org/) or systemd.
  110. ## Database Cleanup
  111. With time and use the healthchecks database will grow in size. You may
  112. decide to prune old data: inactive user accounts, old checks not assigned
  113. to users, records of outgoing email messages and records of received pings.
  114. There are separate Django management commands for each task:
  115. * Remove old records from `api_ping` table. For each check, keep 100 most
  116. recent pings:
  117. ````
  118. $ ./manage.py prunepings
  119. ````
  120. * Remove checks older than 2 hours that are not assigned to users. Such
  121. checks are by-products of random visitors and robots loading the welcome
  122. page and never setting up an account:
  123. ```
  124. $ ./manage.py prunechecks
  125. ```
  126. * Remove records of sent email messages older than 7 days.
  127. ````
  128. $ ./manage.py pruneemails
  129. ````
  130. * Remove old records of sent notifications. For each check, remove
  131. notifications that are older than the oldest stored ping for same check.
  132. ````
  133. $ ./manage.py prunenotifications
  134. ````
  135. * Remove user accounts that match either of these conditions:
  136. * Account was created more than 6 months ago, and user has never logged in.
  137. These can happen when user enters invalid email address when signing up.
  138. * Last login was more than 6 months ago, and the account has no checks.
  139. Assume the user doesn't intend to use the account any more and would
  140. probably *want* it removed.
  141. ```
  142. $ ./manage.py pruneusers
  143. ```
  144. When you first try these commands on your data, it is a good idea to
  145. test them on a copy of your database, not on the live database right away.
  146. In a production setup, you should also have regular, automated database
  147. backups set up.
  148. ## Integrations
  149. ### Pushover
  150. To enable Pushover integration, you will need to:
  151. * register a new application on https://pushover.net/apps/build
  152. * enable subscriptions in your application and make sure to enable the URL
  153. subscription type
  154. * add the application token and subscription URL to `hc/local_settings.py`, as
  155. `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL`