-
-
Notifications
You must be signed in to change notification settings - Fork 629
feat: add MySQL storage support #1003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
694f10f
feat: add mysql support
devhaozi 819150b
fix: tests
devhaozi a2eca11
docs: add mysql example
devhaozi 03bd588
docs: update mysql example
devhaozi dc337b6
fix: mysql reserved word
devhaozi 38efc83
fix: mysql delete
devhaozi 53e550a
fix: mysql reserved word
devhaozi a8952f0
fix: mysql reserved word
devhaozi f3dad26
Merge branch 'master' into master
devhaozi 9433fd6
Merge branch 'master' into master
devhaozi f4f687b
fix: mysql Error 1235 (42000): This version of MySQL doesn't yet supp…
devhaozi e9376e4
Merge remote-tracking branch 'origin/master'
devhaozi f7da17d
Merge branch 'master' into master
devhaozi 677ce20
Merge branch 'master' into master
devhaozi 4556b8a
feat: optimize query
devhaozi 1b3607f
fix: mysql docker-compose error
devhaozi cd4f6be
Merge remote-tracking branch 'TwiN/master'
devhaozi 792f798
chore: merge master
devhaozi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| storage: | ||
| type: mysql | ||
| path: "${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(mysql:3306)/${MYSQL_DATABASE}?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true&interpolateParams=true" | ||
|
|
||
| endpoints: | ||
| - name: back-end | ||
| group: core | ||
| url: "https://example.org/" | ||
| interval: 5m | ||
| conditions: | ||
| - "[STATUS] == 200" | ||
| - "[CERTIFICATE_EXPIRATION] > 48h" | ||
|
|
||
| - name: monitoring | ||
| group: internal | ||
| url: "https://example.org/" | ||
| interval: 5m | ||
| conditions: | ||
| - "[STATUS] == 200" | ||
|
|
||
| - name: nas | ||
| group: internal | ||
| url: "https://example.org/" | ||
| interval: 5m | ||
| conditions: | ||
| - "[STATUS] == 200" | ||
|
|
||
| - name: example-dns-query | ||
| url: "8.8.8.8" # Address of the DNS server to use | ||
| interval: 5m | ||
| dns: | ||
| query-name: "example.com" | ||
| query-type: "A" | ||
| conditions: | ||
| - "[BODY] == 93.184.215.14" | ||
| - "[DNS_RCODE] == NOERROR" | ||
|
|
||
| - name: icmp-ping | ||
| url: "icmp://example.org" | ||
| interval: 1m | ||
| conditions: | ||
| - "[CONNECTED] == true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| version: "3.9" | ||
| services: | ||
| mysql: | ||
| image: mysql:lts | ||
| volumes: | ||
| - ./data/db:/var/lib/mysql | ||
| ports: | ||
| - "3306:3306" | ||
| environment: | ||
| - MYSQL_DATABASE=gatus | ||
| - MYSQL_USER=username | ||
| - MYSQL_PASSWORD=password | ||
| - MYSQL_ROOT_PASSWORD=root_password | ||
| networks: | ||
| - web | ||
|
|
||
| gatus: | ||
| image: twinproduction/gatus:latest | ||
| restart: always | ||
| ports: | ||
| - "8080:8080" | ||
| environment: | ||
| - POSTGRES_USER=username | ||
| - POSTGRES_PASSWORD=password | ||
| - POSTGRES_DB=gatus | ||
| volumes: | ||
| - ./config:/config | ||
| networks: | ||
| - web | ||
| depends_on: | ||
| - mysql | ||
|
|
||
| networks: | ||
| web: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package sql | ||
|
|
||
| func (s *Store) createMySQLSchema() error { | ||
| _, err := s.db.Exec(` | ||
| CREATE TABLE IF NOT EXISTS endpoints ( | ||
| endpoint_id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| endpoint_key VARCHAR(255) UNIQUE, | ||
| endpoint_name VARCHAR(255) NOT NULL, | ||
| endpoint_group VARCHAR(255) NOT NULL, | ||
| UNIQUE(endpoint_name, endpoint_group) | ||
| ) | ||
| `) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = s.db.Exec(` | ||
| CREATE TABLE IF NOT EXISTS endpoint_events ( | ||
| endpoint_event_id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| endpoint_id BIGINT NOT NULL, | ||
| event_type VARCHAR(255) NOT NULL, | ||
| event_timestamp DATETIME NOT NULL, | ||
| FOREIGN KEY (endpoint_id) REFERENCES endpoints(endpoint_id) ON DELETE CASCADE | ||
| ) | ||
| `) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = s.db.Exec(` | ||
| CREATE TABLE IF NOT EXISTS endpoint_results ( | ||
| endpoint_result_id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| endpoint_id BIGINT NOT NULL, | ||
| success BOOLEAN NOT NULL, | ||
| errors TEXT NOT NULL, | ||
| connected BOOLEAN NOT NULL, | ||
| status INT NOT NULL, | ||
| dns_rcode VARCHAR(255) NOT NULL, | ||
| certificate_expiration BIGINT NOT NULL, | ||
| domain_expiration BIGINT NOT NULL, | ||
| hostname VARCHAR(255) NOT NULL, | ||
| ip VARCHAR(255) NOT NULL, | ||
| duration BIGINT NOT NULL, | ||
| timestamp DATETIME NOT NULL, | ||
| FOREIGN KEY (endpoint_id) REFERENCES endpoints(endpoint_id) ON DELETE CASCADE | ||
| ) | ||
| `) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = s.db.Exec(` | ||
| CREATE TABLE IF NOT EXISTS endpoint_result_conditions ( | ||
| endpoint_result_condition_id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| endpoint_result_id BIGINT NOT NULL, | ||
| ` + "`condition`" + ` TEXT NOT NULL, | ||
| success BOOLEAN NOT NULL, | ||
| FOREIGN KEY (endpoint_result_id) REFERENCES endpoint_results(endpoint_result_id) ON DELETE CASCADE | ||
| ) | ||
| `) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = s.db.Exec(` | ||
| CREATE TABLE IF NOT EXISTS endpoint_uptimes ( | ||
| endpoint_uptime_id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| endpoint_id BIGINT NOT NULL, | ||
| hour_unix_timestamp BIGINT NOT NULL, | ||
| total_executions BIGINT NOT NULL, | ||
| successful_executions BIGINT NOT NULL, | ||
| total_response_time BIGINT NOT NULL, | ||
| UNIQUE(endpoint_id, hour_unix_timestamp), | ||
| FOREIGN KEY (endpoint_id) REFERENCES endpoints(endpoint_id) ON DELETE CASCADE | ||
| ) | ||
| `) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = s.db.Exec(` | ||
| CREATE TABLE IF NOT EXISTS endpoint_alerts_triggered ( | ||
| endpoint_alert_trigger_id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| endpoint_id BIGINT NOT NULL, | ||
| configuration_checksum VARCHAR(255) NOT NULL, | ||
| resolve_key VARCHAR(255) NOT NULL, | ||
| number_of_successes_in_a_row INT NOT NULL, | ||
| UNIQUE(endpoint_id, configuration_checksum), | ||
| FOREIGN KEY (endpoint_id) REFERENCES endpoints(endpoint_id) ON DELETE CASCADE | ||
| ) | ||
| `) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.