This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
service_handler.rb
62 lines (55 loc) · 2.08 KB
/
service_handler.rb
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
# Copyright (c) 2009-2012 VMware, Inc.
module Collector
class ServiceHandler < Handler
def initialize(tsdb_connection, job, index, now)
super(tsdb_connection, job, index, now)
end
def send_metric(name, value, tags = {})
default_tags = {:service_type => service_type,
:component => component}
tags = tags.merge(default_tags)
super(name, value, tags)
end
# Process healthy instances percent for each service, default is 0 if
# no instance provisioned.
#
def process_healthy_instances_metric(varz)
healthy_instances = 0
if varz["instances"]
total_instances = varz["instances"].length
healthy_instances = varz["instances"].values.count("ok")
if (total_instances != 0)
healthy_instances = format("%.2f",
healthy_instances.to_f / total_instances.to_f * 100)
end
end
send_metric("services.healthy_instances", healthy_instances)
end
# Sum up all nodes' available_capacity value for each service, report
# low_water & high_water value at the same time.
#
def process_plan_score_metric(varz)
return unless varz.include?("plans")
varz["plans"].each do |plan|
send_metric("services.plans.high_water", plan["high_water"] || 0, :plan => plan["plan"])
send_metric("services.plans.low_water", plan["low_water"] || 0, :plan => plan["plan"])
send_metric("services.plans.score", plan["score"] || 0, :plan => plan["plan"])
send_metric("services.plans.allow_over_provisioning",
plan["allow_over_provisioning"] ? 1 : 0, :plan => plan["plan"])
end if varz["plans"]
end
# Get online nodes varz for each service gateway, report the total
# number of online nodes
#
def process_online_nodes(varz)
return unless varz.include?("nodes")
send_metric("services.online_nodes", varz["nodes"].length)
end
def service_type # "mysql", "postgresql", "mongodb" ...
"unknown"
end
def component # "node", "gateway"
"unknown"
end
end
end