From eac573a742bf04d7708c93eec7c49f635042617c Mon Sep 17 00:00:00 2001 From: vpalos Date: Sat, 21 Feb 2015 13:09:37 +0200 Subject: [PATCH 1/3] Completed Lua/Luvit version of LiteSpeed plugin. --- LICENSE | 369 ++++++++++++++++++++++++---------------------- README.md | 85 ++++++----- index.js | 4 +- init.lua | 273 ++++++++++++++++++++++++++++++++++ modules/tools.lua | 32 ++++ param.json | 6 +- plugin.json | 92 ++++++------ 7 files changed, 600 insertions(+), 261 deletions(-) create mode 100644 init.lua create mode 100644 modules/tools.lua diff --git a/LICENSE b/LICENSE index 37ec93a..4e322a9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,191 +1,202 @@ Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. - -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. - -2. Grant of Copyright License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. - -3. Grant of Patent License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. - -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. - -5. Submission of Contributions. - -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. - -6. Trademarks. - -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. - -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. - -8. Limitation of Liability. - -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. - -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own -identifying information. (Don't include the brackets!) The text should be -enclosed in the appropriate comment syntax for the file format. We also -recommend that a file or class name and description of purpose be included on -the same "printed page" as the copyright notice for easier identification within -third-party archives. - - Copyright [yyyy] [name of copyright owner] + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright Boundary, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + diff --git a/README.md b/README.md index fd9e3b8..40f6dd3 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,69 @@ -Boundary Litespeed Plugin -------------------------- +# Boundary Litespeed Plugin -Collects metrics from Litespeed HTTP Server instance. +Collects metrics from LiteSpeed HTTP Web-Server. -### Prerequisites +## Prerequisites | OS | Linux | Windows | SmartOS | OS X | |:----------|:-----:|:-------:|:-------:|:----:| | Supported | v | - | v | v | +- **OS**: Tested to work on **Debian-based Linux distributions** (although any Linux-based OS should work). +- Requires access to "/tmp/lshttpd" (LiteSpeed real-time reporting folder). -| Runtime | node.js | Python | Java | +### **Meter V4.0 or greater** + +To get the new meter: + + curl -fsS \ + -d "{\"token\":\"\"}" \ + -H "Content-Type: application/json" \ + "https://meter.boundary.com/setup_meter" > setup_meter.sh + chmod +x setup_meter.sh + ./setup_meter.sh + +| Runtime | node.js | Python | Java | |:---------|:-------:|:------:|:----:| -| Required | + | | | +| Required | | | | -- [How to install node.js?](https://help.boundary.com/hc/articles/202360701) +### Meter less than V4.0 -### Plugin Setup -None +| Runtime | node.js | Python | Java | +|:---------|:-------:|:------:|:----:| +| Required | v | | | + +- [How to install node.js?](https://help.boundary.com/hc/articles/202360701) -#### Plugin Configuration Fields +## Plugin Setup +None required. +### Plugin Configuration Fields Litespeed writes server statistics to multiple report files in the /tmp/lshttpd folder by default, check your configuration to ensure that the path is correct. The number of reports are based on the number of CPUs on your server and the number of CPUs that you have licences for. -|Field Name |Description | -|:------------|:---------------------------------------| -|Report path |The path to the lshttp .rtreport files | -|Virtual Hosts|Include individual VHosts in your graphs| +|Field Name |Identifier |Type |Description | +|:--------------|:------------|--------------|:---------------------------------------------------------------------------------| +|Report Path |reportPath |string |The path to the LiteSpeed '.rtreport' file(s) to watch (default: '/tmp/lshttpd'). | +|Virtual Hosts |virtualHosts |array[string] |Include individual VHosts in your graphs. | +|Poll Interval |pollInterval |integer |How often (in milliseconds) to poll the metrics file(s) (default: 5000). | ### Metrics Collected +Tracks the following metrics for the [LiteSpeed](http://www.litespeedtech.com/) HTTP Web-Server. -Tracks the following metrics for the [litespeed](http://www.litespeedtech.com/) webserver. - -|Metric Name |Description | -|:-------------------------------|:-------------------------------------------| -|Litespeed HTTP Connection limit |The ratio of connections to the Max Limit | -|Litespeed Http Conns |The number of current HTTP connections | -|Litespeed Idle Http Conns |The number of current idle HTTP connections | -|Litespeed HTTPS Connection limit|The ratio of connections to the Max Limit | -|Litespeed Https Conns |The number of current HTTPS connections | -|Litespeed Idle Https Conns |The number of current idle HTTPS connections| -|Litespeed Http Bytes In |The amount of inbound data over HTTP | -|Litespeed Http Bytes Out |The amount of outbound data over HTTP | -|Litespeed Https Bytes In |The amount of inbound data over HTTPS | -|Litespeed Https Bytes Out |The amount of outbound data over HTTPS | -|Litespeed Total Bytes In |The total amount of inbound data | -|Litespeed Total Bytes Out |The total amount of outbound data | -|Litespeed Cache Hits |The number of cache hits | -|Litespeed Cache Hit Ratio |The ratio of cache hits to overall requests | -|Litespeed Requests in Process |The number of requests in process | -|Litespeed Requests |The number of requests | +|Metric Name |Description | +|:--------------------------------|:---------------------------------------------| +|Litespeed HTTP Connection limit |The ratio of connections to the Max Limit. | +|Litespeed Http Conns |The number of current HTTP connections. | +|Litespeed Idle Http Conns |The number of current idle HTTP connections. | +|Litespeed HTTPS Connection limit |The ratio of connections to the Max Limit. | +|Litespeed Https Conns |The number of current HTTPS connections. | +|Litespeed Idle Https Conns |The number of current idle HTTPS connections. | +|Litespeed Http Bytes In |The amount of inbound data over HTTP. | +|Litespeed Http Bytes Out |The amount of outbound data over HTTP. | +|Litespeed Https Bytes In |The amount of inbound data over HTTPS. | +|Litespeed Https Bytes Out |The amount of outbound data over HTTPS. | +|Litespeed Total Bytes In |The total amount of inbound data. | +|Litespeed Total Bytes Out |The total amount of outbound data. | +|Litespeed Cache Hits |The number of cache hits. | +|Litespeed Cache Hit Ratio |The ratio of cache hits to overall requests. | +|Litespeed Requests in Process |The number of requests in process. | +|Litespeed Requests |The number of requests. | diff --git a/index.js b/index.js index bc58129..be422c9 100644 --- a/index.js +++ b/index.js @@ -300,8 +300,8 @@ function poll(cb) console.log('LITESPEED_HTTP_BYTES_OUT %d %s', cur.BPS_OUT, _source); console.log('LITESPEED_HTTPS_BYTES_IN %d %s', cur.SSL_BPS_IN, _source); console.log('LITESPEED_HTTPS_BYTES_OUT %d %s', cur.SSL_BPS_OUT, _source); - console.log('LITESPEED_TOTAL_BYTES_IN %d %s', sum(cur.BPS_IN + cur.SSL_BPS_IN), _source); - console.log('LITESPEED_TOTAL_BYTES_OUT %d %s', sum(cur.BPS_OUT + cur.SSL_BPS_OUT), _source); + console.log('LITESPEED_TOTAL_BYTES_IN %d %s', sum(cur.BPS_IN, cur.SSL_BPS_IN), _source); + console.log('LITESPEED_TOTAL_BYTES_OUT %d %s', sum(cur.BPS_OUT, cur.SSL_BPS_OUT), _source); // PER VHOST STATS if (cur.vhosts && Object.keys(cur.vhosts).length > 0) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f984616 --- /dev/null +++ b/init.lua @@ -0,0 +1,273 @@ +-- +-- [boundary.com] Couchbase Lua Plugin +-- [author] Valeriu Paloş +-- + +-- +-- Imports. +-- +local fs = require('fs') +local json = require('json') +local http = require('http') +local os = require('os') +local path = require('path') +local timer = require('timer') +local tools = require('tools') +local url = require('url') + +-- +-- Initialize. +-- +local _buckets = {} +local _parameters = json.parse(fs.readFileSync('param.json')) or {} + +local _reportPath = _parameters.reportPath or '/tmp/lshttpd' +local _virtualHosts = _parameters.virtualHosts or {} +local _pollInterval = tools.fence(tonumber(_parameters.pollInterval) or 5000, 100, 1000 * 60 * 60 * 24) + +local _ignoredLines = { '^VERSION', '^UPTIME', '^BLOCKED_IP', '^EOF' } + +-- +-- Metrics source. +-- +local _source = + (type(_parameters.source) == 'string' and _parameters.source:gsub('%s+', '') ~= '' and _parameters.source) or + os.hostname() + +-- +-- Scan paths. +-- +local reports = {} +local file = path.join(_reportPath, '.rtreport') +if fs.existsSync(file) then + table.insert(reports, file) +end +for i = 0, #os.cpus() do + local file = path.join(_reportPath, '.rtreport' .. i) + if fs.existsSync(file) then + table.insert(reports, file) + end +end + +-- +-- Scan virtual hosts. +-- +local virtualHosts = {} +if #_parameters.virtualHosts == 0 then + table.insert(_parameters.virtualHosts, '') +end +for _, item in ipairs(_parameters.virtualHosts) do + if item then + local vhost = item:match('^([^|]*)') + local alias = item:match('|(.*)$') + + if virtualHosts[vhost] then + error(("The virtual host '%s' is defined twice and hosts must be distinct!"):format(vhost)) + end + + virtualHosts[vhost] = _source .. '-' .. tools.trim(alias or vhost) + end +end + +-- +-- Calculus utility functions. +-- +function sum(a, b) + return (a and b and math.max(a + b, 0)) or a or b +end +function delta(a, b) + local na, nb = tonumber(a), tonumber(b) + return (na and nb and math.max(na - nb, 0)) or 0 +end +function parseFloat(x) + return tonumber(x) or 0 +end +function parseKeyValues(data) + local result = {} + for key, value in data:gmatch("([%w_]+):%s*(%d+)") do + result[key:upper()] = parseFloat(value) + end + return result +end + +-- +-- Schedule poll. +-- +function schedule() + timer.setTimeout(_pollInterval, poll) +end + +-- +-- Print a metric. +-- +function metric(stamp, id, value, source) + print(string.format('%s %s %s %d', id, value, source or _source, stamp)) +end + +-- +-- Parse a report file. +-- +function parseReport(file, callback) + + -- Sample Report: + -- + -- VERSION: LiteSpeed Web Server/Standard/4.2.21 + -- UPTIME: 02:38:00 + -- BPS_IN: 0, BPS_OUT: 0, SSL_BPS_IN: 0, SSL_BPS_OUT: 0 + -- MAXCONN: 150, MAXSSL_CONN: 150, PLAINCONN: 0, AVAILCONN: 150, IDLECONN: 0, SSLCONN: 0, AVAILSSL: 150 + -- REQ_RATE []: REQ_PROCESSING: 0, REQ_PER_SEC: 0.0, TOT_REQS: 0, CACHE_HITS_PER_SEC: 0.0, TOTAL_CACHE_HITS: 0 + -- REQ_RATE [Example]: REQ_PROCESSING: 0, REQ_PER_SEC: 0.0, TOT_REQS: 0, CACHE_HITS_PER_SEC: 0.0, TOTAL_CACHE_HITS: 0 + -- REQ_RATE [_AdminVHost]: REQ_PROCESSING: 0, REQ_PER_SEC: 0.0, TOT_REQS: 0, CACHE_HITS_PER_SEC: 0.0, TOTAL_CACHE_HITS: 0 + -- BLOCKED_IP: + -- EOF + -- + fs.readFile(file, function(failure, data) + + -- Safety check. + if failure or not data then + print("ERROR: " .. failure) + return callback({}) + end + + -- Walk through lines. + local results = { ['virtualHosts'] = {} } + for line in tools.lines(data) do + + -- Catch ignored lines. + local valid = true + for _, ignored in ipairs(_ignoredLines) do + if line:find(ignored) then + valid = false + break + end + end + + -- Parse valid lines. + if valid then + local sink = results + local data = line + + -- General metrics or virtual-host specifc? + local vhost, metrics = line:match('^REQ_RATE %[(.-)%]:(.*)') + if vhost then + data = '' + + if virtualHosts[vhost] then + results.virtualHosts[vhost] = results.virtualHosts[vhost] or {} + sink = results.virtualHosts[vhost] + data = metrics + end + end + + -- Parse metrics. + for key, value in pairs(parseKeyValues(data)) do + sink[key] = (sink[key] or 0) + value + end + end + + end + + callback(results) + end) +end + +-- +-- Collect and aggregate reports. +-- +function collectReports(callback) + local sets = {} + local remaining = #reports + + -- Add results to the stack. + function aggregate(values) + table.insert(sets, values) + if remaining == 0 then + + -- Aggregate if all reports are parsed. + local store = { ['virtualHosts'] = {} } + for _, metrics in ipairs(sets) do + + -- Walk generic values. + for name, value in pairs(metrics) do + if name ~= 'virtualHosts' then + store[name] = (store[name] or 0) + value + end + end + + -- Walk virtual-host-specific values. + for vhost, vhMetrics in pairs(metrics.virtualHosts) do + store.virtualHosts[vhost] = store.virtualHosts[vhost] or {} + for name, value in pairs(vhMetrics) do + store.virtualHosts[vhost][name] = (store.virtualHosts[vhost][name] or 0) + value + end + end + + end + + callback(store) + end + end + + -- Trigger asynchronous parsing of report files. + for _, report in ipairs(reports) do + parseReport(report, function(values) + remaining = remaining - 1 + aggregate(values) + end) + end + +end + +-- +-- Produce metrics. +-- +function poll() + local stamp = os.time() + + -- Trigger one collection. + collectReports(function(metrics) + local httpConnLimit = (metrics.MAXCONN == 0 and 0) or (metrics.PLAINCONN / metrics.MAXCONN) + local httpsConnLimit = (metrics.MAXSSL_CONN == 0 and 0) or (metrics.SSLCONN / metrics.MAXSSL_CONN) + + metrics.BPS_IN = metrics.BPS_IN * 1024; + metrics.BPS_OUT = metrics.BPS_OUT * 1024; + metrics.SSL_BPS_IN = metrics.SSL_BPS_IN * 1024; + metrics.SSL_BPS_OUT = metrics.SSL_BPS_OUT * 1024; + + -- Generic metrics. + metric(stamp, 'LITESPEED_HTTP_CONNECTION_LIMIT', httpConnLimit) + metric(stamp, 'LITESPEED_HTTP_CONNECTIONS', metrics.PLAINCONN) + metric(stamp, 'LITESPEED_HTTP_IDLE_CONNECTIONS', metrics.IDLECONN) + metric(stamp, 'LITESPEED_HTTPS_CONNECTION_LIMIT', httpsConnLimit) + metric(stamp, 'LITESPEED_HTTPS_CONNECTIONS', metrics.SSLCONN) + metric(stamp, 'LITESPEED_HTTPS_IDLE_CONNECTIONS', delta(metrics.AVAILSSL, metrics.SSLCONN)) + metric(stamp, 'LITESPEED_HTTP_BYTES_IN', metrics.BPS_IN) + metric(stamp, 'LITESPEED_HTTP_BYTES_OUT', metrics.BPS_OUT) + metric(stamp, 'LITESPEED_HTTPS_BYTES_IN', metrics.SSL_BPS_IN) + metric(stamp, 'LITESPEED_HTTPS_BYTES_OUT', metrics.SSL_BPS_OUT) + metric(stamp, 'LITESPEED_TOTAL_BYTES_IN', sum(metrics.BPS_IN, metrics.SSL_BPS_IN)) + metric(stamp, 'LITESPEED_TOTAL_BYTES_OUT', sum(metrics.BPS_OUT, metrics.SSL_BPS_OUT)) + + -- Virtual-host specific metrics. + for vhost, vhMetrics in pairs(metrics.virtualHosts) do + local virtualHost = metrics.virtualHosts[vhost]; + local virtualName = virtualHosts[vhost]; + + local cacheHits = virtualHost.CACHE_HITS_PER_SEC or 0; + local requests = virtualHost.REQ_PER_SEC; + local requestsInProcess = virtualHost.REQ_PROCESSING or 0; + local cacheRatio = (requests == 0 and 0) or (cacheHits / requests); + + metric(stamp, 'LITESPEED_CACHE_HITS', cacheHits, virtualName) + metric(stamp, 'LITESPEED_CACHE_RATIO', cacheRatio, virtualName) + metric(stamp, 'LITESPEED_REQUESTS', requests, virtualName) + metric(stamp, 'LITESPEED_REQUESTS_IN_PROCESS', requestsInProcess, virtualName) + end + + -- Reschedule. + schedule() + end) +end + +-- Trigger polling. +poll() \ No newline at end of file diff --git a/modules/tools.lua b/modules/tools.lua new file mode 100644 index 0000000..7e870bc --- /dev/null +++ b/modules/tools.lua @@ -0,0 +1,32 @@ +-- +-- Tools Module. +-- [author] Valeriu Paloş +-- +local tools = {} + +-- +-- Trim string from both ends. +-- +tools.trim = function(text) + return (text:gsub("^%s*(.-)%s*$", "%1")) +end + +-- +-- Iterate through string line by line. +-- +tools.lines = function(text) + return text:gmatch("[^\n\r]+") +end + +-- +-- Limit a given number x between two boundaries. +-- Either min or max can be nil, to fence on one side only. +-- +tools.fence = function(x, min, max) + return (min and x < min and min) or (max and x > max and max) or x +end + +-- +-- Export. +-- +return tools \ No newline at end of file diff --git a/param.json b/param.json index e5f4070..2ac6129 100644 --- a/param.json +++ b/param.json @@ -1,5 +1,7 @@ { "reportPath" : "/tmp/lshttpd", - "virtualHosts" : [], - "pollInterval": 1000 + + "virtualHosts" : [], + + "pollInterval": 1000 } diff --git a/plugin.json b/plugin.json index 0023c8a..7b75d40 100644 --- a/plugin.json +++ b/plugin.json @@ -1,49 +1,53 @@ { - "description" : "Displays important litespeed metrics", - "icon" : "icon.png", - "command" : "node index.js", - "postExtract" : "npm install", - "ignore" : "node_modules", + "description" : "Collects real-time metrics from LiteSpeed HTTP Web-Server.", + "icon" : "icon.png", - "metrics" : [ - "LITESPEED_HTTP_CONNECTION_LIMIT", - "LITESPEED_HTTP_CONNECTIONS", - "LITESPEED_HTTP_IDLE_CONNECTIONS", - "LITESPEED_HTTPS_CONNECTION_LIMIT", - "LITESPEED_HTTPS_CONNECTIONS", - "LITESPEED_HTTPS_IDLE_CONNECTIONS", - "LITESPEED_HTTP_BYTES_IN", - "LITESPEED_HTTP_BYTES_OUT", - "LITESPEED_HTTPS_BYTES_IN", - "LITESPEED_HTTPS_BYTES_OUT", - "LITESPEED_TOTAL_BYTES_IN", - "LITESPEED_TOTAL_BYTES_OUT", - "LITESPEED_CACHE_HITS", - "LITESPEED_CACHE_RATIO", - "LITESPEED_REQUESTS_IN_PROCESS", - "LITESPEED_REQUESTS" - ], + "command" : "node index.js", + "postExtract" : "npm install", + "ignore" : "node_modules", - "dashboards": [ - { "name": "litespeed-overview", "layout": "d-w=3&d-h=3&d-pad=5&d-bg=none&d-g-LITESPEED_HTTPS_BYTES_IN=1-0-1-1-t&d-g-LITESPEED_HTTPS_BYTES_OUT=1-0-1-1-b&d-g-LITESPEED_HTTP_BYTES_IN=0-0-1-1-t&d-g-LITESPEED_HTTP_BYTES_OUT=0-0-1-1-b&d-g-LITESPEED_TOTAL_BYTES_IN=2-0-1-1-t&d-g-LITESPEED_TOTAL_BYTES_OUT=2-0-1-1-b&d-g-LITESPEED_CACHE_RATIO=2-2-1-1&d-g-LITESPEED_HTTP_CONNECTIONS=0-1-1-1&d-g-LITESPEED_HTTP_CONNECTION_LIMIT=0-2-1-1&d-g-LITESPEED_HTTPS_CONNECTIONS=1-1-1-1&d-g-LITESPEED_HTTPS_CONNECTION_LIMIT=1-2-1-1&d-g-LITESPEED_REQUESTS=2-1-1-1" } - ], + "command_lua": "boundary-meter init.lua", + "postExtract_lua": "", - "paramSchema" : [ - { - "title" : "Report path", - "name" : "reportPath", - "description" : "The path to the lshttp .rtreport files", - "type" : "string", - "default" : "/tmp/lshttpd" - }, - { - "title": "Virtual Hosts", - "name": "virutalHosts", - "description": "Include individual VHosts in your graphs", - "type" : "array", - "items" : { - "type" : "string" - } - } - ] + "metrics" : [ + "LITESPEED_HTTP_CONNECTION_LIMIT", + "LITESPEED_HTTP_CONNECTIONS", + "LITESPEED_HTTP_IDLE_CONNECTIONS", + "LITESPEED_HTTPS_CONNECTION_LIMIT", + "LITESPEED_HTTPS_CONNECTIONS", + "LITESPEED_HTTPS_IDLE_CONNECTIONS", + "LITESPEED_HTTP_BYTES_IN", + "LITESPEED_HTTP_BYTES_OUT", + "LITESPEED_HTTPS_BYTES_IN", + "LITESPEED_HTTPS_BYTES_OUT", + "LITESPEED_TOTAL_BYTES_IN", + "LITESPEED_TOTAL_BYTES_OUT", + "LITESPEED_CACHE_HITS", + "LITESPEED_CACHE_RATIO", + "LITESPEED_REQUESTS_IN_PROCESS", + "LITESPEED_REQUESTS" + ], + + "dashboards": [ + { "name": "litespeed-overview", "layout": "d-w=3&d-h=3&d-pad=5&d-bg=none&d-g-LITESPEED_HTTPS_BYTES_IN=1-0-1-1-t&d-g-LITESPEED_HTTPS_BYTES_OUT=1-0-1-1-b&d-g-LITESPEED_HTTP_BYTES_IN=0-0-1-1-t&d-g-LITESPEED_HTTP_BYTES_OUT=0-0-1-1-b&d-g-LITESPEED_TOTAL_BYTES_IN=2-0-1-1-t&d-g-LITESPEED_TOTAL_BYTES_OUT=2-0-1-1-b&d-g-LITESPEED_CACHE_RATIO=2-2-1-1&d-g-LITESPEED_HTTP_CONNECTIONS=0-1-1-1&d-g-LITESPEED_HTTP_CONNECTION_LIMIT=0-2-1-1&d-g-LITESPEED_HTTPS_CONNECTIONS=1-1-1-1&d-g-LITESPEED_HTTPS_CONNECTION_LIMIT=1-2-1-1&d-g-LITESPEED_REQUESTS=2-1-1-1" } + ], + + "paramSchema" : [ + { + "title" : "Report Path", + "name" : "reportPath", + "description" : "The path to the LiteSpeed '.rtreport' file(s) to watch (default: '/tmp/lshttpd').", + "type" : "string", + "default" : "/tmp/lshttpd" + }, + { + "title": "Virtual Hosts", + "name": "virtualHosts", + "description": "Include individual Virtual Hosts in your graphs.", + "type" : "array", + "items" : { + "type" : "string" + } + } + ] } From 2552fca187b66f1ca9271323997ad26c2bee128b Mon Sep 17 00:00:00 2001 From: vpalos Date: Sat, 21 Feb 2015 13:15:11 +0200 Subject: [PATCH 2/3] Made requirements tables less confusing. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 40f6dd3..8762146 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Collects metrics from LiteSpeed HTTP Web-Server. | OS | Linux | Windows | SmartOS | OS X | |:----------|:-----:|:-------:|:-------:|:----:| -| Supported | v | - | v | v | +| Supported | yes | no | yes | yes | - **OS**: Tested to work on **Debian-based Linux distributions** (although any Linux-based OS should work). - Requires access to "/tmp/lshttpd" (LiteSpeed real-time reporting folder). @@ -24,13 +24,13 @@ To get the new meter: | Runtime | node.js | Python | Java | |:---------|:-------:|:------:|:----:| -| Required | | | | +| Required | no | no | no | ### Meter less than V4.0 | Runtime | node.js | Python | Java | |:---------|:-------:|:------:|:----:| -| Required | v | | | +| Required | yes | | | - [How to install node.js?](https://help.boundary.com/hc/articles/202360701) From 34001e53d875cbbe88df2762e13cf4eb7dd75efe Mon Sep 17 00:00:00 2001 From: vpalos Date: Sat, 21 Feb 2015 13:37:37 +0200 Subject: [PATCH 3/3] Added metrics.json. --- README.md | 16 +++---- metrics.json | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 8 deletions(-) create mode 100644 metrics.json diff --git a/README.md b/README.md index 8762146..e0b8aa0 100644 --- a/README.md +++ b/README.md @@ -52,15 +52,15 @@ Tracks the following metrics for the [LiteSpeed](http://www.litespeedtech.com/) |Metric Name |Description | |:--------------------------------|:---------------------------------------------| |Litespeed HTTP Connection limit |The ratio of connections to the Max Limit. | -|Litespeed Http Conns |The number of current HTTP connections. | -|Litespeed Idle Http Conns |The number of current idle HTTP connections. | +|Litespeed HTTP Connections |The number of current HTTP connections. | +|Litespeed Idle HTTP Connections |The number of current idle HTTP connections. | |Litespeed HTTPS Connection limit |The ratio of connections to the Max Limit. | -|Litespeed Https Conns |The number of current HTTPS connections. | -|Litespeed Idle Https Conns |The number of current idle HTTPS connections. | -|Litespeed Http Bytes In |The amount of inbound data over HTTP. | -|Litespeed Http Bytes Out |The amount of outbound data over HTTP. | -|Litespeed Https Bytes In |The amount of inbound data over HTTPS. | -|Litespeed Https Bytes Out |The amount of outbound data over HTTPS. | +|Litespeed HTTPS Connections |The number of current HTTPS connections. | +|Litespeed Idle HTTPS Connections |The number of current idle HTTPS connections. | +|Litespeed HTTP Bytes In |The amount of inbound data over HTTP. | +|Litespeed HTTP Bytes Out |The amount of outbound data over HTTP. | +|Litespeed HTTPS Bytes In |The amount of inbound data over HTTPS. | +|Litespeed HTTPS Bytes Out |The amount of outbound data over HTTPS. | |Litespeed Total Bytes In |The total amount of inbound data. | |Litespeed Total Bytes Out |The total amount of outbound data. | |Litespeed Cache Hits |The number of cache hits. | diff --git a/metrics.json b/metrics.json new file mode 100644 index 0000000..b0be588 --- /dev/null +++ b/metrics.json @@ -0,0 +1,132 @@ +{ + "result": [ + { + "name": "LITESPEED_HTTP_CONNECTION_LIMIT", + "displayName": "Litespeed HTTP Connection limit", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "number", + "displayNameShort": "The ratio of connections to the Max Limit.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTP_CONNECTIONS", + "displayName": "Litespeed HTTP Connections", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of current HTTP connections.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTP_IDLE_CONNECTIONS", + "displayName": "Litespeed Idle HTTP Connections", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of current idle HTTP connections.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTPS_CONNECTION_LIMIT", + "displayName": "Litespeed HTTPS Connection limit", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "number", + "displayNameShort": "The ratio of connections to the Max Limit.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTPS_CONNECTIONS", + "displayName": "Litespeed HTTPS Connections", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of current HTTPS connections.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTPS_IDLE_CONNECTIONS", + "displayName": "Litespeed Idle HTTPS Connections", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of current idle HTTPS connections.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTP_BYTES_IN", + "displayName": "Litespeed HTTP Bytes In", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "bytecount", + "displayNameShort": "The amount of inbound data over HTTP.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTP_BYTES_OUT", + "displayName": "Litespeed HTTP Bytes Out", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "bytecount", + "displayNameShort": "The amount of outbound data over HTTP.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTPS_BYTES_IN", + "displayName": "Litespeed HTTPS Bytes In", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "bytecount", + "displayNameShort": "The amount of inbound data over HTTPS.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_HTTPS_BYTES_OUT", + "displayName": "Litespeed HTTPS Bytes Out", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "bytecount", + "displayNameShort": "The amount of outbound data over HTTPS.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_TOTAL_BYTES_IN", + "displayName": "Litespeed Total Bytes In", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "bytecount", + "displayNameShort": "The total amount of inbound data.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_TOTAL_BYTES_OUT", + "displayName": "Litespeed Total Bytes Out", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "bytecount", + "displayNameShort": "The total amount of outbound data.", + "defaultAggregate": "avg" + }, + { + "name": "LITESPEED_CACHE_HITS", + "displayName": "Litespeed Cache Hits", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of cache hits.", + "defaultAggregate": "avg" + } + { + "name": "LITESPEED_CACHE_RATIO", + "displayName": "Litespeed Cache Hit Ratio", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "number", + "displayNameShort": "The ratio of cache hits to overall requests.", + "defaultAggregate": "avg" + } + { + "name": "LITESPEED_REQUESTS", + "displayName": "Litespeed Requests", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of requests.", + "defaultAggregate": "avg" + } + { + "name": "LITESPEED_REQUESTS_IN_PROCESS", + "displayName": "Litespeed Requests in Process", + "description": "Total quota of memory allocated by the Couchbase cluster for this node.", + "unit": "integer", + "displayNameShort": "The number of requests in process.", + "defaultAggregate": "avg" + } + ] +} \ No newline at end of file