├── vars ├── main.yml └── collectors_default.yml ├── templates ├── collectors.j2 └── diamond.conf ├── handlers └── main.yml ├── tasks ├── setup-RedHat-rpm.yml ├── setup-influxdb.yml └── main.yml ├── meta └── main.yml ├── defaults └── main.yml └── README.md /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for ansible-role-diamond 3 | -------------------------------------------------------------------------------- /templates/collectors.j2: -------------------------------------------------------------------------------- 1 | {% for (k1,v1) in item['value']|dictsort %} 2 | {{k1}}={{v1}} 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for ansible-role-diamond 3 | 4 | - name: restart diamond 5 | service: name=diamond state=restarted 6 | -------------------------------------------------------------------------------- /tasks/setup-RedHat-rpm.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install diamond rpm package. 3 | yum: name={{ diamond_rpm }} state=present 4 | 5 | - name: Ensure diamond enabled at system start. 6 | service: name="diamond" enabled=yes 7 | when: diamond_enabled 8 | -------------------------------------------------------------------------------- /tasks/setup-influxdb.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install python-pip ON RedHat/CentOS. 3 | yum: name=python-pip state=present 4 | when: ansible_os_family == 'RedHat' 5 | 6 | - name: Install influxdb python package. 7 | pip: name={{ diamond_influxdb_name }} 8 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: z@zstack.net 4 | description: Ansible role to install python diamond 5 | company: 6 | license: license (BSD, MIT) 7 | min_ansible_version: 1.6 8 | platforms: 9 | - name: EL 10 | versions: 11 | - 6 12 | - 7 13 | categories: 14 | - monitoring 15 | - system 16 | dependencies: [] 17 | -------------------------------------------------------------------------------- /vars/collectors_default.yml: -------------------------------------------------------------------------------- 1 | diamond_collectors_default: 2 | CPUCollector: 3 | enabled: True 4 | DiskSpaceCollector: 5 | enabled: True 6 | DiskUsageCollector: 7 | enabled: True 8 | LoadAverageCollector: 9 | enabled: True 10 | MemoryCollector: 11 | enabled: True 12 | VMStatCollector: 13 | enabled: True 14 | NetworkCollector: 15 | enabled: True 16 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for ansible-role-diamond 3 | 4 | diamond_enabled: true 5 | diamond_rpm: "http://url/diamond-4.0.198-0.noarch.rpm" 6 | 7 | # config 8 | diamond_collectors_config_path: /etc/diamond/collectors/ 9 | diamond_handlers_config_path: /etc/diamond/handlers/ 10 | 11 | diamond_conf_path_prefix: "servers" 12 | diamond_conf_interval: 300 13 | 14 | # GraphiteHandler 15 | diamond_graphite_handler: 16 | enable: false 17 | host: "127.0.0.1" 18 | port: 2003 19 | timeout: 15 20 | batch: 1 21 | 22 | # InfluxdbHandler 23 | diamond_influxdb_name: "influxdb" 24 | diamond_influxdb_handler: 25 | enable: false 26 | hostname: "localhost" 27 | port: 8096 28 | database: "graphite" 29 | username: "root" 30 | password: "root" 31 | batch_size: 1 32 | cache_size: 20000 33 | time_precision: "s" 34 | 35 | diamond_collectors_extra: {} 36 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for ansible-role-diamond 3 | 4 | - name: Include collector definitions. 5 | include_vars: "collectors_default.yml" 6 | 7 | - name: Include install prebuilt diamond on RedHat/CentOS. 8 | include: setup-RedHat-rpm.yml 9 | when: ansible_os_family == 'RedHat' 10 | 11 | - name: Include install python influxdb client. 12 | include: setup-influxdb.yml 13 | when: diamond_influxdb_handler.enable 14 | 15 | - name: Update diamond.conf with template. 16 | template: src=diamond.conf dest=/etc/diamond/ backup=yes 17 | notify: 18 | - restart diamond 19 | 20 | - name: Configuring default collectors. 21 | template: src=collectors.j2 dest={{ diamond_collectors_config_path }}{{ item.key }}.conf 22 | with_dict: diamond_collectors_default 23 | when: "item.key not in diamond_collectors_extra.keys()" 24 | notify: 25 | - restart diamond 26 | 27 | - name: Configuring extra collectors. 28 | template: src=collectors.j2 dest={{ diamond_collectors_config_path }}{{ item.key }}.conf 29 | with_dict: diamond_collectors_extra 30 | notify: 31 | - restart diamond 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: Diamond 2 | 3 | Ansible role that installs the Diamond metric collector daemon on RedHat/CentOS. 4 | 5 | ## Requirements 6 | 7 | - Graphite和Influxdb不能同时启用,只能二选一. 8 | - 启用Influxdb必须安装EPEL源或是其他可以安装python-pip的源. 9 | 10 | ## Role Variables 11 | 12 | ### `defaults/main.yml` 13 | *default lower priority variables for this role* 14 | 15 | * `diamond_enabled: true` 16 | * `diamond_rpm: "http://url/diamond-4.0.198-0.noarch.rpm"` 17 | 18 | * `diamond_collectors_config_path: /etc/diamond/collectors/` 19 | * `diamond_handlers_config_path: /etc/diamond/handlers/` 20 | 21 | * `diamond_conf_path_prefix: "servers"` 22 | * `diamond_conf_interval: 300` 23 | 24 | * `diamond_graphite_handler:` 25 | ``` 26 | enable: false 27 | host: "127.0.0.1" 28 | port: 2003 29 | timeout: 15 30 | batch: 1 31 | ``` 32 | 33 | * `diamond_influxdb_name: "influxdb"` 34 | * `diamond_influxdb_handler:` 35 | ``` 36 | enable: false 37 | hostname: "localhost" 38 | port: 8096 39 | database: "graphite" 40 | username: "root" 41 | password: "root" 42 | batch_size: 1 43 | cache_size: 20000 44 | time_precision: "s" 45 | ``` 46 | 47 | * `diamond_collectors_extra: {}` 48 | 49 | ## Dependencies 50 | 51 | None 52 | 53 | ## Example Playbook 54 | 55 | - name: Install and configure diamond 56 | hosts: servers 57 | vars: 58 | diamond_rpm: "http://127.0.0.1/diamond-4.0.198-0.noarch.rpm" 59 | diamond_conf_path_prefix: "PRODUCTION" 60 | diamond_conf_interval: 30 61 | diamond_graphite_handler: 62 | enable: true 63 | host: "127.0.0.1" 64 | port: 2003 65 | timeout: 15 66 | batch: 1 67 | diamond_collectors_extra: 68 | UptimeCollector: 69 | enabled: True 70 | roles: 71 | - diamond 72 | 73 | - name: Install and configure diamond 74 | hosts: servers 75 | vars: 76 | diamond_rpm: "http://127.0.0.1/diamond-4.0.198-0.noarch.rpm" 77 | diamond_conf_path_prefix: "PRODUCTION" 78 | diamond_conf_interval: 30 79 | diamond_influxdb_name: "influxdb" 80 | diamond_influxdb_handler: 81 | enable: true 82 | hostname: "localhost" 83 | port: 8096 84 | database: "graphite" 85 | username: "root" 86 | password: "root" 87 | batch_size: 1 88 | cache_size: 20000 89 | time_precision: "s" 90 | diamond_collectors_extra: 91 | UptimeCollector: 92 | enabled: True 93 | roles: 94 | - diamond 95 | 96 | ## License 97 | 98 | MIT / BSD 99 | 100 | ## Author Information 101 | 102 | z@zstack.net 103 | -------------------------------------------------------------------------------- /templates/diamond.conf: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Diamond Configuration File 3 | ################################################################################ 4 | 5 | ################################################################################ 6 | ### Options for the server 7 | [server] 8 | 9 | # Handlers for published metrics. 10 | handlers = diamond.handler.archive.ArchiveHandler, {% if diamond_graphite_handler.enable %}diamond.handler.graphite.GraphiteHandler{% elif diamond_influxdb_handler.enable %}diamond.handler.influxdbHandler.InfluxdbHandler{% endif %} 11 | 12 | # User diamond will run as 13 | # Leave empty to use the current user 14 | user = 15 | 16 | # Group diamond will run as 17 | # Leave empty to use the current group 18 | group = 19 | 20 | # Pid file 21 | pid_file = /var/run/diamond.pid 22 | 23 | # Directory to load collector modules from 24 | collectors_path = /usr/share/diamond/collectors/ 25 | 26 | # Directory to load collector configs from 27 | collectors_config_path = {{ diamond_collectors_config_path }} 28 | 29 | # Directory to load handler configs from 30 | handlers_config_path = {{ diamond_handlers_config_path }} 31 | 32 | # Directory to load handler modules from 33 | handlers_path = /usr/share/diamond/handlers/ 34 | 35 | ################################################################################ 36 | ### Options for handlers 37 | [handlers] 38 | 39 | # daemon logging handler(s) 40 | keys = rotated_file 41 | 42 | ### Defaults options for all Handlers 43 | [[default]] 44 | 45 | [[ArchiveHandler]] 46 | 47 | # File to write archive log files 48 | log_file = /var/log/diamond/archive.log 49 | 50 | # Number of days to keep archive log files 51 | days = 7 52 | 53 | [[GraphiteHandler]] 54 | ### Options for GraphiteHandler 55 | 56 | # Graphite server host 57 | host = {{ diamond_graphite_handler.host}} 58 | 59 | # Port to send metrics to 60 | port = {{ diamond_graphite_handler.port }} 61 | 62 | # Socket timeout (seconds) 63 | timeout = {{ diamond_graphite_handler.timeout }} 64 | 65 | # Batch size for metrics 66 | batch = {{ diamond_graphite_handler.batch }} 67 | 68 | [[GraphitePickleHandler]] 69 | ### Options for GraphitePickleHandler 70 | 71 | # Graphite server host 72 | host = 127.0.0.1 73 | 74 | # Port to send metrics to 75 | port = 2004 76 | 77 | # Socket timeout (seconds) 78 | timeout = 15 79 | 80 | # Batch size for pickled metrics 81 | batch = 256 82 | 83 | [[MySQLHandler]] 84 | ### Options for MySQLHandler 85 | 86 | # MySQL Connection Info 87 | hostname = 127.0.0.1 88 | port = 3306 89 | username = root 90 | password = 91 | database = diamond 92 | table = metrics 93 | # INT UNSIGNED NOT NULL 94 | col_time = timestamp 95 | # VARCHAR(255) NOT NULL 96 | col_metric = metric 97 | # VARCHAR(255) NOT NULL 98 | col_value = value 99 | 100 | [[StatsdHandler]] 101 | host = 127.0.0.1 102 | port = 8125 103 | 104 | [[TSDBHandler]] 105 | host = 127.0.0.1 106 | port = 4242 107 | timeout = 15 108 | 109 | [[LibratoHandler]] 110 | user = user@example.com 111 | apikey = abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 112 | 113 | [[HostedGraphiteHandler]] 114 | apikey = abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 115 | timeout = 15 116 | batch = 1 117 | 118 | [[SignalfxHandler]] 119 | auth_token = abcdefghijklmnopqrstuvwxyz 120 | 121 | # And any other config settings from GraphiteHandler are valid here 122 | 123 | [[HttpPostHandler]] 124 | 125 | ### Urp to post the metrics 126 | url = http://localhost:8888/ 127 | ### Metrics batch size 128 | batch = 100 129 | 130 | {% if diamond_influxdb_handler.enable %} 131 | [[InfluxdbHandler]] 132 | hostname = {{ diamond_influxdb_handler.hostname}} 133 | port = {{ diamond_influxdb_handler.port }} 134 | database = {{ diamond_influxdb_handler.database }} 135 | username = {{ diamond_influxdb_handler.username }} 136 | password = {{ diamond_influxdb_handler.password }} 137 | batch_size = {{ diamond_influxdb_handler.batch_size }} 138 | cache_size = {{ diamond_influxdb_handler.cache_size }} 139 | time_precision = {{ diamond_influxdb_handler.time_precision }} 140 | {% endif %} 141 | 142 | ################################################################################ 143 | ### Options for collectors 144 | [collectors] 145 | 146 | [[default]] 147 | ### Defaults options for all Collectors 148 | 149 | # Uncomment and set to hardcode a hostname for the collector path 150 | # Keep in mind, periods are seperators in graphite 151 | # hostname = my_custom_hostname 152 | 153 | # If you prefer to just use a different way of calculating the hostname 154 | # Uncomment and set this to one of these values: 155 | 156 | # smart = Default. Tries fqdn_short. If that's localhost, uses hostname_short 157 | 158 | # fqdn_short = Default. Similar to hostname -s 159 | # fqdn = hostname output 160 | # fqdn_rev = hostname in reverse (com.example.www) 161 | 162 | # uname_short = Similar to uname -n, but only the first part 163 | # uname_rev = uname -r in reverse (com.example.www) 164 | 165 | # hostname_short = `hostname -s` 166 | # hostname = `hostname` 167 | # hostname_rev = `hostname` in reverse (com.example.www) 168 | 169 | # shell = Run the string set in hostname as a shell command and use its 170 | # output(with spaces trimmed off from both ends) as the hostname. 171 | 172 | # hostname_method = smart 173 | 174 | # Path Prefix and Suffix 175 | # you can use one or both to craft the path where you want to put metrics 176 | # such as: %(path_prefix)s.$(hostname)s.$(path_suffix)s.$(metric)s 177 | # path_prefix = servers 178 | # path_suffix = 179 | path_prefix = {{ diamond_conf_path_prefix }} 180 | 181 | # Path Prefix for Virtual Machines 182 | # If the host supports virtual machines, collectors may report per 183 | # VM metrics. Following OpenStack nomenclature, the prefix for 184 | # reporting per VM metrics is "instances", and metric foo for VM 185 | # bar will be reported as: instances.bar.foo... 186 | # instance_prefix = instances 187 | 188 | # Default Poll Interval (seconds) 189 | # interval = 300 190 | interval = {{ diamond_conf_interval }} 191 | 192 | ################################################################################ 193 | ### Options for logging 194 | # for more information on file format syntax: 195 | # http://docs.python.org/library/logging.config.html#configuration-file-format 196 | 197 | [loggers] 198 | 199 | keys = root 200 | 201 | # handlers are higher in this config file, in: 202 | # [handlers] 203 | # keys = ... 204 | 205 | [formatters] 206 | 207 | keys = default 208 | 209 | [logger_root] 210 | 211 | # to increase verbosity, set DEBUG 212 | level = INFO 213 | handlers = rotated_file 214 | propagate = 1 215 | 216 | [handler_rotated_file] 217 | 218 | class = handlers.TimedRotatingFileHandler 219 | level = DEBUG 220 | formatter = default 221 | # rotate at midnight, each day and keep 7 days 222 | args = ('/var/log/diamond/diamond.log', 'midnight', 1, 7) 223 | 224 | [formatter_default] 225 | 226 | format = [%(asctime)s] [%(threadName)s] %(message)s 227 | datefmt = 228 | 229 | ################################################################################ 230 | ### Options for config merging 231 | # [configs] 232 | # path = "/etc/diamond/configs/" 233 | # extension = ".conf" 234 | #------------------------------------------------------------------------------- 235 | # Example: 236 | # /etc/diamond/configs/net.conf 237 | # [collectors] 238 | # 239 | # [[NetworkCollector]] 240 | # enabled = True 241 | --------------------------------------------------------------------------------