-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCM2CW.coffee
84 lines (71 loc) · 2.66 KB
/
CM2CW.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
request = require 'request'
aws = require 'aws-sdk'
config =
environment: process.env.NODE_ENV or 'development'
region: process.env.AWS_REGION or 'us-east-1'
namespace: process.env.CLOUDWATCH_NAMESPACE or 'Cloudera'
hostname: process.env.CLOUDERA_HOSTNAME or 'http://localhost'
port: process.env.CLOUDERA_API_PORT or 7180
clustername: process.env.CLOUDERA_CLUSTERNAME
username: process.env.CLOUDERA_USERNAME or 'admin'
password: process.env.CLOUDERA_PASSWORD
baseurl = config.hostname+':'+config.port+'/api/v9/clusters/'
unless config.password?
console.log 'Please set CLOUDERA_PASSWORD environment variable'
process.exit(1)
unless config.hostname?
console.log 'Please set CLOUDERA_HOSTNAME environment variable'
process.exit(1)
unless config.clustername?
console.log 'CLOUDERA_CLUSTERNAME not set;\n
Deriving from first array element "items[0].displayName":'
cloudwatch = new (aws.CloudWatch)
region: config.region
apiVersion: '2010-08-01'
#=========================================
baseURLoptions =
method: 'GET'
url: baseurl
headers: 'authorization': "Basic "+
new Buffer(config.username+':'+
config.password).toString("base64")
request baseURLoptions, (error, response, body) ->
throw new Error(error) if error
for item in JSON.parse(body).items
clustername = config.clustername ? item.displayName
console.log ' '+clustername
# #=========================================
options =
method: 'GET'
url: baseurl+clustername+'/services'
headers: 'authorization': "Basic "+
new Buffer(config.username+':'+
config.password).toString("base64")
metricData = []
request options, (error, response, body) ->
throw new Error(error) if error
for item in JSON.parse(body).items
for healthcheck in item.healthChecks
unless healthcheck.suppressed
metricData.push
Dimensions: [
{
Name: 'healthcheck_name'
Value: healthcheck.name
}
{
Name: 'environment'
Value: config.environment
}
]
Value: (if healthcheck.summary == 'GOOD' then 1 else 0)
MetricName: 'ClouderaServiceStatus'
while metricData.length > 0
truncatedMetricData = metricData.slice(0,20)
metricData = metricData.slice(20)
cloudwatch.putMetricData {
Namespace: config.namespace
MetricData: truncatedMetricData
}, (err, data) ->
console.log err, err.stack if err
console.log data if data