Skip to content

Instantly share code, notes, and snippets.

@lanceon
Created August 24, 2013 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanceon/6328572 to your computer and use it in GitHub Desktop.
Save lanceon/6328572 to your computer and use it in GitHub Desktop.
Lift runtime stats snippet
/*
* Copyright 2007-2013 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb.example.snippet
import _root_.net.liftweb._
import http._
import util._
import Helpers._
import _root_.java.text.NumberFormat
import _root_.scala.xml.Text
object RuntimeStats extends DispatchSnippet {
@volatile
var totalMem = Runtime.getRuntime.totalMemory
@volatile
var freeMem = Runtime.getRuntime.freeMemory
@volatile
var sessions = 1
@volatile
var lastUpdate = now
val startedAt = now
private def nf(in: Long): String = NumberFormat.getInstance.format(in)
def dispatch = {
case "total_mem" => i => Text(nf(totalMem))
case "free_mem" => i => Text(nf(freeMem))
case "sessions" => i => Text(sessions.toString)
case "updated_at" => i => Text(lastUpdate.toString)
case "started_at" => i => Text(startedAt.toString)
}
}
<div>
Lift version <span data-lift="version_info.lift"></span> built on <br data-lift="version_info.date">.
<br>
Stats:
Total Memory: <span data-lift="runtime_stats.total_mem"></span>
Free Memory: <span data-lift="runtime_stats.free_mem"></span>
Open Sessions: <span data-lift="runtime_stats.sessions"></span>
<br>
Updated At: <span data-lift="runtime_stats.updated_at"></span>
Started At: <span data-lift="runtime_stats.started_at"></span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment