├── LICENSE ├── README.md ├── Rakefile ├── carbon-base └── Dockerfile ├── carbon-cache ├── Dockerfile ├── config │ ├── carbon.conf │ ├── storage-aggregation.conf │ └── storage-schemas.conf └── run.sh ├── carbon-relay ├── Dockerfile ├── config │ ├── carbon.conf │ ├── relay-rules.conf │ ├── storage-aggregation.conf │ └── storage-schemas.conf └── run.sh ├── docker-compose.yml ├── haproxy ├── Dockerfile └── haproxy.cfg ├── test ├── Dockerfile ├── Gemfile ├── Gemfile.lock └── spec │ ├── graphite_spec.rb │ └── spec_helper.rb └── web ├── Dockerfile └── config ├── initial_data.json ├── local_settings.py ├── nginx.conf └── supervisord.conf /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 | # Graphite Setup 2 | 3 | This reposistory is for images of graphite and the associated carbon daemons: carbon-cache and carbon-relay. It represents what we believe to be the best practices for running a graphite cluster. 4 | 5 | ## Docker Hub locations 6 | 7 | [banno/carbon-base](https://registry.hub.docker.com/u/banno/carbon-base/) 8 | 9 | [banno/carbon-relay](https://registry.hub.docker.com/u/banno/carbon-relay/) 10 | 11 | [banno/carbon-cache](https://registry.hub.docker.com/u/banno/carbon-cache/) 12 | 13 | [banno/graphite-web](https://registry.hub.docker.com/u/banno/graphite-web/) 14 | 15 | ## Build 16 | 17 | - docker and docker-compose must be installed 18 | - `rake -T` will explain most everything 19 | 20 | ## Example docker-compose.yml 21 | 22 | The [docker-compose.yml][] file is an example of a multi-node graphite cluster with each node running mulitple `carbon-cache`s. It's described on [Clustering Graphite - bitprophet.org](http://bitprophet.org/blog/2013/03/07/graphite/) as the "Multiple nodes, multiple caches on each, multiple relays". 23 | 24 | In the [docker-compose.yml][] example, pretend there are two "nodes" `a` and `b`. 25 | 26 | Each of those hosts is running: 27 | - one `carbon-relay` eg `relaya` and `relayb`. Each `carbon-relay` is pointed at the `carbon-cache`s running on the same "node". It is using `consistent-hashing` for the relay method. 28 | - two `carbon-cache`s: e.g. `cachea1`,`cachea2`,`cacheb1`,`cacheb2`. There should be a `carbon-cache` per core. 29 | - one `graphite-web`: e.g. `weba` and `webb`. Each `graphite-web` is only pointed at the `carbon-relay` running on the same "node". 30 | 31 | We then run a separate `web` pointed at `weba` and `webb` and a "top" `carbon-relay` pointed at `relaya` and `relayb`. 32 | 33 | ## Contributing 34 | 35 | Fork away, commit, and send a pull request. 36 | 37 | [docker-compose.yml]: ./docker-compose.yml 38 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | banno_version = "banno-0.1.0" 2 | graphite_version = File.read("./carbon-base/Dockerfile").scan(/ENV GRAPHITE_VERSION ([0-9\.]+)/m)[0][0] 3 | 4 | ## Builders 5 | desc "Builds all docker images" 6 | task :build => ["build:base", "build:cache", "build:web", "build:relay", "build:haproxy"] 7 | 8 | namespace :build do 9 | desc "Build the base image" 10 | task :base do 11 | sh "docker build -t banno/carbon-base:#{graphite_version}-#{banno_version} carbon-base" 12 | sh "docker tag banno/carbon-base:#{graphite_version}-#{banno_version} banno/carbon-base:latest" 13 | end 14 | 15 | desc "Build the cache image" 16 | task :cache do 17 | sh "docker build -t banno/carbon-cache:#{graphite_version}-#{banno_version} carbon-cache" 18 | sh "docker tag banno/carbon-cache:#{graphite_version}-#{banno_version} banno/carbon-cache:latest" 19 | end 20 | 21 | desc "Build the web image" 22 | task :web do 23 | sh "docker build -t banno/graphite-web:#{graphite_version}-#{banno_version} web" 24 | sh "docker tag banno/graphite-web:#{graphite_version}-#{banno_version} banno/graphite-web:latest" 25 | end 26 | 27 | desc "Build the relay image" 28 | task :relay do 29 | sh "docker build -t banno/carbon-relay:#{graphite_version}-#{banno_version} carbon-relay" 30 | sh "docker tag banno/carbon-relay:#{graphite_version}-#{banno_version} banno/carbon-relay:latest" 31 | end 32 | 33 | desc "Build haproxy proxy" 34 | task :haproxy do 35 | sh "docker build -t banno/graphite-haproxy:#{graphite_version}-#{banno_version} haproxy" 36 | sh "docker tag banno/graphite-haproxy:#{graphite_version}-#{banno_version} banno/graphite-haproxy:latest" 37 | end 38 | end 39 | 40 | desc "Push all images to registry" 41 | task :push do 42 | sh "docker push banno/carbon-base:#{graphite_version}-#{banno_version}" 43 | sh "docker push banno/carbon-cache:#{graphite_version}-#{banno_version}" 44 | sh "docker push banno/carbon-relay:#{graphite_version}-#{banno_version}" 45 | sh "docker push banno/graphite-web:#{graphite_version}-#{banno_version}" 46 | sh "docker push banno/graphite-haproxy:#{graphite_version}-#{banno_version}" 47 | end 48 | 49 | ## testing 50 | 51 | desc "Start up the containers, daemonized" 52 | task :up do 53 | sh "docker-compose up -d" 54 | end 55 | 56 | desc "Kill the containers" 57 | task :kill do 58 | sh "docker-compose kill" 59 | sh "docker-compose rm --force" 60 | end 61 | 62 | desc "Roll the containers" 63 | task :roll do 64 | sh "docker-compose kill" 65 | sh "docker-compose rm --force" 66 | sh "docker-compose up -d" 67 | end 68 | 69 | desc "Build test image and run rspec tests" 70 | task :test do 71 | sh "docker-compose build test" 72 | sh "docker-compose run test" 73 | end 74 | 75 | desc "Write data to carbon" 76 | task :write_data do 77 | now = Time.now.to_i 78 | (1..1000000).step(50).each do |offset| 79 | stamp = now - offset 80 | sh % 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /carbon-base/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | 3 | # also, depends on https://github.com/graphite-project/carbon/pull/486 4 | # once 0.9.16 is released, no need for special carbon install belos 5 | ENV GRAPHITE_VERSION 0.9.15 6 | 7 | RUN apt-get update && \ 8 | apt-get -y install python-dev python-pip 9 | 10 | 11 | RUN pip install whisper==$GRAPHITE_VERSION && \ 12 | pip install https://github.com/Banno/carbon/tarball/0.9.x-fix-events-callback && \ 13 | pip install graphite-web==$GRAPHITE_VERSION 14 | -------------------------------------------------------------------------------- /carbon-cache/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM banno/carbon-base 2 | 3 | ENV NODE_NAME cache 4 | ENV LOCAL_DATA_DIR /opt/graphite/storage/whisper/ 5 | ENV MAX_CACHE_SIZE inf 6 | ENV MAX_UPDATES_PER_SECOND 1000 7 | ENV MAX_CREATES_PER_MINUTE inf 8 | ENV LOG_UPDATES False 9 | ENV LINE_RECEIVER_INTERFACE 0.0.0.0 10 | ENV PICKLE_RECEIVER_INTERFACE 0.0.0.0 11 | ENV CACHE_QUERY_INTERFACE 0.0.0.0 12 | ENV LINE_RECEIVER_PORT 2003 13 | ENV PICKLE_RECEIVER_PORT 2004 14 | ENV CACHE_QUERY_PORT 7002 15 | 16 | ADD ./config /opt/graphite/conf/ 17 | ADD run.sh /opt/graphite/ 18 | 19 | EXPOSE 2003 2004 7002 20 | 21 | WORKDIR /opt/graphite 22 | 23 | ENTRYPOINT ["./run.sh"] 24 | -------------------------------------------------------------------------------- /carbon-cache/config/carbon.conf: -------------------------------------------------------------------------------- 1 | [cache] 2 | LOCAL_DATA_DIR = 3 | MAX_CACHE_SIZE = 4 | MAX_UPDATES_PER_SECOND = 5 | MAX_CREATES_PER_MINUTE = 6 | LOG_UPDATES = 7 | 8 | LINE_RECEIVER_INTERFACE = 9 | PICKLE_RECEIVER_INTERFACE = 10 | CACHE_QUERY_INTERFACE = 11 | LINE_RECEIVER_PORT = 12 | PICKLE_RECEIVER_PORT = 13 | CACHE_QUERY_PORT = -------------------------------------------------------------------------------- /carbon-cache/config/storage-aggregation.conf: -------------------------------------------------------------------------------- 1 | [min] 2 | pattern = \.min$ 3 | xFilesFactor = 0.1 4 | aggregationMethod = min 5 | 6 | [max] 7 | pattern = \.max$ 8 | xFilesFactor = 0.1 9 | aggregationMethod = max 10 | 11 | [sum] 12 | pattern = \.count$ 13 | xFilesFactor = 0 14 | aggregationMethod = sum 15 | 16 | [default_average] 17 | pattern = .* 18 | xFilesFactor = 0 19 | aggregationMethod = average 20 | -------------------------------------------------------------------------------- /carbon-cache/config/storage-schemas.conf: -------------------------------------------------------------------------------- 1 | [carbon] 2 | pattern = ^carbon\..* 3 | retentions = 1m:31d,10m:1y 4 | 5 | [highres] 6 | pattern = ^highres.* 7 | retentions = 1s:1d,1m:7d 8 | 9 | [statsd] 10 | pattern = ^statsd.* 11 | retentions = 1m:7d,10m:1y 12 | 13 | [default] 14 | pattern = .* 15 | retentions = 1m:30d,5m:1y 16 | -------------------------------------------------------------------------------- /carbon-cache/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sed -i -e "s/\[cache\]/\[${NODE_NAME}\]/g" ./conf/carbon.conf 4 | sed -i -e "s/\(LOCAL_DATA_DIR\).*$/\1 = $(printf "${LOCAL_DATA_DIR}" | sed -e 's/\//\\\//g')/g" ./conf/carbon.conf 5 | sed -i -e "s/\(MAX_CACHE_SIZE\).*$/\1 = ${MAX_CACHE_SIZE}/g" ./conf/carbon.conf 6 | sed -i -e "s/\(MAX_UPDATES_PER_SECOND\).*$/\1 = ${MAX_UPDATES_PER_SECOND}/g" ./conf/carbon.conf 7 | sed -i -e "s/\(MAX_CREATES_PER_MINUTE\).*$/\1 = ${MAX_CREATES_PER_MINUTE}/g" ./conf/carbon.conf 8 | sed -i -e "s/\(LOG_UPDATES\).*$/\1 = ${LOG_UPDATES}/g" ./conf/carbon.conf 9 | sed -i -e "s/\(LINE_RECEIVER_INTERFACE\).*$/\1 = ${LINE_RECEIVER_INTERFACE}/g" ./conf/carbon.conf 10 | sed -i -e "s/\(PICKLE_RECEIVER_INTERFACE\).*$/\1 = ${PICKLE_RECEIVER_INTERFACE}/g" ./conf/carbon.conf 11 | sed -i -e "s/\(CACHE_QUERY_INTERFACE\).*$/\1 = ${CACHE_QUERY_INTERFACE}/g" ./conf/carbon.conf 12 | sed -i -e "s/\(LINE_RECEIVER_PORT\).*$/\1 = ${LINE_RECEIVER_PORT}/g" ./conf/carbon.conf 13 | sed -i -e "s/\(PICKLE_RECEIVER_PORT\).*$/\1 = ${PICKLE_RECEIVER_PORT}/g" ./conf/carbon.conf 14 | sed -i -e "s/\(CACHE_QUERY_PORT\).*$/\1 = ${CACHE_QUERY_PORT}/g" ./conf/carbon.conf 15 | 16 | /opt/graphite/bin/carbon-cache.py --debug "$@" start 17 | -------------------------------------------------------------------------------- /carbon-relay/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM banno/carbon-base 2 | 3 | ENV NODE_NAME relay 4 | ENV LOCAL_DATA_DIR /opt/graphite/storage/whisper/ 5 | ENV MAX_CACHE_SIZE inf 6 | ENV MAX_UPDATES_PER_SECOND 1000 7 | ENV MAX_CREATES_PER_MINUTE inf 8 | ENV LOG_UPDATES False 9 | ENV LINE_RECEIVER_INTERFACE 0.0.0.0 10 | ENV PICKLE_RECEIVER_INTERFACE 0.0.0.0 11 | ENV CACHE_QUERY_INTERFACE 0.0.0.0 12 | ENV LINE_RECEIVER_PORT 2003 13 | ENV PICKLE_RECEIVER_PORT 2004 14 | ENV CACHE_QUERY_PORT 7002 15 | ENV REPLICATION_FACTOR 1 16 | 17 | ADD ./config /opt/graphite/conf/ 18 | ADD run.sh /opt/graphite/ 19 | 20 | EXPOSE 2003 2004 7002 21 | 22 | WORKDIR /opt/graphite 23 | 24 | ENTRYPOINT ["./run.sh"] 25 | -------------------------------------------------------------------------------- /carbon-relay/config/carbon.conf: -------------------------------------------------------------------------------- 1 | [relay] 2 | LINE_RECEIVER_INTERFACE = 3 | LINE_RECEIVER_PORT = 4 | PICKLE_RECEIVER_INTERFACE = 5 | PICKLE_RECEIVER_PORT = 6 | RELAY_METHOD = 7 | DESTINATIONS = 8 | REPLICATION_FACTOR = 9 | -------------------------------------------------------------------------------- /carbon-relay/config/relay-rules.conf: -------------------------------------------------------------------------------- 1 | [default] 2 | default = true 3 | destinations = 172.17.42.1:2014:1, 172.17.42.1:2024:2, 172.17.42.1:2034:3 4 | -------------------------------------------------------------------------------- /carbon-relay/config/storage-aggregation.conf: -------------------------------------------------------------------------------- 1 | [min] 2 | pattern = \.min$ 3 | xFilesFactor = 0.1 4 | aggregationMethod = min 5 | 6 | [max] 7 | pattern = \.max$ 8 | xFilesFactor = 0.1 9 | aggregationMethod = max 10 | 11 | [sum] 12 | pattern = \.count$ 13 | xFilesFactor = 0 14 | aggregationMethod = sum 15 | 16 | [default_average] 17 | pattern = .* 18 | xFilesFactor = 0 19 | aggregationMethod = average 20 | -------------------------------------------------------------------------------- /carbon-relay/config/storage-schemas.conf: -------------------------------------------------------------------------------- 1 | [carbon] 2 | pattern = ^carbon\..* 3 | retentions = 1m:31d,10m:1y,1h:5y 4 | 5 | [highres] 6 | pattern = ^highres.* 7 | retentions = 1s:1d,1m:7d 8 | 9 | [statsd] 10 | pattern = ^statsd.* 11 | retentions = 1m:7d,10m:1y 12 | 13 | [default] 14 | pattern = .* 15 | retentions = 1m:30d,5m:1y 16 | -------------------------------------------------------------------------------- /carbon-relay/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sed -i -e "s/\[cache\]/\[${NODE_NAME}\]/g" ./conf/carbon.conf 4 | sed -i -e "s/\(LINE_RECEIVER_INTERFACE\).*$/\1 = ${LINE_RECEIVER_INTERFACE}/g" ./conf/carbon.conf 5 | sed -i -e "s/\(LINE_RECEIVER_PORT\).*$/\1 = ${LINE_RECEIVER_PORT}/g" ./conf/carbon.conf 6 | sed -i -e "s/\(PICKLE_RECEIVER_INTERFACE\).*$/\1 = ${PICKLE_RECEIVER_INTERFACE}/g" ./conf/carbon.conf 7 | sed -i -e "s/\(PICKLE_RECEIVER_PORT\).*$/\1 = ${PICKLE_RECEIVER_PORT}/g" ./conf/carbon.conf 8 | sed -i -e "s/\(RELAY_METHOD\).*$/\1 = ${RELAY_METHOD}/g" ./conf/carbon.conf 9 | sed -i -e "s/\(DESTINATIONS\).*$/\1 = ${DESTINATIONS}/g" ./conf/carbon.conf 10 | sed -i -e "s/\(REPLICATION_FACTOR\).*$/\1 = ${REPLICATION_FACTOR}/g" ./conf/carbon.conf 11 | 12 | /opt/graphite/bin/carbon-relay.py --debug "$@" start 13 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | haproxy: 2 | image: banno/graphite-haproxy 3 | net: host 4 | 5 | web: 6 | image: banno/graphite-web 7 | environment: 8 | CLUSTER_SERVERS: weba:80,webb:80 9 | ports: 10 | - "8080:80" 11 | links: 12 | - weba 13 | - webb 14 | 15 | relay: 16 | image: banno/carbon-relay 17 | ports: 18 | - "3003:2003" 19 | - "3004:2004" 20 | environment: 21 | RELAY_METHOD: consistent-hashing 22 | DESTINATIONS: relaya:2104, relayb:2204 23 | links: 24 | - relaya 25 | - relayb 26 | 27 | weba: 28 | image: banno/graphite-web 29 | volumes_from: 30 | - whisper 31 | environment: 32 | CARBONLINK_HOSTS: cachea1:7012,cachea2:7022 33 | WHISPER_DIR: /opt/graphite/storage/whispera 34 | ports: 35 | - "8180:80" 36 | links: 37 | - cachea1 38 | - cachea2 39 | 40 | relaya: 41 | image: banno/carbon-relay 42 | ports: 43 | - "2103:2103" 44 | - "2104:2104" 45 | environment: 46 | LINE_RECEIVER_PORT: 2103 47 | PICKLE_RECEIVER_PORT: 2104 48 | RELAY_METHOD: consistent-hashing 49 | DESTINATIONS: cachea1:2014:a1, cachea2:2024:a2 50 | links: 51 | - cachea1 52 | - cachea2 53 | 54 | cachea1: 55 | image: banno/carbon-cache 56 | volumes_from: 57 | - whisper 58 | ports: 59 | - "7012:7012" 60 | - "2013:2013" 61 | - "2014:2014" 62 | environment: 63 | NODE_NAME: cache:a1 64 | LINE_RECEIVER_PORT: 2013 65 | PICKLE_RECEIVER_PORT: 2014 66 | CACHE_QUERY_PORT: 7012 67 | LOCAL_DATA_DIR: /opt/graphite/storage/whispera 68 | command: --instance=a1 69 | 70 | cachea2: 71 | image: banno/carbon-cache 72 | volumes_from: 73 | - whisper 74 | ports: 75 | - "7022:7022" 76 | - "2023:2023" 77 | - "2024:2024" 78 | environment: 79 | NODE_NAME: cache:a2 80 | LINE_RECEIVER_PORT: 2023 81 | PICKLE_RECEIVER_PORT: 2024 82 | CACHE_QUERY_PORT: 7022 83 | LOCAL_DATA_DIR: /opt/graphite/storage/whispera 84 | command: --instance=a2 85 | 86 | webb: 87 | image: banno/graphite-web 88 | volumes_from: 89 | - whisper 90 | environment: 91 | CARBONLINK_HOSTS: cacheb1:7112,cacheb2:7122 92 | WHISPER_DIR: /opt/graphite/storage/whisperb 93 | ports: 94 | - "8280:80" 95 | links: 96 | - cacheb1 97 | - cacheb2 98 | 99 | relayb: 100 | image: banno/carbon-relay 101 | ports: 102 | - "2203:2203" 103 | - "2204:2204" 104 | environment: 105 | LINE_RECEIVER_PORT: 2203 106 | PICKLE_RECEIVER_PORT: 2204 107 | RELAY_METHOD: consistent-hashing 108 | DESTINATIONS: cacheb1:2114:b1, cacheb2:2124:b2 109 | links: 110 | - cacheb1 111 | - cacheb2 112 | 113 | cacheb1: 114 | image: banno/carbon-cache 115 | volumes_from: 116 | - whisper 117 | ports: 118 | - "7112:7112" 119 | - "2113:2113" 120 | - "2114:2114" 121 | environment: 122 | NODE_NAME: cache:b1 123 | LINE_RECEIVER_PORT: 2113 124 | PICKLE_RECEIVER_PORT: 2114 125 | CACHE_QUERY_PORT: 7112 126 | LOCAL_DATA_DIR: /opt/graphite/storage/whisperb 127 | command: --instance=b1 128 | 129 | cacheb2: 130 | image: banno/carbon-cache 131 | volumes_from: 132 | - whisper 133 | ports: 134 | - "7122:7122" 135 | - "2123:2123" 136 | - "2124:2124" 137 | environment: 138 | NODE_NAME: cache:b2 139 | LINE_RECEIVER_PORT: 2123 140 | PICKLE_RECEIVER_PORT: 2124 141 | CACHE_QUERY_PORT: 7122 142 | LOCAL_DATA_DIR: /opt/graphite/storage/whisperb 143 | command: --instance=b2 144 | 145 | whisper: 146 | image: busybox 147 | volumes: 148 | - /tmp/whispera:/opt/graphite/storage/whispera 149 | - /tmp/whisperb:/opt/graphite/storage/whisperb 150 | 151 | test: 152 | build: ./test 153 | links: 154 | - web 155 | - relay 156 | volumes_from: 157 | - whisper 158 | -------------------------------------------------------------------------------- /haproxy/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM haproxy:1.5 2 | 3 | RUN groupadd haproxy && useradd -g haproxy haproxy 4 | RUN mkdir /var/lib/haproxy 5 | 6 | COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg 7 | -------------------------------------------------------------------------------- /haproxy/haproxy.cfg: -------------------------------------------------------------------------------- 1 | global 2 | log 127.0.0.1 local0 3 | log 127.0.0.1 local1 notice 4 | chroot /var/lib/haproxy 5 | user root 6 | group root 7 | stats socket /tmp/haproxy-stats 8 | 9 | defaults 10 | log global 11 | mode http 12 | option httplog 13 | option dontlognull 14 | option forwardfor 15 | option httpclose 16 | timeout connect 120s 17 | timeout client 120s 18 | timeout server 120s 19 | 20 | frontend http 21 | bind *:8000 22 | 23 | use_backend haproxy-stats 24 | 25 | backend haproxy-stats 26 | stats enable 27 | stats uri / 28 | 29 | listen relay2003 *:2003 30 | mode tcp 31 | option tcplog 32 | balance roundrobin 33 | server relay2003 localhost:3003 check 34 | 35 | listen relay2004 *:2004 36 | mode tcp 37 | option tcplog 38 | balance roundrobin 39 | server relay2004 localhost:3004 check 40 | -------------------------------------------------------------------------------- /test/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.1-onbuild 2 | CMD /bin/bash -c "bundle exec rspec" 3 | -------------------------------------------------------------------------------- /test/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "serverspec" 4 | gem "graphite-api" 5 | gem "faraday" 6 | -------------------------------------------------------------------------------- /test/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | diff-lcs (1.2.5) 5 | eventmachine (1.0.7) 6 | faraday (0.9.1) 7 | multipart-post (>= 1.2, < 3) 8 | graphite-api (0.1.5) 9 | eventmachine (>= 0.3.3) 10 | zscheduler (>= 0.0.3) 11 | multi_json (1.11.0) 12 | multipart-post (2.0.0) 13 | net-scp (1.2.1) 14 | net-ssh (>= 2.6.5) 15 | net-ssh (2.9.2) 16 | rspec (3.2.0) 17 | rspec-core (~> 3.2.0) 18 | rspec-expectations (~> 3.2.0) 19 | rspec-mocks (~> 3.2.0) 20 | rspec-core (3.2.2) 21 | rspec-support (~> 3.2.0) 22 | rspec-expectations (3.2.0) 23 | diff-lcs (>= 1.2.0, < 2.0) 24 | rspec-support (~> 3.2.0) 25 | rspec-its (1.2.0) 26 | rspec-core (>= 3.0.0) 27 | rspec-expectations (>= 3.0.0) 28 | rspec-mocks (3.2.1) 29 | diff-lcs (>= 1.2.0, < 2.0) 30 | rspec-support (~> 3.2.0) 31 | rspec-support (3.2.2) 32 | serverspec (2.14.0) 33 | multi_json 34 | rspec (~> 3.0) 35 | rspec-its 36 | specinfra (~> 2.25) 37 | specinfra (2.27.0) 38 | net-scp 39 | net-ssh 40 | zscheduler (0.0.6) 41 | eventmachine 42 | 43 | PLATFORMS 44 | ruby 45 | 46 | DEPENDENCIES 47 | faraday 48 | graphite-api 49 | serverspec 50 | -------------------------------------------------------------------------------- /test/spec/graphite_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'graphite' do 4 | it 'accepts data' do 5 | client = GraphiteAPI.new( graphite: 'relay:2003' ) 6 | expect(client.metrics("test.serverspec" => 1).size).to eq 1 7 | end 8 | 9 | it 'writes the data to whisper' do 10 | client = GraphiteAPI.new( graphite: 'relay:2003' ) 11 | for i in 1..2 do 12 | client.metrics("test.serverspec" => 1) 13 | sleep 30 14 | end 15 | sleep 5 16 | expect(file('/opt/graphite/storage/whispera/test/serverspec.wsp')).to be_file 17 | expect(file('/opt/graphite/storage/whisperb/test/serverspec.wsp')).to_not be_file 18 | end 19 | 20 | it 'hashes keys to different carbon nodes' do 21 | client = GraphiteAPI.new( graphite: 'relay:2003' ) 22 | client.metrics("test.serverspectest" => 1) 23 | sleep 5 24 | expect(file('/opt/graphite/storage/whispera/test/serverspectest.wsp')).to_not be_file 25 | expect(file('/opt/graphite/storage/whisperb/test/serverspectest.wsp')).to be_file 26 | end 27 | 28 | it 'allows data retrieval' do 29 | conn = Faraday.new(:url => "http://web") do |faraday| 30 | faraday.adapter Faraday.default_adapter 31 | end 32 | datapoints = JSON.parse(conn.get('/render?&target=test.serverspec&from=-2min&rawData=true&format=json').body).first['datapoints'].map {|k| k.first} 33 | unique_datapoints = datapoints.to_set.size 34 | expect(unique_datapoints).to be > 1 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /test/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | require 'graphite-api' 3 | require 'faraday' 4 | require 'json' 5 | 6 | set :backend, :exec 7 | -------------------------------------------------------------------------------- /web/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM banno/carbon-base 2 | 3 | # Install Base Packages 4 | RUN apt-get -y update && \ 5 | apt-get -y install supervisor nginx-light python-simplejson python-memcache python-ldap python-cairo \ 6 | python-twisted python-pysqlite2 python-support \ 7 | python-pip gunicorn 8 | 9 | # Install python packages 10 | RUN pip install pytz pyparsing django==1.5 django-tagging==0.3.1 11 | 12 | # Setup graphite directories and environment variables 13 | ENV GRAPHITE_STORAGE_DIR /opt/graphite/storage 14 | ENV GRAPHITE_CONF_DIR /opt/graphite/conf 15 | ENV PYTHONPATH /opt/graphite/webapp 16 | ENV LOG_DIR /var/log/graphite 17 | ENV DEFAULT_INDEX_TABLESPACE graphite 18 | 19 | RUN mkdir -p /opt/graphite/webapp && \ 20 | mkdir -p /var/log/graphite && \ 21 | cd /var/log/graphite/ && touch info.log && \ 22 | mkdir -p /opt/graphite/storage/whisper && \ 23 | touch /opt/graphite/storage/graphite.db /opt/graphite/storage/index && \ 24 | chown -R www-data /opt/graphite/storage && \ 25 | chmod 0775 /opt/graphite/storage /opt/graphite/storage/whisper && \ 26 | chmod 0664 /opt/graphite/storage/graphite.db 27 | 28 | # Copy configuration files 29 | ADD ./config/local_settings.py /opt/graphite/webapp/graphite/local_settings.py 30 | ADD ./config/initial_data.json /opt/graphite/webapp/graphite/initial_data.json 31 | ADD ./config/nginx.conf /etc/nginx/nginx.conf 32 | ADD ./config/supervisord.conf /etc/supervisor/supervisord.conf 33 | 34 | # Initialize database(sqlite3) 35 | RUN cd /opt/graphite/webapp/graphite && django-admin.py syncdb --settings=graphite.settings --noinput 36 | RUN cd /opt/graphite/webapp/graphite && django-admin.py loaddata --settings=graphite.settings initial_data.json 37 | 38 | # Set CMD 39 | WORKDIR /opt/graphite/webapp 40 | EXPOSE 80 41 | CMD ["/usr/bin/supervisord"] 42 | -------------------------------------------------------------------------------- /web/config/initial_data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pk": 1, 4 | "model": "auth.user", 5 | "fields": { 6 | "username": "admin", 7 | "first_name": "", 8 | "last_name": "", 9 | "is_active": true, 10 | "is_superuser": true, 11 | "is_staff": true, 12 | "last_login": "2011-09-20 17:02:14", 13 | "groups": [], 14 | "user_permissions": [], 15 | "password": "sha1$1b11b$edeb0a67a9622f1f2cfeabf9188a711f5ac7d236", 16 | "email": "root@example.com", 17 | "date_joined": "2011-09-20 17:02:14" 18 | } 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /web/config/local_settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json, requests 3 | from datetime import datetime 4 | 5 | LOG_DIR = '/var/log/graphite' 6 | if os.getenv("CARBONLINK_HOSTS"): 7 | CARBONLINK_HOSTS = os.getenv("CARBONLINK_HOSTS").split(',') 8 | 9 | if os.getenv("CLUSTER_SERVERS"): 10 | CLUSTER_SERVERS = os.getenv("CLUSTER_SERVERS").split(',') 11 | elif os.getenv("RANCHER_GRAPHITE_CLUSTER_SERVICE_NAME"): 12 | rancher_carbonlink_service_url = "http://rancher-metadata/2015-12-19/services/%s/containers" % os.getenv("RANCHER_GRAPHITE_CLUSTER_SERVICE_NAME") 13 | r = requests.get(rancher_carbonlink_service_url, headers={"Accept": "application/json"}).json() 14 | r = map(lambda x: x["primary_ip"] + ":80", r) 15 | CLUSTER_SERVERS = [str(x) for x in r] 16 | 17 | if os.getenv("MEMCACHE_HOSTS"): 18 | MEMCACHE_HOSTS = os.getenv("MEMCACHE_HOSTS").split(',') 19 | 20 | if os.getenv("WHISPER_DIR"): 21 | WHISPER_DIR = os.getenv("WHISPER_DIR") 22 | 23 | SECRET_KEY = str(datetime.now()) 24 | -------------------------------------------------------------------------------- /web/config/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 | server { 30 | listen 80 default_server; 31 | server_name _; 32 | 33 | open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m; 34 | 35 | location / { 36 | proxy_pass http://127.0.0.1:8000; 37 | proxy_set_header X-Real-IP $remote_addr; 38 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 39 | proxy_set_header X-Forwarded-Proto $scheme; 40 | proxy_set_header X-Forwarded-Server $host; 41 | proxy_set_header X-Forwarded-Host $host; 42 | proxy_set_header Host $host; 43 | 44 | client_max_body_size 10m; 45 | client_body_buffer_size 128k; 46 | 47 | proxy_connect_timeout 90; 48 | proxy_send_timeout 90; 49 | proxy_read_timeout 90; 50 | 51 | proxy_buffer_size 4k; 52 | proxy_buffers 4 32k; 53 | proxy_busy_buffers_size 64k; 54 | proxy_temp_file_write_size 64k; 55 | } 56 | 57 | add_header Access-Control-Allow-Origin "*"; 58 | add_header Access-Control-Allow-Methods "GET, OPTIONS"; 59 | add_header Access-Control-Allow-Headers "origin, authorization, accept"; 60 | 61 | location /content { 62 | alias /opt/graphite/webapp/content; 63 | } 64 | 65 | location /media { 66 | alias /usr/share/pyshared/django/contrib/admin/media; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /web/config/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon = true 3 | 4 | [program:nginx] 5 | command = /usr/sbin/nginx 6 | stdout_logfile = /var/log/supervisor/%(program_name)s.log 7 | stderr_logfile = /var/log/supervisor/%(program_name)s.log 8 | autorestart = true 9 | 10 | [program:graphite-webapp] 11 | directory = /opt/graphite/webapp 12 | command = /usr/bin/gunicorn_django -b0.0.0.0:8000 -w2 graphite/settings.py 13 | stdout_logfile = /var/log/supervisor/%(program_name)s.log 14 | stderr_logfile = /var/log/supervisor/%(program_name)s.log 15 | autorestart = true 16 | --------------------------------------------------------------------------------