11. amps-sqlite3¶
For more information on working with the AMPS statistics database, see the chapter on the AMPS Statistics Database in the AMPS User Guide.
The AMPS distribution includes a convenience script, amps-sqlite3
,
for easily running queries against a statistics database. This script
requires a Python 2.6, 2.7, or 3.X interpreter that includes the sqlite3
module. Most Linux distributions meet this requirement in the default
installation.
Options and Parameters¶
The script takes two parameters, as shown below:
Parameter | Description |
---|---|
database
|
The sqlite3 database file to query. |
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
script 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
wrapper also provides a set of convenience
functions that can be included in the query. These functions are
evaluated before the query is presented to the sqlite3 database engine.
Convenience Functions¶
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. |
Usage¶
To use the amps-sqlite3
script, 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:
$ amps-sqlite3 stats.db "select iso8601(timestamp),system_percent from hcpus order by timestamp"