|By David Shadovitz||
|August 23, 2002 12:00 AM EDT||
As a member of Team Macromedia I respond to a lot of questions posted on the Macromedia Forums ( http://webforums.macromedia.com/coldfusion).
My responses often contain sample code, and I realized that many questions arose over and over again. So rather than repeatedly typing the same code snippets, I created a small Web site ( http://members.evolt.org/dshadovi) to hold them. Now I can simply point to the relevant page when I respond to a question.
Being a nosy guy, I wanted to know how the site was being used. Yes, there are tools that do a wonderful job of presenting this information, such as Analog and WebTrends. But they require access to the Web server logs, which I don't have. Anyway, I wanted to roll my own. That's the fun of CF!
My first cut at tracking traffic was to use session management and CFMAIL. I set up Application.cfm to send me a message whenever a new session was started. It worked, but sometimes the mail was overwhelming. The biggest problem with this technique, though, was that it made it hard to perform analysis. I couldn't easily determine which page was getting the most hits, or how many visitors use Netscape.
The right technique, and the one I'll describe in detail, is to record the site traffic in a database and use CF's graphing capabilities to display it.
Recording the Site Traffic
Using MySQL, I created a single table to record information on each hit. Listing 1 shows the structure of that table. As you can see, each record contains the page visited, the visitor's IP address and browser (the user agent), and the date and time of the visit.
A record is inserted into that database table each time the site is hit. Listing 2 shows the code to do this. This code belongs in Application.cfm.
Note that the INSERT statement doesn't include the time of the hit. When no value is specified for a field of type TIMESTAMP, which cannot be null, MySQL automatically inserts the current date and time. I could have passed the value #CreateODBC DateTime(Now())#, but it's more efficient to let the database take care of it.
You'll also see that I've massaged the name of the page a bit. For all of the pages on my site, CGI.SCRIPT_ NAME starts with "dshadovi/", so I strip this off. I also strip off the ".cfm" extension, since the name of the page, not the extension, is what's important for the graphical display of the traffic.
Don't chide me for not using CFQUERYPARAM. I do use it, but I omitted it here in the interest of readability.
Displaying the Site Traffic
Now that the pieces are in place to record the site traffic, we're ready to write the code to graphically display it. Listing 3 is a complete CFML template that does exactly that. Figure 1 is a screenshot of this template in action; you can also see it live at http://members.evolt.org/dshadovi/traffic.cfm.
An exception is an error that occurs at runtime. Most if not all programming languages offer a way to handle exceptions. The goal of this handling is to minimize the damage done by the exception. Sometimes it's possible to repair the problem or to work around it. If not, the application can at least provide a detailed error message.
ColdFusion provides CFTRY/CFCATCH, modeled on C's try/catch statements. Using this construct, the ColdFusion Server tries to execute a designated block of code, and if it catches any exceptions it executes another designated block of code.
I use CFTRY/CFCATCH in Listings 2 and 3. Let's take a closer look.
Listing 2 shows a snippet of code in Application.cfm, which inserts a record into the database. The record contains information about the current page visit. Now, the main goal of my Web site is to provide helpful code to other programmers. Tracking visits to the site is only a minor goal, mostly to satisfy my curiosity. I certainly wouldn't want problems with this minor goal to interfere with my major goal.
What kinds of problems might happen? Well, the database server could go down, or the database's transaction log may be full. Either of these would make it impossible to insert a record, but there's no reason why that should render my site unusable. So I put the CFQUERY tag in a CFTRY block. If there are any runtime errors, the CFCATCH code block is executed. The CFCATCH block here is empty because there's no remedial action to take. If a record can't be inserted, that's okay. Execution continues on with whatever code follows the entire CFTRY block.
In Listing 2 the protected code block, a CFQUERY tag, did under-the-covers work. Not so for Listing 3, in which the protected code block is a CFGRAPH tag. There is surely a user impact if the graph isn't displayed. So in this case the CFCATCH block isn't empty. Rather, it lets the user know there should have been a graph, and points to a possible cause of the problem. (Okay, I should also have code here to automatically e-mail the details of the problem to the server administrator, or to log the problem.)
I've shown here two uses of CFTRY/CFCATCH. Beyond this, CFTRY's TYPE attribute lets you take different actions based on the type of exception. The ColdFusion Server also provides CFCATCH variables that contain details of the exception. And CFTHROW gives you the power to declare that an exception has taken place.
Using CFTRY/CFCATCH to handle exceptions lets you compartmentalize your code, leading to more robust applications.
The code uses CFGRAPH, introduced in CF5. Those of you using earlier versions of CF are not out of luck, though. You laggards can use the old bar chart Java graphlet that used to come with CF. Do a Google search on "About ColdFusion Graphlets" for more information, or contact me. At the other end of the spectrum ColdFusion MX offers CFCHART in place of CFGRAPH, but that should be a straightforward change.
Each bar in the bar graph represents a page, and the bar's height indicates the number of hits on that page. CFGRAPH's URLColumn attribute provides a drill-down capability when using the Flash format. I've set it up so that clicking on a bar will lead you to that bar's page.
You may notice that although I record each visitor's IP address, I don't display it anywhere. That's because I record it for hacker control, not for a simple view of the site traffic.
A programmer's work is never done (especially when he's got a paying client), so here are some thoughts for future enhancements:
Let me close with thanks to evolt.org, a community for Web developers, for hosting my site.
|David Shadovitz 11/01/02 04:00:00 PM EST|
I've found a good use for my traffic information. One site which I track contains an important search feature. Now, on the page which displays the form for a search, I also display the user's last few searches. They are displayed as hyperlinks which the user can simply click on to re-do a search.
SYS-CON Events announced today that ContentMX, the marketing technology and services company with a singular mission to increase engagement and drive more conversations for enterprise, channel and SMB technology marketers, has been named “Sponsor & Exhibitor Lounge Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York City, New York. “CloudExpo is a great opportunity to start a conversation with new prospects, but what happens after the...
May. 30, 2016 06:45 PM EDT Reads: 1,433
WebRTC is bringing significant change to the communications landscape that will bridge the worlds of web and telephony, making the Internet the new standard for communications. Cloud9 took the road less traveled and used WebRTC to create a downloadable enterprise-grade communications platform that is changing the communication dynamic in the financial sector. In his session at @ThingsExpo, Leo Papadopoulos, CTO of Cloud9, will discuss the importance of WebRTC and how it enables companies to fo...
May. 30, 2016 04:30 PM EDT Reads: 2,634
The IoT is changing the way enterprises conduct business. In his session at @ThingsExpo, Eric Hoffman, Vice President at EastBanc Technologies, discuss how businesses can gain an edge over competitors by empowering consumers to take control through IoT. We'll cite examples such as a Washington, D.C.-based sports club that leveraged IoT and the cloud to develop a comprehensive booking system. He'll also highlight how IoT can revitalize and restore outdated business models, making them profitable...
May. 30, 2016 02:00 PM EDT Reads: 3,077
SYS-CON Events announced today that MangoApps will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. MangoApps provides modern company intranets and team collaboration software, allowing workers to stay connected and productive from anywhere in the world and from any device. For more information, please visit https://www.mangoapps.com/.
May. 30, 2016 01:30 PM EDT Reads: 1,141
SYS-CON Events announced today the How to Create Angular 2 Clients for the Cloud Workshop, being held June 7, 2016, in conjunction with 18th Cloud Expo | @ThingsExpo, at the Javits Center in New York, NY. Angular 2 is a complete re-write of the popular framework AngularJS. Programming in Angular 2 is greatly simplified. Now it’s a component-based well-performing framework. The immersive one-day workshop led by Yakov Fain, a Java Champion and a co-founder of the IT consultancy Farata Systems and...
May. 30, 2016 12:00 PM EDT Reads: 4,122
What a difference a year makes. Organizations aren’t just talking about IoT possibilities, it is now baked into their core business strategy. With IoT, billions of devices generating data from different companies on different networks around the globe need to interact. From efficiency to better customer insights to completely new business models, IoT will turn traditional business models upside down. In the new customer-centric age, the key to success is delivering critical services and apps wit...
May. 30, 2016 11:15 AM EDT Reads: 1,353
Join us at Cloud Expo | @ThingsExpo 2016 – June 7-9 at the Javits Center in New York City and November 1-3 at the Santa Clara Convention Center in Santa Clara, CA – and deliver your unique message in a way that is striking and unforgettable by taking advantage of SYS-CON's unmatched high-impact, result-driven event / media packages.
May. 30, 2016 11:00 AM EDT Reads: 2,589
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, will provide an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life ...
May. 30, 2016 10:45 AM EDT Reads: 2,077
SYS-CON Events announced today that BMC Software has been named "Siver Sponsor" of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2015 at the Javits Center in New York, New York. BMC is a global leader in innovative software solutions that help businesses transform into digital enterprises for the ultimate competitive advantage. BMC Digital Enterprise Management is a set of innovative IT solutions designed to make digital business fast, seamless, and optimized from mainframe to mo...
May. 30, 2016 09:15 AM EDT Reads: 2,401
SYS-CON Events announced today that MobiDev will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business managers to a full-scale mobile software company with over 200 develope...
May. 30, 2016 09:15 AM EDT Reads: 2,861
As cloud and storage projections continue to rise, the number of organizations moving to the cloud is escalating and it is clear cloud storage is here to stay. However, is it secure? Data is the lifeblood for government entities, countries, cloud service providers and enterprises alike and losing or exposing that data can have disastrous results. There are new concepts for data storage on the horizon that will deliver secure solutions for storing and moving sensitive data around the world. ...
May. 30, 2016 09:00 AM EDT Reads: 1,461
SoftLayer operates a global cloud infrastructure platform built for Internet scale. With a global footprint of data centers and network points of presence, SoftLayer provides infrastructure as a service to leading-edge customers ranging from Web startups to global enterprises. SoftLayer's modular architecture, full-featured API, and sophisticated automation provide unparalleled performance and control. Its flexible unified platform seamlessly spans physical and virtual devices linked via a world...
May. 30, 2016 08:00 AM EDT Reads: 2,411
Companies can harness IoT and predictive analytics to sustain business continuity; predict and manage site performance during emergencies; minimize expensive reactive maintenance; and forecast equipment and maintenance budgets and expenditures. Providing cost-effective, uninterrupted service is challenging, particularly for organizations with geographically dispersed operations.
May. 30, 2016 07:00 AM EDT Reads: 2,299
The IoTs will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, will demonstrate how to move beyond today's coding paradigm and share the must-have mindsets for removing complexity from the development proc...
May. 30, 2016 06:00 AM EDT Reads: 2,021
SYS-CON Events announced today TechTarget has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY, and the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. TechTarget is the Web’s leading destination for serious technology buyers researching and making enterprise technology decisions. Its extensive global networ...
May. 30, 2016 05:30 AM EDT Reads: 3,320
SYS-CON Events announced today that Commvault, a global leader in enterprise data protection and information management, has been named “Bronze Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY, and the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Commvault is a leading provider of data protection and information management...
May. 30, 2016 04:45 AM EDT Reads: 3,353
The essence of data analysis involves setting up data pipelines that consist of several operations that are chained together – starting from data collection, data quality checks, data integration, data analysis and data visualization (including the setting up of interaction paths in that visualization). In our opinion, the challenges stem from the technology diversity at each stage of the data pipeline as well as the lack of process around the analysis.
May. 30, 2016 03:15 AM EDT Reads: 1,554
Designing IoT applications is complex, but deploying them in a scalable fashion is even more complex. A scalable, API first IaaS cloud is a good start, but in order to understand the various components specific to deploying IoT applications, one needs to understand the architecture of these applications and figure out how to scale these components independently. In his session at @ThingsExpo, Nara Rajagopalan is CEO of Accelerite, will discuss the fundamental architecture of IoT applications, ...
May. 30, 2016 03:00 AM EDT Reads: 1,409
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, wh...
May. 30, 2016 03:00 AM EDT Reads: 2,102
SYS-CON Events announced today that Tintri Inc., a leading producer of VM-aware storage (VAS) for virtualization and cloud environments, will exhibit at the 18th International CloudExpo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, New York, and the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
May. 30, 2016 02:45 AM EDT Reads: 2,557