|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.
WebRTC has had a real tough three or four years, and so have those working with it. Only a few short years ago, the development world were excited about WebRTC and proclaiming how awesome it was. You might have played with the technology a couple of years ago, only to find the extra infrastructure requirements were painful to implement and poorly documented. This probably left a bitter taste in your mouth, especially when things went wrong.
Sep. 1, 2015 03:00 AM EDT Reads: 460
Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome,” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.
Aug. 31, 2015 09:00 PM EDT Reads: 371
The Internet of Things is in the early stages of mainstream deployment but it promises to unlock value and rapidly transform how organizations manage, operationalize, and monetize their assets. IoT is a complex structure of hardware, sensors, applications, analytics and devices that need to be able to communicate geographically and across all functions. Once the data is collected from numerous endpoints, the challenge then becomes converting it into actionable insight.
Aug. 31, 2015 07:00 PM EDT
Consumer IoT applications provide data about the user that just doesn’t exist in traditional PC or mobile web applications. This rich data, or “context,” enables the highly personalized consumer experiences that characterize many consumer IoT apps. This same data is also providing brands with unprecedented insight into how their connected products are being used, while, at the same time, powering highly targeted engagement and marketing opportunities. In his session at @ThingsExpo, Nathan Treloar, President and COO of Bebaio, will explore examples of brands transforming their businesses by t...
Aug. 31, 2015 06:00 PM EDT Reads: 246
With the Apple Watch making its way onto wrists all over the world, it’s only a matter of time before it becomes a staple in the workplace. In fact, Forrester reported that 68 percent of technology and business decision-makers characterize wearables as a top priority for 2015. Recognizing their business value early on, FinancialForce.com was the first to bring ERP to wearables, helping streamline communication across front and back office functions. In his session at @ThingsExpo, Kevin Roberts, GM of Platform at FinancialForce.com, will discuss the value of business applications on wearable ...
Aug. 31, 2015 03:15 PM EDT
While many app developers are comfortable building apps for the smartphone, there is a whole new world out there. In his session at @ThingsExpo, Narayan Sainaney, Co-founder and CTO of Mojio, will discuss how the business case for connected car apps is growing and, with open platform companies having already done the heavy lifting, there really is no barrier to entry.
Aug. 31, 2015 02:30 PM EDT Reads: 144
With the proliferation of connected devices underpinning new Internet of Things systems, Brandon Schulz, Director of Luxoft IoT – Retail, will be looking at the transformation of the retail customer experience in brick and mortar stores in his session at @ThingsExpo. Questions he will address include: Will beacons drop to the wayside like QR codes, or be a proximity-based profit driver? How will the customer experience change in stores of all types when everything can be instrumented and analyzed? As an area of investment, how might a retail company move towards an innovation methodolo...
Aug. 31, 2015 02:30 PM EDT Reads: 462
The Internet of Things (IoT) is about the digitization of physical assets including sensors, devices, machines, gateways, and the network. It creates possibilities for significant value creation and new revenue generating business models via data democratization and ubiquitous analytics across IoT networks. The explosion of data in all forms in IoT requires a more robust and broader lens in order to enable smarter timely actions and better outcomes. Business operations become the key driver of IoT applications and projects. Business operations, IT, and data scientists need advanced analytics t...
Aug. 31, 2015 02:30 PM EDT Reads: 422
Contrary to mainstream media attention, the multiple possibilities of how consumer IoT will transform our everyday lives aren’t the only angle of this headline-gaining trend. There’s a huge opportunity for “industrial IoT” and “Smart Cities” to impact the world in the same capacity – especially during critical situations. For example, a community water dam that needs to release water can leverage embedded critical communications logic to alert the appropriate individuals, on the right device, as soon as they are needed to take action.
Aug. 31, 2015 12:00 PM EDT
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
Aug. 31, 2015 11:30 AM EDT Reads: 897
SYS-CON Events announced today that Micron Technology, Inc., a global leader in advanced semiconductor systems, will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Micron’s broad portfolio of high-performance memory technologies – including DRAM, NAND and NOR Flash – is the basis for solid state drives, modules, multichip packages and other system solutions. Backed by more than 35 years of technology leadership, Micron's memory solutions enable the world's most innovative computing, consumer,...
Aug. 31, 2015 11:15 AM EDT Reads: 234
As more intelligent IoT applications shift into gear, they’re merging into the ever-increasing traffic flow of the Internet. It won’t be long before we experience bottlenecks, as IoT traffic peaks during rush hours. Organizations that are unprepared will find themselves by the side of the road unable to cross back into the fast lane. As billions of new devices begin to communicate and exchange data – will your infrastructure be scalable enough to handle this new interconnected world?
Aug. 31, 2015 11:00 AM EDT Reads: 164
Through WebRTC, audio and video communications are being embedded more easily than ever into applications, helping carriers, enterprises and independent software vendors deliver greater functionality to their end users. With today’s business world increasingly focused on outcomes, users’ growing calls for ease of use, and businesses craving smarter, tighter integration, what’s the next step in delivering a richer, more immersive experience? That richer, more fully integrated experience comes about through a Communications Platform as a Service which allows for messaging, screen sharing, video...
Aug. 31, 2015 10:30 AM EDT Reads: 662
SYS-CON Events announced today that Pythian, a global IT services company specializing in helping companies leverage disruptive technologies to optimize revenue-generating systems, has been named “Bronze Sponsor” of SYS-CON's 17th Cloud Expo, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Founded in 1997, Pythian is a global IT services company that helps companies compete by adopting disruptive technologies such as cloud, Big Data, advanced analytics, and DevOps to advance innovation and increase agility. Specializing in designing, imple...
Aug. 31, 2015 10:15 AM EDT Reads: 309
In his session at @ThingsExpo, Lee Williams, a producer of the first smartphones and tablets, will talk about how he is now applying his experience in mobile technology to the design and development of the next generation of Environmental and Sustainability Services at ETwater. He will explain how M2M controllers work through wirelessly connected remote controls; and specifically delve into a retrofit option that reverse-engineers control codes of existing conventional controller systems so they don't have to be replaced and are instantly converted to become smart, connected devices.
Aug. 31, 2015 09:30 AM EDT Reads: 127
SYS-CON Events announced today that IceWarp will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. IceWarp, the leader of cloud and on-premise messaging, delivers secured email, chat, documents, conferencing and collaboration to today's mobile workforce, all in one unified interface
Aug. 31, 2015 04:00 AM EDT Reads: 429
As more and more data is generated from a variety of connected devices, the need to get insights from this data and predict future behavior and trends is increasingly essential for businesses. Real-time stream processing is needed in a variety of different industries such as Manufacturing, Oil and Gas, Automobile, Finance, Online Retail, Smart Grids, and Healthcare. Azure Stream Analytics is a fully managed distributed stream computation service that provides low latency, scalable processing of streaming data in the cloud with an enterprise grade SLA. It features built-in integration with Azur...
Aug. 28, 2015 07:45 PM EDT Reads: 222
Akana has announced the availability of the new Akana Healthcare Solution. The API-driven solution helps healthcare organizations accelerate their transition to being secure, digitally interoperable businesses. It leverages the Health Level Seven International Fast Healthcare Interoperability Resources (HL7 FHIR) standard to enable broader business use of medical data. Akana developed the Healthcare Solution in response to healthcare businesses that want to increase electronic, multi-device access to health records while reducing operating costs and complying with government regulations.
Aug. 26, 2015 07:00 AM EDT Reads: 196
For IoT to grow as quickly as analyst firms’ project, a lot is going to fall on developers to quickly bring applications to market. But the lack of a standard development platform threatens to slow growth and make application development more time consuming and costly, much like we’ve seen in the mobile space. In his session at @ThingsExpo, Mike Weiner, Product Manager of the Omega DevCloud with KORE Telematics Inc., discussed the evolving requirements for developers as IoT matures and conducted a live demonstration of how quickly application development can happen when the need to comply wit...
Aug. 2, 2015 11:15 AM EDT Reads: 560
The Internet of Everything (IoE) brings together people, process, data and things to make networked connections more relevant and valuable than ever before – transforming information into knowledge and knowledge into wisdom. IoE creates new capabilities, richer experiences, and unprecedented opportunities to improve business and government operations, decision making and mission support capabilities.
Aug. 1, 2015 10:00 AM EDT Reads: 489