AMPS Statistics
AMPS provides the ability to record the statistics gathered from the AMPS instance and the host machine.
The AMPS statistics database is stored in sqlite3 format and can be used with any of the standard sqlite3 tools. This section assumes that you are using the standard sqlite3
package installed on your local computer. While you may be able to run the SQL examples in this guide using other packages, this guide will assume that all SQL commands will be executed with sqlite3
.
Notice that the statistics subsystem is independent of the other subsystems in AMPS, and is the only part of AMPS that uses the sqlite3 format. You cannot use sqlite3 tools with SOW files, journal files or .ack files: these files use formats specifically designed for high performance messaging.
Working with the AMPS statistics database is described in more detail in the following sections.
Configuring AMPS to Persist Statistics
By default, AMPS maintains statistics in memory. To configure AMPS to record the statistics to a file, the following configuration options are available in the AMPS configuration file to update the location and frequency of the statistics database file.
In the example above, the AMPS administration interface is set to collect statistics every 5 seconds as indicated by the <Interval>
tag. The AMPS administration interface is additionally configured to save the statistics in the stats.db
file, which will be created in the directory where AMPS was started.
AMPS does not require that statistics are persisted. Persisting statistics enables information about instance performance, capacity, usage, and so on to be analyzed offline (rather than by using RESTful operations against a running instance). This also enables statistical information about the instance to be persisted when AMPS restarts.
Introduction to SQLite3
This section is a quick reference to sqlite3. It is intended to help in getting started with examining the statistics provided by AMPS. While this guide will be sufficient to execute the examples listed, a more comprehensive guide of the sqlite3 command line tool is available at http://www.sqlite.org/sqlite.html.
Starting SQLite3
To start sqlite3 with the stats.db file simply type:
This will create a command prompt that looks like the following:
To exit the sqlite3 prompt at any time, use the Ctrl+d sequence.
Simple SQLite3 Commands
Tables
To get a listing of all available tables in the sqlite database type the .table
command.
Schema
To view the schema for any table, type the .schema <table name>
command where <table name>
is the name of the table to inspect.
Statistics Table Design
This section describes the philosophy of how the AMPS tables are designed within the statistics database. This chapter also includes some examples of some useful queries which can give an administrator more information than just the raw data would normally give them. Such information can be a powerful tool in diagnosing perceived problems in AMPS.
Table Naming Scheme
Tables in the database use the following naming scheme:
Example Queries
To view which clients have fallen behind at one time, run:
To view clients that are behind in the latest sample:
Using the amps-sqlite3 Utility
The AMPS distribution includes a convenience utility, amps-sqlite3
, for easily running queries against a statistics database.
The utility takes two parameters, as shown below:
Parameter
Description
The sqlite3 database file to query.
The query to run. Notice that the query must be enclosed in quotes, since this is a command-line program run by the Linux shell.
The amps-sqlite3
utility joins the STATIC
and DYNAMIC
tables together, making a single table that is easier to query on. For example, the script joins the ICLIENTS_DYNAMIC
and ICLIENTS_STATIC
tables together into a single ICLIENTS
table.
The amps-sqlite3
utility also provides a set of convenience functions that can be included in the query.
Option
Description
ISO8601(timestamp)
Convert timestamp
to an ISO8601 format string.
ISO8601_local(timestamp)
Convert timestamp
to an ISO8601 format string in the local timezone.
timestamp(string)
Convert the provided ISO8601 format string
to a timestamp.
To use amps-sqlite3
, simply provide the file name of the database to query and the query to run. For example, the following query returns the set of samples AMPS has recorded for the system_percent
consumed on each CPU while the instance has been running:
SQLite Tips and Troubleshooting
This section includes information on SQLite tasks that may not be immediately obvious and troubleshooting information on SQLite.
Converting AMPS Statistics Time to an ISO8601 Datetime
This Python function shows how to convert an AMPS timestamp to an ISO8601 datetime. You can use the equivalent in your language of choice to convert between the timestamps recorded in the statistics database and ISO8601 timestamps.
Shrinking an AMPS Statistics Database
If the retention policy for an AMPS statistics database has changed such that there is unused space in the file at the maximum retention size, it may be helpful to shrink the size of the statistics database.
Running this procedure will only reduce the size of the database if the database has been truncated.
To do this:
Take the AMPS instance offline.
(Optional, but recommended) Make a backup copy of the AMPS statistics database on another device.
Run the sqlite
VACUUM
command to shrink the database:This operation may require free disk space equal to the current size of the statistics database. If the operation fails, the vacuum rolls back without changing the database.
A database should not be vacuumed while AMPS is running.
Troubleshooting "Database Disk Image is Malformed"
To repair this error, you need to extract the data from the SQLite datastore and create a new datastore. To do this:
Open the sqlite datastore. For example, if the database store is named
stats.db
, the command would be:
Dump the data into a SQL script.
This creates a series of SQL commands that recreate the data in the database.
Make sure that the script commits updates (depending on the version of sqlite3 and the state of the database, the script may roll back the updates rather than committing them without this step).
Now create a new database file using the SQL commands.
Finally, adjust the configuration of the Admin server to use the new database (in this example, good.db
) or copy the new database over the old database.
Last updated