Posts Tagged “object”

I recently decided to do a fresh CentOS install on a web server with a minimal amount of sites on it because it seemed easier than attempting to upgrade everything. With a fresh install I figured I would be forced to get everything completed quicker. The server was upgraded from CentOS 5.1 to CentOS 5.3 and from ISPConfig 2.X to ISPConfig 3.X. One of the virtual host configurations was for a Nagios server that monitors a fairly large list of servers running various services from basic server items like CPU, Load, Disk Space, etc. all the way to complex PostgreSQL statistics and other custom items. There are numerous Perl scripts to monitor PostgreSQL including check_pg_connections.pl, check_pg_lock_status.pl, check_pg_max_xid.pl, check_pg_queries.pl, check_pg_time.pl, and check_pg_waiting_queries.pl. The scripts use the DBD-Pg Perl module to make a connection (remote or local) to PostgreSQL servers.

Read the rest of this entry »

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , , , , , , , , , , , , ,

Comments No Comments »

If you want to dynamically add a member to a Ruby object, use the hash/array brackets and symbol (:user_id) as shown in the iRb session below. As you can see the dot notation will not work.

>> d = AccessMode.find(1)
=> #<AccessMode id: 1, device_id: 31218, mode: "dialup", timestamp: "2007-12-25 15:52:55">
>> d[:user_id] = 5
=> 5
>> d
=> #<AccessMode id: 1, device_id: 31218, mode: "dialup", timestamp: "2007-12-25 15:52:55">
>> d.user_id
=> 5
>> d.user_id = 6
=> 6
>> d.session_id = 10
NoMethodError: undefined method `session_id=' for #<AccessMode:0x58dace8>
from C:/chirag no backup/haloror/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:251:in `method_missing'
from (irb):23
DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , ,

Comments No Comments »

I decided to use BackgrounDrb 0.2.1 to launch a periodic task that would run every 15 seconds.Warning: After going through the hassle of setting up BackgrounDrb, I found out that it isn’t even supported in Windows (my dev environment)! See step 8. So, these instructions haven’t been fully tested yet on a *.nix environment. Good luck and please post comments if you have any helpful suggestions.

  1. Install BackgroundDrb: svn co http://svn.devjavu.com/backgroundrb/tags/release-0.2.1 backgroundrb
  2. Setup BackgrounDrb: rake backgroundrb:setup
  3. Generate worker thread (Foo is capitalized): ruby script/generate worker Foo
  4. In one of your controllers, create new worker with Middleman object (:foo_worker is lowercase with underscore)
       MiddleMan.new_worker(:class => :foo_worker,
        :args => "Arguments used to instantiate a new HeartratepostWorker object",
  5. Instantiate Middleman object in environment.rb (you might not need this with version 0.2.1 of BackgrounDrb)
      require "drb"  DRb.start_service
    
      MiddleMan = DRbObject.new(nil, "druby://localhost:22222"
  6. Install the daemons gem if you haven’t already: gem install daemons
  7. Install the slave gem if you haven’t already: gem install slave
  8. Start the BackgroundDrb server in a separate command window: ruby script\backgroundrb start
    • If you get the error “ERROR: there is already one or more instance(s) of the program running”, delete log\backgroundrb.pid
    • Windows users are out of luck! You’ll get this message: `fork': the fork() function is unimplemented on this machine. Here’s a message from Ezra (the devleoper of BackgroundDrb) about Windows support:
      • “Unfortunately that won’t cut it in this case, I wish it would. Slave does more then just fork. It uses ipc and a few other things that just don’t work yet on windows. There is a possibility it could be made to work but right now it does not, even with win32 process (gem). -Ezra Wed Nov 29 16:19:03 EST 2006″
  9. Debugging methods if things don’t work well

Notes

  1. You might want to restart the backgroundrb server after you’ve modified the *_worker.rb file to lib/workers. It could cause an error otherwise.
  2. In case you get this error when starting Mongel, copy the vendor/plugins/backgroundrb directory to a temp directory and it will work

    already initialized constant OPTIONS

  3. To set up a periodic task, set up the Middleman object this way:
            session[:job_key] = worker
    
            MiddleMan.schedule_worker(
    
              :class => :heartrate_post_worker,
    
              :args => "some arg to do_work",
    
              :job_key => :simple_schedule,
    
              :trigger_args => {
    
                :start => Time.now,
    
                :end => Time.now + 10.minutes,
    
                :repeat_interval => 15.seconds
    
              }
    
            )

References

  1. Sending emails in the background with ActionMailer and BackgrounDRB
  2. Example using TTL (time to live)
DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , ,

Comments 3 Comments »

I recently installed a really nice set of charts and graphs called XML/SWF Charts using the Ziya plugin for Rails. The nice part is that it costs only $45 for your entire domain. This license fee will remove the link when you click on the chart (it currently goes to their website)

For the most part, the instructions in Ziya’s README were very good. I did run into a few snags, but they didn’t take me too long to figure out. Here’s a rundown. Hopefully this will make it even easier to implement Ziya and XML/SWF:

Under the “Steps” section of the the README:

1. If you get an error message when trying to install the Rails plugin on Windows, be sure to install the Window’s subversion client. This will install the command line svn client and add the subversion path to your environment variables. Be sure to open a new command prompt after installing the subversion client. This is the quickest way to get the latest version 0.12 of Ziya since they don’t make the latest code downloadable.

2. There’s an obvious typo in the following line

graph  = Ziya::Charts::Bar.new( license, title, chart_id )

I changed it to the following to get something working quickly:

graph  = Ziya::Charts::Line.new( nil, nil, "mychart" )

Here, "mychart" is the name of the YAML stylesheet which will be:

public/charts/default/mychart.yml

3. My biggest mistake: You can not instantiate the Ziya object in the controller corresponding to the chart’s view. It needs to be in a separate controller. Otherwise, an XML file (instead of a chart) will be returned when that controller is invoked.

In other words, if the following view code is in line_chart.rhtml file (note: here the ‘css_id’ is the id attribute for the <object> element that is rendered in the final HTML)

<%= ziya_chart( url_for( :controller => 'blee', :action => 'refresh_my_graph' ), :id => 'css_id', :bgcolor => "transparent", :width => 400, :height => 250 ) %>

Then you cannot put the following code in the line_chart controller

def line_chart
graph  = Ziya::Charts::Line.new( nil, nil, "mychart" )
graph.add( :axis_category_text, [ "Dog", "Cat", "Rat"] )
       graph.add( :series, "Series A", [10, -20, 30] )
       render :xml => graph.to_xml
end

The controller name needs to be different. They used refresh_my_graph as an example

4. The parameters passed into into the ziya_chart helper in the line_chart.rhtml file above apply to the canvas_bg property. These parameter apply to main canvas of the chart and cannot be specificed in the YAML file. The attributes for canvas_bg become part of the static html page.

The best way to specify attributes in the YAML stylesheet is to look at XML/SWF’s reference. It is very well documented and very understandble.

5. I was able to get their sample charting application working pretty quick. It’s the code for Ziya’s website. Download it by typing this at the command prompt (after you’ve done #1 above)

svn co svn://rubyforge.org/var/svn/liquidrail/samples/charting

After you download it, you will need to

a. Create a database called “ruby_dev” in your database server

b. Run db:migrate

Thanks a lot to the folks at maani.us for providing such a nice and rich set of graphs and charts for next to nothing. And also thanks to Fernand Galiana and Delynn Berry for such a nicely written plugin to the Rails community!

DeliciousStumbleUponDiggTwitterFacebookRedditLinkedInEmail
Tags: , , , , , , , , , , , , , ,

Comments 2 Comments »