Top Level Namespace

Defined Under Namespace

Classes: PostgreStats

Instance Method Summary collapse

Instance Method Details

#counter_to_gauge(prefix, counter, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'bin/postgrestats', line 11

def counter_to_gauge(prefix, counter, value)
  field_name = [prefix, counter].join("_")
  if @counter_list[field_name].nil?
    @counter_list[field_name] = value.to_f
    return 0.0
  else
    ret = value.to_f - @counter_list[field_name]
    @counter_list[field_name] = value.to_f
    return ret
  end
end

#publish_aggregate_metric(stats_ds, publish_host, name, value, slope, units) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'bin/postgrestats', line 43

def publish_aggregate_metric(stats_ds, publish_host, name, value, slope, units)
  type = @watch_aggregate_double.include?(name) ? 'double' : 'uint32'
  c_value = @watch_aggregate_double.include?(name) ? value.to_f : value.to_i

  Ganglia::GMetric.send(
    stats_ds.config['gmond']['aggregate']['host'],
    stats_ds.config['gmond']['aggregate']['port'], {
      :name => name,
      :units => units,
      :type => type,
      :value => c_value,
      :tmax => 60,
      :dmax => 300,
      :group => 'staging_aggregate',
      :slope => slope,
      :spoof => 1,
      :hostname => "#{publish_host}:#{publish_host}"
  })
end

#publish_hierarchy(stats_ds, tree) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'bin/postgrestats', line 63

def publish_hierarchy(stats_ds, tree)
  tree.each_key do |table_name|
    if table_name =~ /aggregate/
      tree[table_name].each_key do |metric|
        publish_aggregate_metric(
          stats_ds,
          table_name,
          metric,
          tree[table_name][metric]['value'],
          tree[table_name][metric]['slope'],
          tree[table_name][metric]['units']
        )
      end
    else
      tree[table_name].each_key do |metric|
        publish_table_metric(
          stats_ds,
          table_name,
          metric,
          tree[table_name][metric]['value'],
          tree[table_name][metric]['slope'],
          tree[table_name][metric]['units']
        )
      end
    end
  end
end

#publish_table_metric(stats_ds, publish_host, name, value, slope, units) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'bin/postgrestats', line 23

def publish_table_metric(stats_ds, publish_host, name, value, slope, units)
  type = @watch_table_double.include?(name) ? 'double' : 'uint32'
  c_value = @watch_table_double.include?(name) ? value.to_f : value.to_i

  Ganglia::GMetric.send(
    stats_ds.config['gmond']['tables']['host'],
    stats_ds.config['gmond']['tables']['port'], {
      :name => name,
      :units => units,
      :type => type,
      :value => c_value,
      :tmax => 60,
      :dmax => 300,
      :group => 'staging_tables',
      :slope => slope,
      :spoof => 1,
      :hostname => "#{publish_host}:#{publish_host}"
   })
end