diff --git a/Gemfile b/Gemfile index 51f64b2..d9edd02 100644 --- a/Gemfile +++ b/Gemfile @@ -38,7 +38,6 @@ gem 'spring', :group => :development # Use debugger # gem 'debugger', group: [:development, :test] - #Installed by me group :production do gem 'rails_12factor' @@ -48,6 +47,7 @@ group :production do gem 'dalli' end +gem 'influxdb-rails' gem 'devise' gem 'cancancan' gem 'round_robin_tournament' diff --git a/Gemfile.lock b/Gemfile.lock index 51deed1..e7106af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,11 +62,11 @@ GEM zeitwerk (~> 2.3) addressable (2.4.0) ast (2.4.2) - backports (3.20.2) + backports (3.21.0) bcrypt (3.1.16) brakeman (5.0.0) builder (3.2.4) - bullet (6.1.3) + bullet (6.1.4) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) cancancan (3.2.1) @@ -85,10 +85,10 @@ GEM dalli (2.7.11) delayed_job (4.1.9) activesupport (>= 3.0, < 6.2) - delayed_job_active_record (4.1.5) + delayed_job_active_record (4.1.6) activerecord (>= 3.0, < 6.2) delayed_job (>= 3.0, < 5) - delayed_job_web (1.4.3) + delayed_job_web (1.4.4) activerecord (> 3.0.0) delayed_job (> 2.0.3) rack-protection (>= 1.5.5) @@ -109,7 +109,7 @@ GEM multipart-post (>= 1.2, < 3) faraday_middleware (0.14.0) faraday (>= 0.7.4, < 1.0) - ffi (1.14.2) + ffi (1.15.0) gh (0.15.1) addressable (~> 2.4.0) backports @@ -132,8 +132,12 @@ GEM http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) - i18n (1.8.8) + i18n (1.8.10) concurrent-ruby (~> 1.0) + influxdb (0.8.1) + influxdb-rails (1.0.1) + influxdb (~> 0.6, >= 0.6.4) + railties (>= 5.0) jbuilder (2.11.2) activesupport (>= 5.0.0) jquery-rails (4.4.0) @@ -154,11 +158,13 @@ GEM method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2020.1104) - mimemagic (0.3.5) - mini_mime (1.0.2) + mime-types-data (3.2021.0225) + mimemagic (0.3.10) + nokogiri (~> 1) + rake + mini_mime (1.0.3) mini_portile2 (2.5.0) - minitest (5.14.3) + minitest (5.14.4) multi_json (1.15.0) multipart-post (2.1.1) mustermann (1.1.1) @@ -168,8 +174,8 @@ GEM net-http-pipeline (1.0.1) netrc (0.11.0) newrelic_rpm (6.15.0) - nio4r (2.5.5) - nokogiri (1.11.1) + nio4r (2.5.7) + nokogiri (1.11.2) mini_portile2 (~> 2.5.0) racc (~> 1.4) orm_adapter (0.5.0) @@ -179,7 +185,7 @@ GEM passenger (6.0.7) rack rake (>= 0.8.1) - puma (5.2.1) + puma (5.2.2) nio4r (~> 2.0) pusher-client (0.6.2) json @@ -226,7 +232,7 @@ GEM rb-readline (0.5.5) rdoc (6.3.0) ref (2.0.0) - regexp_parser (2.0.3) + regexp_parser (2.1.1) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -237,7 +243,7 @@ GEM netrc (~> 0.8) rexml (3.2.4) round_robin_tournament (0.1.1) - rubocop (1.9.1) + rubocop (1.12.0) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) @@ -250,7 +256,7 @@ GEM parser (>= 2.7.1.5) ruby-progressbar (1.11.0) ruby2_keywords (0.0.4) - sdoc (2.0.3) + sdoc (2.1.0) rdoc (>= 5.0) sinatra (2.1.0) mustermann (~> 1.0) @@ -266,8 +272,7 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.4.2) - terminal-table (3.0.0) - unicode-display_width (~> 1.1, >= 1.1.1) + terminal-table (1.6.0) therubyracer (0.12.3) libv8 (~> 3.16.14.15) ref @@ -296,8 +301,8 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.7) - unicode-display_width (1.7.0) - uniform_notifier (1.13.2) + unicode-display_width (2.0.0) + uniform_notifier (1.14.2) warden (1.2.9) rack (>= 2.0.9) websocket (1.2.9) @@ -320,6 +325,7 @@ DEPENDENCIES delayed_job_web devise hakiri + influxdb-rails jbuilder jquery-rails mysql2 diff --git a/README.md b/README.md index 64ad057..d349078 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,8 @@ The production version of this is currently deployed in Kubernetes. See [Deployi * `MEMCACHIER_SERVERS=memcachier_hostname:memcachier_port` needed for caching * `MEMCACHIER_USERNAME=memcachier_username` needed for caching * `WRESTLINGDEV_NEW_RELIC_LICENSE_KEY=new_relic_license_key` this is only needed to use new relic +* `WRESTLINGDEV_INFLUXDB_DATABASE=influx_db_name` to send metrics to influxdb this is required +* `WRESTLINGDEV_INFLUXDB_HOST=influx_db_ip_or_hostname` to send metrics to influxdb this is required +* `WRESTLINGDEV_INFLUXDB_PORT=influx_db_port` to send metrics to influxdb this is required +* `WRESTLINGDEV_INFLUXDB_USERNAME=influx_db_username` to send metrics to influxdb this is optional +* `WRESTLINGDEV_INFLUXDB_PASSWORD=influx_db_password` to send metrics to influxdb this is optional \ No newline at end of file diff --git a/config/initializers/influxdb_rails.rb b/config/initializers/influxdb_rails.rb new file mode 100644 index 0000000..4a24a3f --- /dev/null +++ b/config/initializers/influxdb_rails.rb @@ -0,0 +1,45 @@ +InfluxDB::Rails.configure do |config| + ## The only setting you actually need to update is the name of the + ## database within the InfluxDB server instance. Don't forget to + ## create this database as well. + config.client.database = "#{ENV['WRESTLINGDEV_INFLUXDB_DATABASE']}" + config.client.hosts = ["#{ENV['WRESTLINGDEV_INFLUXDB_HOST']}"] + config.client.port = ENV['WRESTLINGDEV_INFLUXDB_PORT'] + + ## If you've setup user authentication (and activated it in the server + ## config), you need to configure the credentials here. + config.client.username = "#{ENV['WRESTLINGDEV_INFLUXDB_USERNAME']}" + config.client.password = "#{ENV['WRESTLINGDEV_INFLUXDB_PASSWORD']}" + + ## If your InfluxDB service requires an HTTPS connection then you can + ## enable it here. + # config.client.use_ssl = true + + ## Various other client and connection options. These are used to create + ## an `InfluxDB::Client` instance (i.e. `InfluxDB::Rails.client`). + ## + ## See docs for the influxdb gem for the canonical list of options: + ## https://github.com/influxdata/influxdb-ruby#list-of-configuration-options + ## + ## These defaults for the influxdb-rails gem deviate from the default + ## for the influxdb gem: + # config.client.async = true # false + # config.client.read_timeout = 30 # 300 + # config.client.max_delay = 300 # 30 + # config.client.time_precision = "ms" # "s" + + ## Prior to 1.0.0, this gem has written all data points in different + ## measurements (the config options were named `series_name_for_*`). + ## Since 1.0.0.beta3, we're now using a single measurements + # config.measurement_name = "rails" + + ## Disable rails framework hooks. + # config.ignored_hooks = ['sql.active_record', 'render_template.action_view'] + + # Modify tags on the fly. + # config.tags_middleware = ->(tags) { tags } + + ## Set the application name to something meaningful, by default we + ## infer the app name from the Rails.application class name. + # config.application_name = Rails.application.class.parent_name +end diff --git a/deploy/docker-compose-test.yml b/deploy/docker-compose-test.yml index 7aacb14..783f25c 100644 --- a/deploy/docker-compose-test.yml +++ b/deploy/docker-compose-test.yml @@ -2,6 +2,7 @@ version: "2.2" networks: database: caching: + metrics: volumes: mysql: @@ -23,9 +24,13 @@ services: - MEMCACHIER_PASSWORD= - WRESTLINGDEV_DEVISE_SECRET_KEY=2f29d49db6704377ba263f7cb9db085b386bcb301c0cd501126a674686ab1a109754071165b08cd72af03cec4642a4dd04361c994462254dd5d85e9594e8b9aa - WRESTLINGDEV_SECRET_KEY_BASE=077cdbef5c2ccf22543fb17a67339f234306b7fa2e1e4463d851c444c10a5611829a2290b253da78339427f131571fac9a42c83d960b2d25ecc10a4a0a7ce1a2 + - WRESTLINGDEV_INFLUXDB_DATABASE=wrestlingdev + - WRESTLINGDEV_INFLUXDB_HOST=influxdb + - WRESTLINGDEV_INFLUXDB_PORT=8086 networks: database: caching: + metrics: restart: always ports: - "80:80" @@ -58,16 +63,28 @@ services: - MEMCACHIER_PASSWORD= - WRESTLINGDEV_DEVISE_SECRET_KEY=2f29d49db6704377ba263f7cb9db085b386bcb301c0cd501126a674686ab1a109754071165b08cd72af03cec4642a4dd04361c994462254dd5d85e9594e8b9aa - WRESTLINGDEV_SECRET_KEY_BASE=077cdbef5c2ccf22543fb17a67339f234306b7fa2e1e4463d851c444c10a5611829a2290b253da78339427f131571fac9a42c83d960b2d25ecc10a4a0a7ce1a2 + - WRESTLINGDEV_INFLUXDB_DATABASE=wrestlingdev + - WRESTLINGDEV_INFLUXDB_HOST=influxdb + - WRESTLINGDEV_INFLUXDB_PORT=8086 networks: database: caching: + metrics: restart: always command: bundle exec bin/delayed_job -n 1 run + + influxdb: + image: influxdb:1.8-alpine + environment: + - INFLUXDB_DB=wrestlingdev + ports: + - "8086:8086" + networks: + metrics: memcached: image: memcached:1.5 mem_limit: 64000000 restart: always networks: - caching: - + caching: \ No newline at end of file diff --git a/deploy/kubernetes/manifests/influxdb.yaml b/deploy/kubernetes/manifests/influxdb.yaml new file mode 100644 index 0000000..6aef67f --- /dev/null +++ b/deploy/kubernetes/manifests/influxdb.yaml @@ -0,0 +1,74 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: wrestlingdev-influxdb + labels: + app: wrestlingdev + tier: metrics +spec: + ports: + - port: 8086 + selector: + app: wrestlingdev + tier: metrics + clusterIP: None +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wrestlingdev-influxdb + labels: + app: wrestlingdev + tier: metrics +spec: + replicas: 1 + selector: + matchLabels: + app: wrestlingdev + template: + metadata: + labels: + app: wrestlingdev + tier: metrics + spec: + containers: + - name: wrestlingdev-influxdb + image: influxdb:1.8-alpine + ports: + - containerPort: 8086 + env: + - name: INFLUXDB_DB + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_database + volumeMounts: + - name: wrestlingdev-influxdb-persistent-storage + mountPath: /var/lib/influxdb + resources: + limits: + cpu: "0.7" + memory: "512Mi" + requests: + memory: "128Mi" + cpu: "0.5" + volumes: + - name: wrestlingdev-influxdb-persistent-storage + persistentVolumeClaim: + claimName: wrestlingdev-influxdb-pv-claim +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: wrestlingdev-influxdb-pv-claim + labels: + app: wrestlingdev + tier: metrics +spec: + storageClassName: standard + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi \ No newline at end of file diff --git a/deploy/kubernetes/manifests/wrestlingdev.yaml b/deploy/kubernetes/manifests/wrestlingdev.yaml index 261a58a..ff5e19f 100644 --- a/deploy/kubernetes/manifests/wrestlingdev.yaml +++ b/deploy/kubernetes/manifests/wrestlingdev.yaml @@ -81,6 +81,21 @@ spec: secretKeyRef: name: wrestlingdev-secrets key: gmailemail + - name: WRESTLINGDEV_INFLUXDB_DATABASE + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_database + - name: WRESTLINGDEV_INFLUXDB_HOST + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_hostname + - name: WRESTLINGDEV_INFLUXDB_PORT + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_port resources: limits: cpu: "0.5" @@ -187,6 +202,21 @@ spec: secretKeyRef: name: wrestlingdev-secrets key: gmailemail + - name: WRESTLINGDEV_INFLUXDB_DATABASE + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_database + - name: WRESTLINGDEV_INFLUXDB_HOST + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_hostname + - name: WRESTLINGDEV_INFLUXDB_PORT + valueFrom: + secretKeyRef: + name: wrestlingdev-secrets + key: influxdb_port command: ["bundle"] args: ["exec", "bin/delayed_job", "-n", "1", "run"] resources: diff --git a/deploy/kubernetes/secrets/secrets.yaml b/deploy/kubernetes/secrets/secrets.yaml index d84f6de..1719af9 100644 --- a/deploy/kubernetes/secrets/secrets.yaml +++ b/deploy/kubernetes/secrets/secrets.yaml @@ -11,4 +11,7 @@ stringData: devisesecretkey: PUT_SECRET_HERE get from running rails secret railssecretkey: PUT_SECRET_HERE get from running rails secret emailpassword: PUT_EMAIL_PASSWORD_HERE - gmailemail: PUT EMAIL ADDRESS HERE \ No newline at end of file + gmailemail: PUT EMAIL ADDRESS HERE + influxdb_database: PUT INFLUXDB DATABASE NAME HERE + influxdb_hostname: PUT INFLUXDB HOSTNAME OR IP HERE + influxdb_port: PUT INFLUXDB PORT HERE \ No newline at end of file