cf_light_api 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cf_light_api/worker.rb +27 -3
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 892f44f1093e2c4dbe2e195463dafbe2a4038ec3
|
4
|
+
data.tar.gz: 516a3ddd90bc674dd5ccb9dd8ff4fbaefb3ce586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b4a1be614230c15fea449956cb6935648ddddbe5add1a750c390cca984531b1e385d4b6581f9fc7d0e36c8a774dc094dbb9a1f3d26a46afd78dc0fb9662b999
|
7
|
+
data.tar.gz: 40fe1395ff99687ecce09ddc7ee9fdb16a0447889d2af427780d83964b3afbd8582d131bd9f79d4f55c6cd6d6a2e2b6a3075a3b72b6e55c01ab2012d2257b742
|
data/lib/cf_light_api/worker.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rufus-scheduler'
|
|
4
4
|
require 'parallel'
|
5
5
|
require 'redlock'
|
6
6
|
require 'logger'
|
7
|
+
require 'graphite-api'
|
7
8
|
|
8
9
|
@logger = Logger.new(STDOUT)
|
9
10
|
@logger.formatter = proc do |severity, datetime, progname, msg|
|
@@ -28,6 +29,10 @@ scheduler = Rufus::Scheduler.new
|
|
28
29
|
|
29
30
|
scheduler.every UPDATE_INTERVAL, :first_in => '5s', :overlap => false, :timeout => UPDATE_TIMEOUT do
|
30
31
|
cf_client = nil
|
32
|
+
|
33
|
+
graphite = if ENV['GRAPHITE'] then GraphiteAPI.new(graphite: ENV['GRAPHITE']) end
|
34
|
+
@logger.info "Sending data to graphite server #{ENV['GRAPHITE']}" if graphite
|
35
|
+
|
31
36
|
begin
|
32
37
|
lock_manager.lock("#{ENV['REDIS_KEY_PREFIX']}:lock", 5*60*1000) do |lock|
|
33
38
|
if lock
|
@@ -38,7 +43,7 @@ scheduler.every UPDATE_INTERVAL, :first_in => '5s', :overlap => false, :timeout
|
|
38
43
|
cf_client = get_client()
|
39
44
|
|
40
45
|
org_data = get_org_data(cf_client)
|
41
|
-
app_data = get_app_data(cf_client)
|
46
|
+
app_data = get_app_data(cf_client, graphite)
|
42
47
|
|
43
48
|
put_in_redis "#{ENV['REDIS_KEY_PREFIX']}:orgs", org_data
|
44
49
|
put_in_redis "#{ENV['REDIS_KEY_PREFIX']}:apps", app_data
|
@@ -64,7 +69,22 @@ def get_client(cf_api=ENV['CF_API'], cf_user=ENV['CF_USER'], cf_password=ENV['CF
|
|
64
69
|
client
|
65
70
|
end
|
66
71
|
|
67
|
-
def
|
72
|
+
def send_data_to_graphite(data, graphite)
|
73
|
+
org = data[:org]
|
74
|
+
space = data[:space]
|
75
|
+
name = data[:name].sub ".", "_" # Some apps have dots in the app name
|
76
|
+
|
77
|
+
data[:instances].each_with_index do |instance_data, index|
|
78
|
+
instance_data[:stats][:usage].each do |key, value|
|
79
|
+
if key != :time
|
80
|
+
graphite_key = "cf_apps.#{org}.#{space}.#{name}.#{index}.#{key}"
|
81
|
+
graphite.metrics graphite_key => value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_app_data(cf_client, graphite)
|
68
88
|
Parallel.map(cf_client.organizations, :in_processes => PARALLEL_MAPS) do |org|
|
69
89
|
org_name = org.name
|
70
90
|
Parallel.map(org.spaces, :in_processes => PARALLEL_MAPS) do |space|
|
@@ -73,7 +93,11 @@ def get_app_data(cf_client)
|
|
73
93
|
Parallel.map(space.apps, :in_processes => PARALLEL_MAPS) do |app|
|
74
94
|
begin
|
75
95
|
# It's possible for an app to have been terminated before this stage is reached.
|
76
|
-
format_app_data(app, org_name, space_name)
|
96
|
+
formatted_app_data = format_app_data(app, org_name, space_name)
|
97
|
+
if graphite
|
98
|
+
send_data_to_graphite(formatted_app_data, graphite)
|
99
|
+
end
|
100
|
+
formatted_app_data
|
77
101
|
rescue CFoundry::AppNotFound
|
78
102
|
next
|
79
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf_light_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Springer Platform Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cfoundry
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.1.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: graphite-api
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.1.6
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.1.6
|
97
111
|
description: A super lightweight API for reading App and Org data from CloudFoundry,
|
98
112
|
cached in Redis.
|
99
113
|
email: ''
|
@@ -102,9 +116,9 @@ executables:
|
|
102
116
|
extensions: []
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
105
|
-
- ./lib/sinatra/cf_light_api.rb
|
106
119
|
- ./lib/cf_light_api/redis.rb
|
107
120
|
- ./lib/cf_light_api/worker.rb
|
121
|
+
- ./lib/sinatra/cf_light_api.rb
|
108
122
|
- bin/cf_light_api
|
109
123
|
homepage: https://github.com/springerpe/cf-light-api
|
110
124
|
licenses:
|
@@ -126,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
140
|
version: '0'
|
127
141
|
requirements: []
|
128
142
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.4.6
|
130
144
|
signing_key:
|
131
145
|
specification_version: 4
|
132
146
|
summary: A super lightweight API for reading App and Org data from CloudFoundry, cached
|