Server Monitoring for Web Applications
by codejunkie on Mar.16, 2009, under Systems Management
I’ll be honest, I am a lot better at getting a project out of the door than maintaining it in the long run. I think this is a common problem for a lot of developers who are more interested in the creation than the sustainability of a project. However, I have also come to learn that, like it or not, I am going to have to do some level of system monitoring and management if I want to be able to fund those future projects. There is no point in creating an app that is going to fail the next day.
That being said, I decided to take a little time to look into the available resources out there for systems or server monitoring. While there are definitely quite a few solutions available, I needed to start on a budget. I deciced to go with Hyperic for myriad reasons, but here are just a few of them…
- It’s open source. Or, at least, there is a free open source version available to get me started. Frankly, I don’t have the time or money to waste on a closed-source app that might turn out not to serve my needs. More importantly, with companies going downhill fast, I didn’t want to get tied down by proprietary software which might not be updated if the company itself goes out of business. For me, this was a no brainer.
- Easy installation. I am not a sys admin. I am a programmer. I recognize the difference and I am not prepared to hire a sysadmin at this time. I needed something I could install, setup and deploy quickly. The open-source part of it alone made installation a lot quicker. I didn’t even need to speak with a service rep to get started.
- Scaling up. At some rapidly approaching point, I am going to have to get some professional help for these projects. Putting together my own solution would mean that I would have to train folks to get up to speed. Using Hyperic means I can just upgrade to their professional products and use their own existing support community.
I won’t pretend that Hyperic is the perfect solution for everyone. For example, I have to get the Enterprise edition for role-based access control and external authentication with LDAP - two things I am actually interested in eventually. However, compared to everything else available, this definitely made the most sense for my current projects and my projected growth. I definitely think that for systems management and server monitoring that Hyperic is the right choice.
Frustration
by Ian on May.03, 2007, under Learning Cakephp
Have you ever been stuck 10 - 20 miles out in the middle of nowwhere with a broken down car? Gas looks fine, temp. is fine. The engine turns but just not quite enough to start. You’re faced with a question. Walk the 20 miles which you know will get you where you’re going, or tinker with the car,which if you can get it working will get you there a whole lot faster.
That’s my experience with cake today. I’m still commited to using it. I’d like to help the community succeed, but the lack of significant documentation is crippling. Cake is great for the exact tasks that the tutorials outline, but after that it gets sketchy.
I’m working on a HasAndBelongsToMany (HABTM) article to try to explain how it works. It seems to only work when it wants to, and due to lack of documentation I can’t figure out when that is. I can’t find anything significant online at the moment, so I’ll be delving in to the code but if anyone would like to help or point a resource my way it’d be appreciated.
Thanks.
Javascript Helper pt. 2
by Ian on Apr.30, 2007, under Learning Cakephp
So I just read my last post about the javascript helper and I realized it makes little to no sense.
I was in a rush and just wanted to document the finding. Here’s a second try at explaining the js helper:
Using Javascript on your site.
1. Add the helper to the controller.
To use javascript in your cakephp site you need to first set the $helpers array in your controller to:
var $helpers = array('other_helper', 'javascript', 'other_helper');
You’ll probably be using other helpers already so just add the ‘javascript’ to the array.
2. Save your .js file under /app/webroot/js this is the conventional place to put all your js files and will make life easier for you if you use this directory.
3. Call your file from the template.
Since the call
needs to be in the header of your page and all of your view templates get inserted after the
link(”myfile.js”);?>
If you only want to include this in one page or in a class of pages you can create another layout template and call that from your controller using the $layout variable or the
setLayout() function.
Iif you must use an externally located .js file you can use the function $javascript->linkOut($url);
4. Use your javascript.
Now instead of writing out $javascript->codeBlock("function();"); and that will insert the script tags for you.
As of yet I don’t have much experience with the javascript helper so here is a list of functions litterally copied and pasted out of the 1.1 Helper:Javascript code. I’ll write more as I use the helper more.
codeBlock
* Returns a JavaScript script tag.
*
* @param string $script The JavaScript to be wrapped in SCRIPT tags.
* @param boolean $allowCache Allows the script to be cached if non-event caching is active
* @return string The full SCRIPT element, with the JavaScript inside it.
escapeScript
* Escape carriage returns and single and double quotes for JavaScript segments.
*
* @param string $script string that might have javascript elements
* @return string escaped string
escapeString
* Escape a string to be JavaScript friendly.
*
* List of escaped ellements:
* + “\r\n” => ‘\n’
* + “\r” => ‘\n’
* + “\n” => ‘\n’
* + ‘”‘ => ‘\”‘
* + “‘” => “\\’”
*
* @param string $script String that needs to get escaped.
* @return string Escaped string.
event
* Attach an event to an element. Used with the Prototype library.
*
* @param string $object Object to be observed
* @param string $event event to observe
* @param string $observer function to call
* @param boolean $useCapture default true
* @return boolean true on success
cacheEvents
* Cache JavaScript events created with event()
*
* @param boolean $file If true, code will be written to a file
* @param boolean $all If true, all code written with JavascriptHelper will be sent to a file
* @return void
writeEvents
* Write cached JavaScript events
*
* @return string
object
* Generates a JavaScript object in JavaScript Object Notation (JSON)
* from an array
*
* @param array $data Data to be converted
* @param boolean $block Wraps return value in a block if true
* @param string $prefix Prepends the string to the returned data
* @param string $postfix Appends the string to the returned data
* @param array $stringKeys A list of array keys to be treated as a string
* @param boolean $quoteKeys If false, treats $stringKey as a list of keys *not* to be quoted
* @param string $q The type of quote to use
* @return string A JSON code block
dAuth v0.3 tarball
by Ian on Apr.01, 2007, under Learning Cakephp
Dieter Plaetinck has created a really well thought-out user authentication system, dAuth for cakephp.
Php security can be a tricky beast, and web programmers can never learn enough about it. Dieter has evolved this project in bakery articles and it’s very useful to go through and read them all. Once you have and you understand how they work it’d be nice to be able to download all the code examples at once so that you can play with them easily in your cake project/favorite editor.
Well I’ve compiled all the code taken directly from his posted examples and put them in a tarball here.
Enjoy, but remember, it’s a bad idea to just copy/paste code from anywhere and use it in a production system. I suggest using this code as a template or learning example, before writing your own modified authentication code.
Mad Props Dieter,
Ian
Javascript Helper.
by Ian on Mar.30, 2007, under Learning Cakephp
How does the javascript helper work?
$javascript->link() function.
Youl’d think there’d be a section in the manual under the helpers saying:
Css helper, called by $css->function(). Here’s a list of fuctions.
Javascript helper, called by $javascript->function(). etc.
It looks like the rule of thumb is the full word, lowercase, prefixed with a $ sign, and be sure to add the Helper name in your controller. So to use the javascript ( along with html and form) helper:
I set $var $helpers = (’Html’, ‘Form’, ‘Javascript’); in my controller.
Advanced Model functions
by Ian on Mar.23, 2007, under Learning Cakephp
|
How to use models and controllers in your webpages.
by Ian on Mar.23, 2007, under Learning Cakephp
When first getting started I was quite perplexed as how to build a page that has more than one model and controller attached to it.
If /users/index runs the Users::index() function and the users controller uses the User model then how do I look at data from, say a Profile model on that page? What if I want to have my login function on that page as well?
Well once you get your head around it it’s not that tough, but it took me an embarrassingly long time to get my head around it.
By default the page you go to example.com/users/index is loading the app/views/users/index.thtml file. It’s also running the function index() in app/controllers/users_controller.php and loading the app/models/user.php.
The model tells cake how to interact with the database, and what tables to access.
The controller possibly runs some logic and passes variables to the view.
But the view is in control here. The view loads the html, displays the variables the controller passed (using the set function), and links and forms etc.
So if you want a login form on your index page you simply put that form in your index view and have it submit to /users/login (or whatever function handles the login logic). When you submit that form you’re running that function, not before.
If you want to display information generated (by business logic) in other functions then you can run those functions inside of your index() function. But I think more often you’ll probably want to load data from other models.
I’ll talk about that and the details in my next post.
How does CSS work in CakePhp?
by Ian on Mar.23, 2007, under Learning Cakephp
To use cakephp’s framework to the fullest, you need to utilize its conventions. To modify the default template for your site copy:
/cake/libs/view/templates/layouts/default.thtml to /app/views/layouts/
You then edit that copied file. The presence of
/app/views/layouts/default.thtml
tells cake to stop looking at the old layout and look at the new one.
So you’d think that it would work the same way with css. Well almost. You don’t need to copy the css file, it’s already there for you in
/app/webroot/css/cake.generic.css
Ok great. Just delete that and copy your new css over the old stuff right? No, that’s not a great idea. If you do that you’ll lose all the cool cakephp css classes that you may want to take advantage of later on. For example ‘required’ and ‘optional’ classes for your form labels. Let’s keep the generic css and overwrite it’s classes as we need them.
How do we do that? Let’s go to the default.thtml and we’ll see:
$html->css('cake.generic');
That’s the same as putting
<link rel="stylesheet" type="text/css" href="/ProjectPath/css/cake.generic.css" />
In your html code. Well that’s not exactly what we want to use because we want to use the @import url code to import our css files rather than link them.
Luckily the HtmlHelper::css function has an import option. So we use:
$html->css(’cake.custom’, import);
which yields :
@import url(ProjectPath/css/cake.custom.css);
between style tags.
Now that you have an idea of how the html helper css function works you can check out how to auto-load your css files for each controller.
Thanks,
Ian
Hi, my name is Ian and I program in the Cakephp framework.
by Ian on Mar.23, 2007, under Learning Cakephp
“Hi Ian”
I’m a new developer that has been happily <a href=”http://bakery.cakephp.org/articles/view/159″>seduced</a> into doing a project or two in the Cakephp framework.
I’m starting this blog because I feel that the learning curve is still a little bit to high, and despite some very good efforts from the cakephp <a href=”http://bakery.cakephp.org/”>community</a> and <a href=”https://www6.software.ibm.com/developerworks/education/os-php-cake1/”>others</a> to welcome newcomers most of the documentation is either in the form of tutorials, the manual, or message boards.
The tutorials that are out there are great but they can only do so much. The manual is still young and needs more content, and as we all know you can only expect so much out of message boards, sometimes they have exactly what you want, sometimes not.
The theme I get from the manual and the message boards is “if you knew how to use cake this would be easy”. The theme should be “You’re probably very smart, but you’ve got no experience with our way of doing things and you’ve done this your own way many times before, let’s give you the resources you need to start programming more effectively”.
This is my first post, look out for more posts, asking questions, and giving answers on the fundamentals of cakephp.
Thanks,
Ian