Skip to content

Instantly share code, notes, and snippets.

View dalen's full-sized avatar

Erik Dalén dalen

View GitHub Profile
puppetdb=# select * from pg_stat_database where datname='puppetdb';
datid | datname | numbackends | xact_commit | xact_rollback | blks_read | blks_hit | tup_returned | tup_fetched | tup_inserted | tup_updated | tup_deleted | conflicts | stats_reset
-------+----------+-------------+-------------+---------------+------------+--------------+--------------+-------------+--------------+-------------+-------------+-----------+-------------------------------
16389 | puppetdb | 67 | 19350645 | 7158 | 5203673932 | 730840051209 | 296150976554 | 39856410308 | 3042400442 | 19151545 | 2915288790 | 0 | 2013-05-03 15:27:17.030942+00
@dalen
dalen / gist:5956412
Last active December 19, 2015 12:39
puppetdb=# select * from pg_stat_all_tables where schemaname='public';
relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del | n_tup_hot_upd | n_live_tup | n_dead_tup | last_vacuum | last_autovacuum | last_analyze | last_autoanalyze | vacuum_count | autovacuum_count | analyze_count | autoanalyze_count
-------+------------+-------------------------+----------+--------------+------------+---------------+------------+-----------+------------+---------------+------------+------------+-------------+-------------------------------+--------------+-------------------------------+--------------+------------------+---------------+-------------------
16455 | public | catalog_resources | 9122 | 39959606875 | 35291772 | 7313691435 | 809557259 | 0 | 802674911 | 0 | 5781907 | 1013101 | | 2013-07-08 22:33:51.260409+00 | | 2013-07-09 10:17:11
@dalen
dalen / gist:5956442
Last active December 19, 2015 12:39
puppetdb=# select * from pg_statio_all_tables where schemaname='public';
relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit
-------+------------+-------------------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
16455 | public | catalog_resources | 3342606866 | 9262119774 | 979685526 | 668733437342 | 0 | 0 | 0 | 0
16489 | public | schema_migrations | 7 | 31 | 14 | 41 | | | |
16552 | public | resource_events | 62059176 | 728183445 | 257889288 | 7405931285 | 47214 | 91996 | 983 | 215746
16539 | public | reports | 4749413 | 247689
# rather this:
# Sets up NTP client
class ntp (
$server # Server address
) {
...
}
# Determines which role a machine has.
# For example for lon2-pl4cassandra-a1 this will return 'pl4cassandra'
Facter.add('role') do
setcode do
if (Facter.fqdn =~ /[[:alpha:]]+\d*-([a-z0-9]+)-[[:alpha:]]+\d+/) == 0 then
next $1
end
nil
end
end
Puppet::Parser::Functions.newfunction(:query_nodes, :type => :rvalue, :arity => -2, :doc => <<-EOT
accepts two arguments, a query used to discover nodes, and a optional
fact that should be returned.
The query specified should conform to the following format:
(Type[title] and fact_name<operator>fact_value) or ...
Package["mysql-server"] and cluster_id=my_first_cluster
The second argument should be single fact (this argument is optional)
@dalen
dalen / gradual_deploy.rb
Created September 8, 2013 23:29
function to gradually deploy using puppet
module Puppet::Parser::Functions
newfunction(:gradual_deploy, :type => :rvalue, :arity => 4, :doc => "\
Gradually deploy something
Arguments are from, to, start and finish. Will gradually move from returning <from>
to returning <to> over the duration between <start> and <finish>.
start and finish are specified as ruby datetime strings, supports all formats that ruby
can parse.
") do |args|
from, to, start, finish = *args
"lib/puppet/indirector/facts/ohaifacter.rb" 14L, 544C
require 'puppet/node/facts'
require 'puppet/indirector/code'
class Puppet::Node::Facts::Ohaifacter < Puppet::Indirector::Code
desc "Retrieve facts from Ohai and Facter.
Merges facts from both facts terminii preferring Ohai facts if there is a conflict."
# Look up a host's facts
def find(request)
@dalen
dalen / mem_cache.conf
Created September 23, 2013 15:28
puppet apache file metadata caching
<IfModule mod_mem_cache.c>
CacheEnable mem /production/file_metadata
CacheEnable mem /production/file_content
CacheDefaultExpire 300
MCacheSize 1024000
MCacheMaxObjectCount 10000
MCacheMinObjectSize 1
MCacheMaxObjectSize 2048000
CacheIgnoreNoLastMod On
</IfModule>
@dalen
dalen / gist:6727254
Created September 27, 2013 11:32
puppetdb crash 1.4.0
/v2/facts query=["]
2013-09-27 11:31:09,132 WARN [qtp1667945037-129] [server.AbstractHttpConnection] /v2/facts
com.fasterxml.jackson.core.JsonParseException: Unexpected end-of-input: was expecting closing quote for a string value
at [Source: java.io.StringReader@3b642de4; line: 1, column: 7]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1369)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:599)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:532)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString2(ReaderBasedJsonParser.java:1517)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString(ReaderBasedJsonParser.java:1505)