Skip to content

Instantly share code, notes, and snippets.

View ncdc's full-sized avatar

Andy Goldstein ncdc

View GitHub Profile
@ncdc
ncdc / -
Last active August 26, 2015 17:13
commit 7f0637c4b5703b8d2df0ac535f69addb5703820f
Author: Andy Goldstein <agoldste@redhat.com>
Date: Wed Aug 5 12:46:11 2015 -0400
Correct port-forward data copying logic
Correct port-forward data copying logic so that the server closes its
half of the data stream when socat exits, and the client closes its half
of the data stream when it finishes writing.
commit 7f0637c4b5703b8d2df0ac535f69addb5703820f
Author: Andy Goldstein <agoldste@redhat.com>
Date: Wed Aug 5 12:46:11 2015 -0400
Correct port-forward data copying logic
Correct port-forward data copying logic so that the server closes its
half of the data stream when socat exits, and the client closes its half
of the data stream when it finishes writing.
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@ncdc
ncdc / metric_handler.rb
Created February 28, 2014 16:29
Custom rsyslog output program to send metrics to Graphite via Carbon
#!/bin/env ruby
require 'time'
require 'socket'
class GraphiteClient
def carbon
begin
@carbon ||= TCPSocket.new('localhost', 2003)
rescue => e
class FilePlugin < MetricPlugin
def initialize(config)
super
end
def process(app, gear, timestamp, fields)
File.open("/root/gear_metrics.log", 'a') do |f|
fields.each do |key, value|
f.puts "#{app}.#{gear}.#{key} #{value} #{timestamp.to_i}"
end
#!/usr/bin/env oo-ruby
require 'openshift-origin-node'
require 'strscan'
gears = %w(533c34e04b85e4913e000009
533c38384b85e4913e000031
533c38294b85e4a2d6000015
533c38384b85e49c3c000003
533c38024b85e4913e00001d
/openshift/533c34e04b85e4913e000009:
cpu.rt_period_us: 1000000
cpu.rt_runtime_us: 0
cpu.stat: nr_periods 6266
nr_throttled 0
throttled_time 0
cpu.cfs_period_us: 100000
cpu.cfs_quota_us: 200000
cpu.shares: 512
cpuacct.stat: user 115
This file has been truncated, but you can view the full file.
[root@ip-10-146-206-12 ~]# strace -ttt -p `pgrep -f test.rb`
Process 9942 attached - interrupt to quit
1396887178.137657 read(5, "while true\n while !basename"..., 8192) = 6357
1396887178.138221 read(5, "", 8192) = 0
1396887178.138319 close(5) = 0
1396887178.138406 lstat("/opt", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
1396887178.138577 lstat("/opt/rh", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
1396887178.138738 lstat("/opt/rh/ruby193", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
1396887178.138913 lstat("/opt/rh/ruby193/root", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
1396887178.139044 lstat("/opt/rh/ruby193/root/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
return /opt/rh/ruby193/root/usr/share/ruby/monitor.rb:215 mon_synchronize MonitorMixin
return /opt/rh/ruby193/root/usr/share/ruby/logger.rb:576 write Logger::LogDevice
line /opt/rh/ruby193/root/usr/share/ruby/logger.rb:379 add Logger
return /opt/rh/ruby193/root/usr/share/ruby/logger.rb:380 add Logger
return /opt/rh/ruby193/root/usr/share/ruby/logger.rb:435 info Logger
return /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-node-1.23.0/lib/openshift-origin-node/utils/logger/split_trace_logger.rb:90 trace OpenShift::Runtime::NodeLogger::SplitTraceLogger
c-return /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-node-1.23.0/lib/openshift-origin-node/utils/shell_exec.rb:171 each Array
c-call /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-node-1.23.0/lib/openshift-origin-node/utils/shell_exec.rb:163 any? Enumerable
c-call /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-node-1.23.0/lib/openshift-origin-node/ut
diff --git a/node-util/conf/watchman/plugins.d/metrics_plugin.rb b/node-util/conf/watchman/plugins.d/metrics_plugin.rb
index b16fb6f..fa99ea9 100644
--- a/node-util/conf/watchman/plugins.d/metrics_plugin.rb
+++ b/node-util/conf/watchman/plugins.d/metrics_plugin.rb
@@ -71,11 +71,20 @@ module OpenShift
@cgroups_keys = @cgroups_keys.split(',').map(&:strip).join(' -r ')
end
+ Syslog.info "Initializing Watchman metrics plugin"
+