├── .ebextensions └── 01-ebs.config ├── Dockerfile ├── Dockerrun.aws.json ├── LICENSE ├── README.md ├── build ├── cloudwatch ├── env2file ├── leadbutt-cloudwatch-cron.conf └── leadbutt-cloudwatch.conf ├── configure.sh ├── configure_influxdb_at_run.sh ├── grafana └── config.js ├── influxdb ├── LICENSE ├── config.toml └── run.sh ├── nginx ├── nginx.conf └── run.sh ├── set_grafana.sh ├── set_influxdb.sh ├── start ├── stop └── utils └── leadbutt2influxdb.clj /.ebextensions/01-ebs.config: -------------------------------------------------------------------------------- 1 | commands: 2 | 000create-my-user: 3 | command: | 4 | useradd holyjak --home-dir /home/holyjak --create-home --groups root 5 | mkdir /home/holyjak/.ssh 6 | echo 'ssh-rsa AAAAB3NzaC2yc2EAAAADAQABAAABAQC6LfBJGqsxwyhHY7jDnQGtq7cmk+WXYjsnKSoy/xt6kroWgbEaFvgRVXIzcS9sbuu8PvYbIpsHmOStFvmJzbRNQk+zlqE85WLVkcUwi8fH0hs8tJwMyDJ4kR88s22n80L3RN7uBAaD9E10wEHEmng4xgyT2WqI7GmlK7+bZWWA5E3WaqVyFgihZ8ju6/j+H5uL8tEGOUJxRY087syHghPjhFxSC5Vjkd0lBIAtLx41TbejhQOXv+VWZj7nc18sW6n+3u2cURgmxWIae/YdK2ZKZVLf+dDg7D5AYj5t6hyyT+1ZTXQ89ZpClwxPy7qsRg+dXaxrf9+gP8IqnXYmp2oR jakub.holy@iterate.no' > /home/holyjak/.ssh/authorized_keys 7 | chmod -R go-rwx /home/holyjak/.ssh 8 | chown -R holyjak /home/holyjak/.ssh 9 | test: sh -c "! egrep '^holyjak:' /etc/passwd" 10 | 001sudo-authorize: 11 | command: | 12 | echo 'holyjak ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/holyjak 13 | chown root:root /etc/sudoers.d/* 14 | chmod 0440 /etc/sudoers.d/* 15 | test: test ! -f /etc/sudoers.d/holyjak 16 | 01format-volume: 17 | command: mkfs -t ext3 /dev/sdh 18 | test: file -sL /dev/sdh | grep -v 'ext3 filesystem' 19 | # ^ prints '/dev/sdh: data' if not formatted 20 | 02attach-volume: 21 | # Note: The volume may be renamed by the Kernel, e.g. sdh -> xvdh but 22 | # /dev/ will then contain a symlink from the old to the new name 23 | command: | 24 | mkdir /media/ebs_volume 25 | mount /dev/sdh /media/ebs_volume 26 | test: sh -c "! grep -qs '/media/ebs_volume' /proc/mounts" 27 | option_settings: 28 | - namespace: aws:autoscaling:launchconfiguration 29 | option_name: BlockDeviceMappings 30 | value: /dev/sdh=:100 31 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage:0.9.16 2 | 3 | # TODO Update Grafana to 2.0.2; consider using .deb installer? 4 | ENV GRAFANA_VERSION 1.9.1 5 | ENV INFLUXDB_VERSION 0.8.8 6 | 7 | # Prevent some error messages 8 | ENV DEBIAN_FRONTEND noninteractive 9 | 10 | #RUN echo 'deb http://us.archive.ubuntu.com/ubuntu/ trusty universe' >> /etc/apt/sources.list 11 | RUN apt-get -y update && apt-get -y upgrade 12 | 13 | # ---------------- # 14 | # Installation # 15 | # ---------------- # 16 | 17 | # Install all prerequisites 18 | RUN apt-get -y install wget nginx-light curl 19 | 20 | # Install Grafana to /src/grafana 21 | RUN mkdir -p src/grafana && cd src/grafana && \ 22 | wget http://grafanarel.s3.amazonaws.com/grafana-${GRAFANA_VERSION}.tar.gz -O grafana.tar.gz && \ 23 | tar xzf grafana.tar.gz --strip-components=1 && rm grafana.tar.gz 24 | 25 | # Install InfluxDB 26 | RUN wget http://s3.amazonaws.com/influxdb/influxdb_${INFLUXDB_VERSION}_amd64.deb && \ 27 | dpkg -i influxdb_${INFLUXDB_VERSION}_amd64.deb && rm influxdb_${INFLUXDB_VERSION}_amd64.deb 28 | 29 | # ----------------- # 30 | # Configuration # 31 | # ----------------- # 32 | 33 | # Configure InfluxDB 34 | ADD influxdb/config.toml /etc/influxdb/config.toml 35 | ADD influxdb/run.sh /etc/service/influxdb/run 36 | # These two databases have to be created. These variables are used by set_influxdb.sh and set_grafana.sh 37 | ENV PRE_CREATE_DB data grafana 38 | ENV INFLUXDB_DATA_USER data 39 | ENV INFLUXDB_DATA_PW data 40 | ENV INFLUXDB_GRAFANA_USER grafana 41 | ENV INFLUXDB_GRAFANA_PW grafana 42 | ENV ROOT_PW root 43 | 44 | # Configure Grafana 45 | ADD ./grafana/config.js /src/grafana/config.js 46 | #ADD ./grafana/scripted.json /src/grafana/app/dashboards/default.json 47 | 48 | ADD ./configure.sh /configure.sh 49 | ADD ./set_grafana.sh /set_grafana.sh 50 | ADD ./set_influxdb.sh /set_influxdb.sh 51 | RUN /configure.sh 52 | 53 | # Configure nginx (that serves Grafana) 54 | ADD ./nginx/run.sh /etc/service/nginx/run 55 | ADD ./nginx/nginx.conf /etc/nginx/nginx.conf 56 | 57 | 58 | # -------------- # 59 | # CloudWatch # 60 | # -------------- # 61 | 62 | # Add a script run automatically at startup that creates /docker.env 63 | # so that the Cron job can access the AWS credentials env variables 64 | ADD cloudwatch/env2file /etc/my_init.d/env2file 65 | 66 | RUN apt-get -y install python-pip 67 | 68 | RUN pip install --global-option="--without-libyaml" PyYAML 69 | # ^- libyaml seems to be unavailable here; cloudwatch dependency 70 | RUN pip install cloudwatch-to-graphite==0.5.0 71 | 72 | ADD cloudwatch/leadbutt-cloudwatch.conf /etc/leadbutt-cloudwatch.conf 73 | ADD cloudwatch/leadbutt-cloudwatch-cron.conf /etc/cron.d/leadbutt-cloudwatch 74 | # TODO(improvement) use crontab fragments in /etc/cron.d/ instead of using root's crontab 75 | # See for other tips: http://stackoverflow.com/questions/26822067/running-cron-python-jobs-within-docker 76 | RUN crontab /etc/cron.d/leadbutt-cloudwatch 77 | 78 | # Note: AWS cedentials should be provided via ENV vars; ex.: 79 | # docker run -e AWS_ACCESS_KEY_ID=xxxx -e AWS_SECRET_ACCESS_KEY=yyyy ... 80 | 81 | # ----------- # 82 | # Cleanup # 83 | # ----------- # 84 | 85 | RUN apt-get autoremove -y wget curl && \ 86 | apt-get -y clean && \ 87 | rm -rf /var/lib/apt/lists/* && rm /*.sh 88 | 89 | # ----------- # 90 | # Volumes # 91 | # ----------- # 92 | 93 | ADD configure_influxdb_at_run.sh /etc/my_init.d/configure_influxdb_at_run.sh 94 | RUN cp -r /var/easydeploy/share /var/infuxdb_initial_data_backup 95 | # influxdb data dir: 96 | VOLUME ["/var/easydeploy/share"] 97 | 98 | # ---------------- # 99 | # Expose Ports # 100 | # ---------------- # 101 | 102 | # Grafana 103 | EXPOSE 80 104 | 105 | # InfluxDB Admin server 106 | EXPOSE 8083 107 | 108 | # InfluxDB HTTP API 109 | EXPOSE 8086 110 | 111 | # InfluxDB HTTPS API 112 | EXPOSE 8084 113 | 114 | # -------- # 115 | # Run! # 116 | # -------- # 117 | CMD /sbin/my_init 118 | -------------------------------------------------------------------------------- /Dockerrun.aws.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSEBDockerrunVersion": "1", 3 | "Volumes": [ 4 | { 5 | "HostDirectory": "/media/ebs_volume", 6 | "ContainerDirectory": "/var/easydeploy/share" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docker-grafana-influxdb-cloudwatch 2 | ================================== 3 | 4 | Derived from [kamon-io/docker-grafana-influxdb][1], 5 | this image contains a sensible default configuration of InfluxDB and Grafana but also: 6 | 7 | * Is based on [phusion/baseimage](http://phusion.github.io/baseimage-docker/) instead of stock 8 | Ubuntu 9 | * Bundles [cloudwatch-to-graphite](https://github.com/crccheck/cloudwatch-to-graphite), run via 10 | cron, for fetching metrics from AWS CloudWatch 11 | * Enables InfluxDB's Graphite input plugin 12 | 13 | See the introductory blog post [All-in-one Docker with Grafana, InfluxDB, and cloudwatch-to-graphite for AWS/Beanstalk monitoring](https://theholyjava.wordpress.com/2015/05/07/all-in-one-docker-with-grafana-influxdb-and-cloudwatch-to-graphite-for-awsbeanstalk-monitoring/) for more details. 14 | 15 | ### Configuration 16 | 17 | For InfluxDB and Grafana, see [docker-grafana-influxdb][1]. 18 | By default there are 2 databases, `grafana` for dashboards and `data` for metrics. 19 | Use the user and password `data` to access the metrics via the InfluxDB UI. 20 | 21 | Regarding cloudwatch-to-graphite and its `leadbutt` command-line: 22 | 23 | * Metrics to fetch are in [`cloudwatch/leadbutt-cloudwatch`](cloudwatch/leadbutt-cloudwatch) 24 | * AWS Credentials are supposed to be provided via env variables, for example: 25 | `docker run -e AWS_ACCESS_KEY_ID=xxxx -e AWS_SECRET_ACCESS_KEY=yyyy ...` (see `./start`) - in the case of AWS Elastic Beanstalk you can set them in you environment's configuration UI 26 | 27 | ### Other 28 | 29 | See `utils/leadbutt2influxdb.clj` for a utility that can convert leadbutt output 30 | to InfluxDB input. You might want to copy and modify the leadbutt configuration 31 | file to fetch the last 2 weeks of hourly data (`Period: 60; Count: 336`), use 32 | the utility to convert it and post to InfluxDB. 33 | 34 | [1]: https://github.com/kamon-io/docker-grafana-influxdb 35 | -------------------------------------------------------------------------------- /build: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | docker rm grafana-influxdb_con 4 | docker rmi -f grafana_influxdb 5 | docker build -t grafana_influxdb . 6 | -------------------------------------------------------------------------------- /cloudwatch/env2file: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | env > /docker.env 3 | -------------------------------------------------------------------------------- /cloudwatch/leadbutt-cloudwatch-cron.conf: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin 3 | 4 | # Metrics are fetched every 5 minutes 5 | # while...: re-create env variables in a fail-safe way even if they contain spaces etc. 6 | */5 * * * * while read line; do export "$line"; done < /docker.env && leadbutt --config-file=/etc/leadbutt-cloudwatch.conf 2>/var/log/leadbutt.log | nc -q0 127.0.0.1 2003 >>/var/log/leadbutt.log 2>&1 7 | -------------------------------------------------------------------------------- /cloudwatch/leadbutt-cloudwatch.conf: -------------------------------------------------------------------------------- 1 | # TODO Add custom metric to tract deployments 2 | # Define defaults that can be referenced below 3 | JH_Defaults: 4 | - &ElbMetric 5 | # Ex. name: 'cloudwatch.aws.elb.awseb-e-v-awsebloa-zelk76tu0gp.requestcount.sum.count' 6 | Namespace: "AWS/ELB" 7 | Dimensions: 8 | # You can have multiple dimensions, but boto will only return the last one 9 | LoadBalancerName: "awseb-e-v-AWSEBLoa-ZELK76TU0GP" 10 | Auth: 11 | region: "eu-west-1" 12 | Metrics: 13 | - <<: *ElbMetric 14 | MetricName: "RequestCount" 15 | Statistics: "Sum" 16 | Unit: "Count" 17 | # You can list additional metrics in one file. Just be careful about rate limits. 18 | - <<: *ElbMetric 19 | MetricName: "UnHealthyHostCount" 20 | Statistics: "Maximum" 21 | Unit: "Count" 22 | # You can list additional metrics in one file. Just be careful about rate limits. 23 | - <<: *ElbMetric 24 | MetricName: "Latency" 25 | Statistics: 26 | - "Average" 27 | - "Maximum" 28 | Unit: "Seconds" 29 | - <<: *ElbMetric 30 | MetricName: "HTTPCode_ELB_5XX" 31 | Statistics: "Sum" 32 | Unit: "Count" 33 | #- Namespace: "AWS/EC2" 34 | # MetricName: "CPUUtilization" 35 | # You can have multiple statistics too 36 | # Statistics: 37 | # - "Maximum" 38 | # - "Average" 39 | # Unit: "Percent" 40 | # Dimensions: 41 | # InstanceId: "i-14afebf3" # TODO and i-2a2262ce 42 | # OPTIONAL: set defaults for all metrics in this file 43 | Options: 44 | Count: 1 # How many Periods to return (note: there is a max datapoints you can get at once) 45 | Period: 5 # [min], minimum 1 46 | -------------------------------------------------------------------------------- /configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | if [ ! -f "/.grafana_configured" ]; then 6 | /set_grafana.sh 7 | fi 8 | 9 | if [ ! -f "/.influxdb_configured" ]; then 10 | /set_influxdb.sh 11 | fi 12 | exit 0 13 | -------------------------------------------------------------------------------- /configure_influxdb_at_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -d /var/easydeploy/share/db ]; then 4 | echo "No .../db, likely a freshly mounted Volume, copying initial InfluxDB data" 5 | cp -rT /var/infuxdb_initial_data_backup /var/easydeploy/share 6 | else 7 | echo "InfluxDB seems to be set up, skipping copying of data" 8 | fi 9 | -------------------------------------------------------------------------------- /grafana/config.js: -------------------------------------------------------------------------------- 1 | // == Configuration 2 | // config.js is where you will find the core Grafana configuration. This file contains parameter that 3 | // must be set before Grafana is run for the first time. 4 | 5 | define(['settings'], function(Settings) { 6 | 7 | 8 | return new Settings({ 9 | 10 | /* Data sources 11 | * ======================================================== 12 | * Datasources are used to fetch metrics, annotations, and serve as dashboard storage 13 | * - You can have multiple of the same type. 14 | * - grafanaDB: true marks it for use for dashboard storage 15 | * - default: true marks the datasource as the default metric source (if you have multiple) 16 | * - basic authentication: use url syntax http://username:password@domain:port 17 | */ 18 | 19 | // InfluxDB example setup (the InfluxDB databases specified need to exist) 20 | 21 | datasources: { 22 | data: { 23 | type: 'influxdb', 24 | url: "/db/data", 25 | username: '<--DATA_USER-->', 26 | password: '<--DATA_PW-->', 27 | }, 28 | grafana: { 29 | type: 'influxdb', 30 | url: "/db/grafana", 31 | username: '<--GRAFANA_USER-->', 32 | password: '<--GRAFANA_PW-->', 33 | grafanaDB: true 34 | }, 35 | }, 36 | 37 | /* Global configuration options 38 | * ======================================================== 39 | */ 40 | 41 | // specify the limit for dashboard search results 42 | search: { 43 | max_results: 100 44 | }, 45 | 46 | // default home dashboard 47 | default_route: '/dashboard/file/default.json', 48 | 49 | // set to false to disable unsaved changes warning 50 | unsaved_changes_warning: true, 51 | 52 | // set the default timespan for the playlist feature 53 | // Example: "1m", "1h" 54 | playlist_timespan: "1m", 55 | 56 | // If you want to specify password before saving, please specify it below 57 | // The purpose of this password is not security, but to stop some users from accidentally changing dashboards 58 | admin: { 59 | password: '' 60 | }, 61 | 62 | // Change window title prefix from 'Grafana - ' 63 | window_title_prefix: 'Grafana - ', 64 | 65 | // Add your own custom panels 66 | plugins: { 67 | // list of plugin panels 68 | panels: [], 69 | // requirejs modules in plugins folder that should be loaded 70 | // for example custom datasources 71 | dependencies: [], 72 | } 73 | 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /influxdb/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /influxdb/config.toml: -------------------------------------------------------------------------------- 1 | # Welcome to the InfluxDB configuration file. 2 | 3 | # If hostname (on the OS) doesn't return a name that can be resolved by the other 4 | # systems in the cluster, you'll have to set the hostname to an IP or something 5 | # that can be resolved here. 6 | # hostname = "" 7 | 8 | bind-address = "0.0.0.0" 9 | 10 | [logging] 11 | # logging level can be one of "debug", "info", "warn" or "error" 12 | level = "info" 13 | file = "/var/log/easydeploy/influxdb.log" # stdout to log to standard out 14 | 15 | # Configure the admin server 16 | [admin] 17 | port = 8083 # binding is disabled if the port isn't set 18 | assets = "./admin" 19 | 20 | # Configure the http api 21 | [api] 22 | port = 8086 # binding is disabled if the port isn't set 23 | # ssl-port = 8084 # SSL support is enabled if you set a port and cert 24 | # ssl-cert = "/path/to/cert.pem" 25 | 26 | # connections will timeout after this amount of time. Ensures that clients that misbehave 27 | # and keep alive connections they don't use won't end up connection a million times. 28 | # However, if a request is taking longer than this to complete, could be a problem. 29 | read-timeout = "5s" 30 | 31 | [input_plugins] 32 | 33 | # Configure the graphite api 34 | [input_plugins.graphite] 35 | enabled = true 36 | port = 2003 37 | database = "data" # store graphite data in this database 38 | 39 | # Raft configuration 40 | [raft] 41 | # The raft port should be open between all servers in a cluster. 42 | # However, this port shouldn't be accessible from the internet. 43 | 44 | port = 8090 45 | 46 | # Where the raft logs are stored. The user running InfluxDB will need read/write access. 47 | dir = "/var/easydeploy/share/raft" 48 | 49 | # election-timeout = "1s" 50 | 51 | [storage] 52 | dir = "/var/easydeploy/share/db" 53 | # How many requests to potentially buffer in memory. If the buffer gets filled then writes 54 | # will still be logged and once the local storage has caught up (or compacted) the writes 55 | # will be replayed from the WAL 56 | write-buffer-size = 10000 57 | 58 | [cluster] 59 | # A comma separated list of servers to seed 60 | # this server. this is only relevant when the 61 | # server is joining a new cluster. Otherwise 62 | # the server will use the list of known servers 63 | # prior to shutting down. Any server can be pointed to 64 | # as a seed. It will find the Raft leader automatically. 65 | 66 | # Here's an example. Note that the port on the host is the same as the raft port. 67 | # seed-servers = ["hosta:8090","hostb:8090"] 68 | 69 | # Replication happens over a TCP connection with a Protobuf protocol. 70 | # This port should be reachable between all servers in a cluster. 71 | # However, this port shouldn't be accessible from the internet. 72 | 73 | protobuf_port = 8099 74 | protobuf_timeout = "2s" # the write timeout on the protobuf conn any duration parseable by time.ParseDuration 75 | protobuf_heartbeat = "200ms" # the heartbeat interval between the servers. must be parseable by time.ParseDuration 76 | protobuf_min_backoff = "1s" # the minimum backoff after a failed heartbeat attempt 77 | protobuf_max_backoff = "10s" # the maximum backoff after a failed heartbeat attempt 78 | 79 | # How many write requests to potentially buffer in memory per server. If the buffer gets filled then writes 80 | # will still be logged and once the server has caught up (or come back online) the writes 81 | # will be replayed from the WAL 82 | write-buffer-size = 10000 83 | 84 | # the maximum number of responses to buffer from remote nodes, if the 85 | # expected number of responses exceed this number then querying will 86 | # happen sequentially and the buffer size will be limited to this 87 | # number 88 | max-response-buffer-size = 100000 89 | 90 | # When queries get distributed out to shards, they go in parallel. This means that results can get buffered 91 | # in memory since results will come in any order, but have to be processed in the correct time order. 92 | # Setting this higher will give better performance, but you'll need more memory. Setting this to 1 will ensure 93 | # that you don't need to buffer in memory, but you won't get the best performance. 94 | concurrent-shard-query-limit = 10 95 | 96 | [leveldb] 97 | 98 | # Maximum mmap open files, this will affect the virtual memory used by 99 | # the process 100 | max-open-files = 40 101 | 102 | # LRU cache size, LRU is used by leveldb to store contents of the 103 | # uncompressed sstables. You can use `m` or `g` prefix for megabytes 104 | # and gigabytes, respectively. 105 | lru-cache-size = "200m" 106 | 107 | # The default setting on this is 0, which means unlimited. Set this to something if you want to 108 | # limit the max number of open files. max-open-files is per shard so this * that will be max. 109 | max-open-shards = 0 110 | 111 | # The default setting is 100. This option tells how many points will be fetched from LevelDb before 112 | # they get flushed into backend. 113 | point-batch-size = 100 114 | 115 | # These options specify how data is sharded across the cluster. There are two 116 | # shard configurations that have the same knobs: short term and long term. 117 | # Any series that begins with a capital letter like Exceptions will be written 118 | # into the long term storage. Any series beginning with a lower case letter 119 | # like exceptions will be written into short term. The idea being that you 120 | # can write high precision data into short term and drop it after a couple 121 | # of days. Meanwhile, continuous queries can run downsampling on the short term 122 | # data and write into the long term area. 123 | [sharding] 124 | # how many servers in the cluster should have a copy of each shard. 125 | # this will give you high availability and scalability on queries 126 | replication-factor = 1 127 | 128 | [sharding.short-term] 129 | # each shard will have this period of time. Note that it's best to have 130 | # group by time() intervals on all queries be < than this setting. If they are 131 | # then the aggregate is calculated locally. Otherwise, all that data gets sent 132 | # over the network when doing a query. 133 | duration = "7d" 134 | 135 | # split will determine how many shards to split each duration into. For example, 136 | # if we created a shard for 2014-02-10 and split was set to 2. Then two shards 137 | # would be created that have the data for 2014-02-10. By default, data will 138 | # be split into those two shards deterministically by hashing the (database, series) 139 | # tuple. That means that data for a given series will be written to a single shard 140 | # making querying efficient. That can be overridden with the next option. 141 | split = 1 142 | 143 | # You can override the split behavior to have the data for series that match a 144 | # given regex be randomly distributed across the shards for a given interval. 145 | # You can use this if you have a hot spot for a given time series writing more 146 | # data than a single server can handle. Most people won't have to resort to this 147 | # option. Also note that using this option means that queries will have to send 148 | # all data over the network so they won't be as efficient. 149 | # split-random = "/^hf.*/" 150 | 151 | [sharding.long-term] 152 | duration = "30d" 153 | split = 1 154 | # split-random = "/^Hf.*/" 155 | 156 | [wal] 157 | 158 | dir = "/var/easydeploy/share/wal" 159 | flush-after = 1000 # the number of writes after which wal will be flushed, 0 for flushing on every write 160 | bookmark-after = 1000 # the number of writes after which a bookmark will be created 161 | 162 | # the number of writes after which an index entry is created pointing 163 | # to the offset of the first request, default to 1k 164 | index-after = 1000 165 | 166 | # the number of requests per one log file, if new requests came in a 167 | # new log file will be created 168 | requests-per-logfile = 10000 169 | -------------------------------------------------------------------------------- /influxdb/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -m 4 | 5 | CONFIG_FILE="/etc/influxdb/config.toml" 6 | 7 | echo "=> Starting InfluxDB ..." 8 | exec /usr/bin/influxdb -config=${CONFIG_FILE} 9 | -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | daemon off; 2 | user www-data; 3 | worker_processes 1; 4 | pid /var/run/nginx.pid; 5 | 6 | events { 7 | worker_connections 1024; 8 | } 9 | 10 | http { 11 | sendfile on; 12 | tcp_nopush on; 13 | tcp_nodelay on; 14 | keepalive_timeout 65; 15 | types_hash_max_size 2048; 16 | server_tokens off; 17 | 18 | server_names_hash_bucket_size 32; 19 | 20 | include /etc/nginx/mime.types; 21 | default_type application/octet-stream; 22 | 23 | access_log /var/log/nginx/access.log; 24 | error_log /var/log/nginx/error.log; 25 | 26 | gzip on; 27 | gzip_disable "msie6"; 28 | 29 | upstream influxdb { 30 | server 127.0.0.1:8086; 31 | } 32 | 33 | server { 34 | listen 80 default_server; 35 | server_name _; 36 | location /db { 37 | proxy_pass http://influxdb; 38 | } 39 | location / { 40 | root /src/grafana; 41 | index index.html; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /nginx/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -m 4 | 5 | echo "=> Starting ngnix ..." 6 | exec /usr/sbin/nginx 7 | -------------------------------------------------------------------------------- /set_grafana.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ -f /.grafana_configured ]; then 5 | echo "=> grafana has been configured!" 6 | exit 0 7 | fi 8 | 9 | echo "=> Configuring grafana" 10 | sed -i -e "s/<--DATA_USER-->/${INFLUXDB_DATA_USER}/g" \ 11 | -e "s/<--DATA_PW-->/${INFLUXDB_DATA_PW}/g" \ 12 | -e "s/<--GRAFANA_USER-->/${INFLUXDB_GRAFANA_USER}/g" \ 13 | -e "s/<--GRAFANA_PW-->/${INFLUXDB_GRAFANA_PW}/g" /src/grafana/config.js 14 | 15 | touch /.grafana_configured 16 | 17 | echo "=> Grafana has been configured as follows:" 18 | echo " InfluxDB DB DATA NAME: data" 19 | echo " InfluxDB USERNAME: ${INFLUXDB_DATA_USER}" 20 | echo " InfluxDB PASSWORD: ${INFLUXDB_DATA_PW}" 21 | echo " InfluxDB DB GRAFANA NAME: grafana" 22 | echo " InfluxDB USERNAME: ${INFLUXDB_GRAFANA_USER}" 23 | echo " InfluxDB PASSWORD: ${INFLUXDB_GRAFANA_USER}" 24 | echo " ** Please check your environment variables if you find something is misconfigured. **" 25 | echo "=> Done!" 26 | exit 0 27 | -------------------------------------------------------------------------------- /set_influxdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -m 4 | CONFIG_FILE="/etc/influxdb/config.toml" 5 | 6 | API_URL="http://localhost:8086" 7 | 8 | #if [ -n "${FORCE_HOSTNAME}" ]; then 9 | # if [ "${FORCE_HOSTNAME}" == "auto" ]; then 10 | # #set hostname with IPv4 eth0 11 | # HOSTIPNAME=$(ip a show dev eth0 | grep inet | grep eth0 | sed -e 's/^.*inet.//g' -e 's/\/.*$//g') 12 | # /usr/bin/perl -p -i -e "s/^# hostname.*$/hostname = \"${HOSTIPNAME}\"/g" ${CONFIG_FILE} 13 | # else 14 | # /usr/bin/perl -p -i -e "s/^# hostname.*$/hostname = \"${FORCE_HOSTNAME}\"/g" ${CONFIG_FILE} 15 | # fi 16 | #fi 17 | # 18 | #if [ -n "${SEEDS}" ]; then 19 | # /usr/bin/perl -p -i -e "s/^# seed-servers.*$/seed-servers = [${SEEDS}]/g" ${CONFIG_FILE} 20 | #fi 21 | # 22 | #if [ -n "${REPLI_FACTOR}" ]; then 23 | # /usr/bin/perl -p -i -e "s/replication-factor = 1/replication-factor = ${REPLI_FACTOR}/g" ${CONFIG_FILE} 24 | #fi 25 | # 26 | #if [ "${PRE_CREATE_DB}" == "**None**" ]; then 27 | # unset PRE_CREATE_DB 28 | #fi 29 | # 30 | #if [ "${SSL_CERT}" == "**None**" ]; then 31 | # unset SSL_CERT 32 | #fi 33 | # 34 | #API_URL="http://localhost:8086" 35 | #if [ -n "${SSL_CERT}" ]; then 36 | # echo "=> Found ssl cert file, using ssl api instead" 37 | # echo "=> Listening on port 8084(https api), disabling port 8086(http api)" 38 | # echo -e "${SSL_CERT}" > /cert.pem 39 | # sed -i -r -e 's/^# ssl-/ssl-/g' -e 's/^port *= * 8086/# port = 8086/' ${CONFIG_FILE} 40 | # API_URL="https://localhost:8084" 41 | #fi 42 | 43 | echo "=> About to create the following database: ${PRE_CREATE_DB}" 44 | if [ -f "/.influxdb_configured" ]; then 45 | echo "=> Database had been created before, skipping ..." 46 | else 47 | echo "=> Starting InfluxDB ..." 48 | exec /usr/bin/influxdb -config=${CONFIG_FILE} & 49 | arr=$(echo ${PRE_CREATE_DB} | tr ";" "\n") 50 | 51 | #wait for the startup of influxdb 52 | RET=1 53 | while [[ RET -ne 0 ]]; do 54 | echo "=> Waiting for confirmation of InfluxDB service startup ..." 55 | sleep 3 56 | curl -k ${API_URL}/ping 2> /dev/null 57 | RET=$? 58 | done 59 | echo "" 60 | 61 | for x in $arr 62 | do 63 | echo "=> Creating database: ${x}" 64 | curl -s -k -X POST -d "{\"name\":\"${x}\"}" $(echo ${API_URL}'/db?u=root&p=root') 65 | done 66 | echo "" 67 | 68 | echo "=> Creating User for database: data" 69 | curl -s -k -X POST -d "{\"name\":\"${INFLUXDB_DATA_USER}\",\"password\":\"${INFLUXDB_DATA_PW}\"}" $(echo ${API_URL}'/db/data/users?u=root&p=root') 70 | echo "=> Creating User for database: grafana" 71 | curl -s -k -X POST -d "{\"name\":\"${INFLUXDB_GRAFANA_USER}\",\"password\":\"${INFLUXDB_GRAFANA_PW}\"}" $(echo ${API_URL}'/db/grafana/users?u=root&p=root') 72 | echo "" 73 | 74 | echo "=> Changing Password for User: root" 75 | curl -s -k -X POST -d "{\"password\":\"${ROOT_PW}\"}" $(echo ${API_URL}'/cluster_admins/root?u=root&p=root') 76 | echo "" 77 | 78 | touch "/.influxdb_configured" 79 | exit 0 80 | fi 81 | 82 | exit 0 83 | -------------------------------------------------------------------------------- /start: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | docker stop grafana-influxdb_con &>/dev/null 4 | docker rm grafana-influxdb_con &>/dev/null 5 | 6 | ## Linux: 7 | #docker run -d -v /etc/localtime:/etc/localtime:ro -p 80:80 -p 8083:8083 -p 8084:8084 -p 8086:8086 --name grafana-influxdb_con monitoring3 8 | ## OS X: 9 | # 10 | docker run -e AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" -e AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" -d -p 80:80 -p 8083:8083 -p 8084:8084 -p 8086:8086 --name grafana-influxdb_con grafana_influxdb 11 | #-v $PWD/vol_data:/var/easydeploy/share # BROKEN under OS X due to boot2docker/VirtualBox & permission on mounts issues 12 | -------------------------------------------------------------------------------- /stop: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | docker stop grafana-influxdb_con 4 | docker rm grafana-influxdb_con 5 | -------------------------------------------------------------------------------- /utils/leadbutt2influxdb.clj: -------------------------------------------------------------------------------- 1 | ;; A script to read output from cloudwatch-to-graphite's leadbutt 2 | ;; and convert it into a JSON suitable for InfluxDB 3 | ;; Usage: 4 | ;; lein exec leadbutt2json.clj leadbutt.output # => leadbutt.output.out.json 5 | ;; curl -X POST -ind @leadbutt.output.out.json "http://your.influxdb.api/db/data/series?time_precision=s" 6 | ;; (provided there is a DB called 'data' and you have your username+password in ~/.netrc) 7 | 8 | (try (require '[leiningen.exec :as exec]) 9 | (when @(ns-resolve 'leiningen.exec '*running?*) 10 | (leiningen.exec/deps '[[org.clojure/data.csv "0.1.2"] 11 | [org.clojure/data.json "0.2.6"]])) 12 | (catch java.io.FileNotFoundException e)) 13 | 14 | (ns leadbutt-2-json.core 15 | (:require [clojure.data.csv :as csv] 16 | [clojure.data.json :as json] 17 | [clojure.java.io :as io])) 18 | 19 | 20 | (defn read-csv [in-file-name] 21 | (print "Reading" in-file-name "...") 22 | (with-open [in-file (clojure.java.io/reader in-file-name)] 23 | (doall 24 | (csv/read-csv in-file :separator \ )))) 25 | 26 | (defn mk-series [[name points]] 27 | {:name name 28 | :columns ["value" "time"] 29 | :points points}) 30 | 31 | (defn format-values [values] ;; [ [name value time] ... ] 32 | (->> values 33 | (map rest) 34 | (map (fn [[val time]] [(Double/parseDouble val) (Integer/parseInt time)])))) 35 | 36 | (defn format-data [data] 37 | (->> data 38 | (group-by first) 39 | (reduce-kv (fn [acc k vs] 40 | (assoc acc k 41 | (format-values vs))) {}) 42 | (seq) 43 | (map mk-series))) 44 | 45 | (defn write-json [out-file data] 46 | (print "Writing" out-file "...") 47 | (with-open [out (io/writer out-file)] 48 | (comment binding [*out* out] 49 | (json/pprint data)) 50 | (json/write data out))) 51 | 52 | (defn -main [in-file] 53 | (->> (read-csv in-file) 54 | (format-data) 55 | (write-json (str in-file ".out.json")))) 56 | 57 | ;; lein-exec support 58 | (try (require 'leiningen.exec) 59 | (when @(ns-resolve 'leiningen.exec '*running?*) 60 | (apply -main (rest *command-line-args*))) 61 | (catch java.io.FileNotFoundException e)) 62 | --------------------------------------------------------------------------------