Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit 8f9bc95

Browse files
committed
New readme changes to accomodate js scripts
1 parent 4343ac8 commit 8f9bc95

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

README.md

+41-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are other projects that do the same: [collectd](http://collectd.org/) has
1313
Install, configure and run it
1414
---------------------------------
1515

16-
Configuration is done using the a json file. The package includes a default config that you probably can use after changing the hostname for your graphite/carbon node. HoardD was meant to be used with runit and similar tools so no daemonizing is done and all the logging is written on stdout (use `--debug` if you want detailed info on what is happening.) By default scripts sample the data each 10 seconds, and then sends the data to graphite each 6 samples are collected, effectively making one connection each 60 seconds.
16+
Configuration is done using the a `json` file. The package includes a default config that you probably can use after changing the hostname for your graphite/carbon node. HoardD was meant to be used with runit and similar tools so no daemonizing is done and all the logging is written on stdout (use `--debug` if you want detailed info on what is happening.) By default scripts sample the data each 10 seconds, and then sends the data to graphite each 6 samples are collected, effectively making one connection each 60 seconds.
1717

1818
Also, HoardD was made to be used with chef (or any other configuration management system) so while I know that configuring the FQDN on the config JSON is annoying, it was meant to be automatically filled by a template. If you are managing lots of servers and configs by hand in 2012 you are doing it wrong.
1919

@@ -23,7 +23,7 @@ The master branch will be updated only to working versions (i.e: I will *try* no
2323

2424
The MySQL script is an example of how to configure specific scripts. It contains a `mysql.json` file that is read by the script when it starts. Just make sure to:
2525

26-
* Keep the configs with the same name as the plugin (like, mysql.coffee and mysql.json)
26+
* Keep the configs with the same name as the plugin (like, `mysql.coffee` and `mysql.json`)
2727
* Put/link the configuration on the script path (together with the scripts)
2828

2929
For real, you can do whatever you want on your scripts, but it's better to make it easier for other people to configure/understand, so let's stick to a default.
@@ -56,7 +56,7 @@ scale(derivative(hoard.host.interfaces.eth0.txBytes),0.1)
5656
Writing new scripts
5757
--------------------
5858

59-
To add new scripts just drop the `.coffee` file on `scriptPath` and restart HoardD (making it detect new scripts without restarting is on TODO).
59+
To add new scripts just drop the `.coffee` or `.js` file on `scriptPath` and restart HoardD (making it detect new scripts without restarting is on TODO).
6060

6161
Writing new scripts should be easy:
6262

@@ -70,20 +70,48 @@ Writing new scripts should be easy:
7070
* `cli` has all the methods from the [cli](https://github.com/chriso/cli) module (use it for logging)
7171
* `fqdn` the server FQDN configured on the JSON config file for you to use on metrics
7272

73-
Code speaks better than words in some case, this is the uptime script:
73+
Code speaks better than words in some case, this is the `load_average.coffee` script:
7474

7575
```coffeescript
76-
77-
os = require 'os'
76+
Fs = require 'fs'
77+
Path = require 'path'
7878

7979
module.exports = (server) ->
8080
run = () ->
81-
metricPrefix = "#{server.fqdn}.uptime"
82-
server.cli.debug "Running uptime script"
81+
metricPrefix = "#{server.fqdn}.load_average"
82+
server.cli.debug "Running load average script"
83+
84+
# Read from /proc
85+
procfile = '/proc/loadavg'
86+
if Path.existsSync procfile
87+
data = Fs.readFileSync(procfile, 'utf-8')
88+
[one, five, fifteen] = data.split(' ', 3)
89+
server.push_metric "#{metricPrefix}.short", one
90+
server.push_metric "#{metricPrefix}.medium", five
91+
server.push_metric "#{metricPrefix}.long", fifteen
92+
```
93+
94+
And this is the `uptime.js` script:
95+
96+
```javascript
97+
var Os;
8398

84-
# Node os object makes this easy
85-
uptime = os.uptime()
86-
server.push_metric metricPrefix, uptime
99+
Os = require('os');
100+
101+
module.exports = function(server) {
102+
var run;
103+
104+
run = function() {
105+
var metricPrefix, uptime;
106+
metricPrefix = server.fqdn + ".uptime";
107+
server.cli.debug("Running uptime script");
108+
109+
// Node os object makes this easy
110+
uptime = Os.uptime();
111+
server.push_metric(metricPrefix, uptime);
112+
}
113+
return run;
114+
}
87115
```
88116

89117
Take a look at the code of the other scripts and you will see that there's nothing genius going on there.
@@ -94,5 +122,6 @@ License and author
94122
------------------
95123

96124
HoardD is licensed under the MIT License but please, send back your changes :). A copy of the license is included on the LICENSE file.
97-
You can probably read announcements and news on http://coredump.io
125+
126+
You can read announcements and news on http://coredump.io
98127

0 commit comments

Comments
 (0)