-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit of data from old location
- Loading branch information
0 parents
commit a48fc40
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM ruby:2.6-alpine | ||
|
||
RUN gem install awesome_print elasticsearch optimist | ||
COPY src/spacemon.rb /usr/local/bin/spacemon.rb | ||
COPY src/docker_entrypoint.sh /docker_entrypoint.sh | ||
RUN chmod a+x /docker_entrypoint.sh | ||
ENTRYPOINT /docker_entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: spacemon | ||
labels: | ||
com.theguardian.app: Multimedia | ||
com.theguardian.stack: spacemon | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 5 #clean up replica sets older than this | ||
selector: | ||
matchLabels: | ||
com.theguardian.app: Multimedia | ||
com.theguardian.stack: spacemon | ||
template: | ||
metadata: | ||
labels: | ||
com.theguardian.app: Multimedia | ||
com.theguardian.stack: spacemon | ||
spec: | ||
nodeSelector: | ||
has-san: "true" | ||
containers: | ||
- image: published-image-here | ||
name: spacemon | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
env: | ||
- name: ELASTICSEARCH_HOST | ||
value: elasticsearch:9200 | ||
- name: SLEEP_TIME | ||
value: "120" | ||
- name: FILTER | ||
value: "/srv" | ||
#mount the volumes you want to scan here | ||
#volumeMounts: | ||
#configure the volumes that you want to scan as hostPath volumes here, | ||
#then mount them above in volumeMounts | ||
#volumes: | ||
|
||
restartPolicy: Always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
|
||
if [ "$SLEEP_TIME" == "" ]; then | ||
SLEEP_TIME=60 | ||
fi | ||
|
||
while `/bin/true`; do | ||
ruby /usr/local/bin/spacemon.rb --elasticsearch $ELASTICSEARCH_HOST --filter $FILTER | ||
if [ "$?" != "0" ]; then | ||
echo Command failed, exiting | ||
exit $? | ||
fi | ||
sleep $SLEEP_TIME | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'elasticsearch' | ||
require 'logger' | ||
require 'awesome_print' | ||
require 'socket' | ||
require 'optimist' | ||
|
||
INDEXNAME = "diskspace" | ||
TYPENAME = "diskspace" | ||
|
||
#START MAIN | ||
opts = Optimist::options do | ||
opt :elasticsearch, "Elasticsearch hosts", :type=>:string | ||
opt :filter, "Only include these filesystems. Specify as a regex.", :type=>:string | ||
end | ||
|
||
lines = `df -P`.split(/\n/) | ||
|
||
have_header = false | ||
header = [] | ||
|
||
content = [] | ||
|
||
lines.each {|line| | ||
if not have_header | ||
header = line.split(/\s+/) | ||
have_header = true | ||
next | ||
end | ||
|
||
parts = /^(.*\S)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)%\s+(.*)$/.match(line) | ||
if parts | ||
data = Hash[header.zip(parts.captures)] | ||
data.each {|k,v| | ||
begin | ||
data[k] = Integer(v) | ||
rescue StandardError | ||
end | ||
|
||
} | ||
data['Hostname'] = Socket.gethostname | ||
data['Timestamp'] = DateTime.now | ||
content << data | ||
end | ||
|
||
} | ||
|
||
if opts.filter | ||
ap opts.filter | ||
matcher = Regexp.compile(opts[:filter]) | ||
filtered_content = content.filter { |entry| | ||
matcher.match(entry["Mounted"]) | ||
} | ||
else | ||
filtered_content = content | ||
end | ||
|
||
ap filtered_content | ||
|
||
if opts.elasticsearch | ||
es = Elasticsearch::Client.new(:hosts=>opts.elasticsearch) | ||
result=es.cluster.health | ||
|
||
ops = [] | ||
filtered_content.each do |entry| | ||
ops << {index: {_index: INDEXNAME, _type: TYPENAME, data: entry}} | ||
end | ||
es.bulk(body: ops) | ||
end |