<commit_before>What?
=====

Small DSL in progress to describe a graphite graph.

If you have data like in graphite:

	devco_net
	`-- munin
	    `-- cpu
		|-- idle
		|-- iowait
		|-- irq
		|-- nice
		|-- softirq
		|-- steal
		|-- system
		`-- user

You can describe the data like this:

_cpu/irq.graph_:

	title   "CPU IRQ Usage"
	vtitle  "percent"
	area    :stacked

	service :munin, :cpu do
	  field :irq,    :derivative => true,
			 :scale => 0.001,
			 :color => "red",
			 :alias => "IRQ"

	  field :softirq, :derivative => true,
			  :scale => 0.001,
			  :color => "yellow",
			  :alias => "Batched IRQ"
	end

_cpu/overview.graph_

	title   "CPU Usage"
	vtitle  "percent"
	area    :stacked
	width   500
	height  250
	from	"-2hour"

	service :munin, :cpu do
	  field :iowait, :derivative => true,
			 :scale => 0.001,
			 :color => "red",
			 :alias => "IO Wait"

	  field :system, :derivative => true,
			 :scale => 0.001,
			 :color => "orange",
			 :alias => "System"

	  field :user,   :derivative => true,
			 :scale => 0.001,
			 :color => "yellow",
			 :alias => "User"
	end


To use these 2 files in your own code simply do:

	g = GraphiteGraph.new("cpu/overview.graph", {}, :hostname => "devco_net")
	puts g.url

This will produce:

       title=CPU Usage&vtitle=percent&from=-2hour&width=500&height=250&areaMode=stacked&target=alias(scale(derivative(devco_net.munin.cpu.iowait),0.001),"IO Wait")&target=alias(scale(derivative(devco_net.munin.cpu.system),0.001),"System")&target=alias(scale(derivative(devco_net.munin.cpu.user),0.001),"User")&colorList=red,orange,yellow

You can also mix in any other kind of target:


	title   "Combined CPU Usage"
	vtitle  "percent"
	area    :stacked

	field :iowait, :scale => 0.001,
		       :color => "red",
		       :alias => "IO Wait",
		       :data  => "sumSeries(derivative(mw*munin.cpu.iowait))"

	field :system, :scale => 0.001,
		       :color => "orange",
		       :alias => "System",
		       :data  => "sumSeries(derivative(mw*.munin.cpu.system))"

	field :user, :scale => 0.001,
		     :color => "yellow",
		     :alias => "User",
		     :data  => "sumSeries(derivative(mw*.munin.cpu.user))"

This will use totally custom targets but still let you use some helpers for color etc.

In all cases the items will appear on the graph in the order it appears in the file
<commit_msg>Improve examples<commit_after>What?
=====

Small DSL in progress to describe a graphite graph.

If you have data like in graphite:

	devco_net
	`-- munin
	    `-- cpu
		|-- idle
		|-- iowait
		|-- irq
		|-- nice
		|-- softirq
		|-- steal
		|-- system
		`-- user

You can describe the data like this:

_cpu/irq.graph_:

	title   "CPU IRQ Usage"
	vtitle  "percent"
	area    :stacked

	# helper to locate data in the tree.  You give it
	# the hostname in the constructor - see later example -
	# and it will then find mun/cpu/irq for example in
	# that specific host data tree
	service :munin, :cpu do
	  field :irq,    :derivative => true,
			 :scale => 0.001,
			 :color => "red",
			 :alias => "IRQ"

	  field :softirq, :derivative => true,
			  :scale => 0.001,
			  :color => "yellow",
			  :alias => "Batched IRQ"
	end

_cpu/overview.graph_

	title   "CPU Usage"
	vtitle  "percent"
	area    :stacked
	width   500
	height  250
	from	"-2hour"

	service :munin, :cpu do
	  field :iowait, :derivative => true,
			 :scale => 0.001,
			 :color => "red",
			 :alias => "IO Wait"

	  field :system, :derivative => true,
			 :scale => 0.001,
			 :color => "orange",
			 :alias => "System"

	  field :user,   :derivative => true,
			 :scale => 0.001,
			 :color => "yellow",
			 :alias => "User"
	end

	# draws a vertical line for every time that puppet ran on the host
	# info is the hash that gets passed into the constructor, see later
	# example
	field :puppet, :color => "blue",
		       :alias => "Puppet Run",
		       :data  => "drawAsInfinite(#{info[:hostname}.puppet.time.total)"

To use these 2 files in your own code simply do:

	g = GraphiteGraph.new("cpu/overview.graph", {}, :hostname => "devco_net")
	puts g.url

This will produce:

       title=CPU Usage&vtitle=percent&from=-2hour&width=500&height=250&areaMode=stacked&target=alias(scale(derivative(devco_net.munin.cpu.iowait),0.001),"IO Wait")&target=alias(scale(derivative(devco_net.munin.cpu.system),0.001),"System")&target=alias(scale(derivative(devco_net.munin.cpu.user),0.001),"User")&colorList=red,orange,yellow

You can also mix in any other kind of target:


	title   "Combined CPU Usage"
	vtitle  "percent"
	area    :stacked

	field :iowait, :scale => 0.001,
		       :color => "red",
		       :alias => "IO Wait",
		       :data  => "sumSeries(derivative(mw*munin.cpu.iowait))"

	field :system, :scale => 0.001,
		       :color => "orange",
		       :alias => "System",
		       :data  => "sumSeries(derivative(mw*.munin.cpu.system))"

	field :user, :scale => 0.001,
		     :color => "yellow",
		     :alias => "User",
		     :data  => "sumSeries(derivative(mw*.munin.cpu.user))"

This will use totally custom targets but still let you use some helpers for color etc.

In all cases the items will appear on the graph in the order it appears in the file

{'fraction_non_alphanumeric': 0.14824850009676796, 'fraction_numerical': 0.022837236307335012, 'mean_word_length': 2.9784449576597383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4833582', 'n_tokens_mistral': 2117, 'n_tokens_neox': 1782, 'n_words': 520}