Saturday, February 16, 2013

editing graphite.db

I'm not all that experienced with Django, or sqlite. But, today I figured out how to delete graph views from the graphite.db to get rid of graphs that cant be deleted through the UI. At first I tried using 'django-admin.py', but the 'manage.py' wrapper was easier to use because I didn't need to create env vars.

#location of manage.py and settings.py
cd /opt/graphite/webapp/graphite
root@monitor1.sv3:/opt/graphite/webapp/graphite$ python manage.py dbshell
SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>.help

#outputs help here

Most of the time I have trouble deleting graphs from "My Graphs" or "User Graphs", below is an example of an entry where I made a spelling error as well as a poor choice for naming (I used periods instead of underscore, ..oops.).
To do that:

sqlite> select * from account_mygraph;
2|2|Most Deviant Web Servers with respecet to somepoorlynamed.file.php|http://10.80.1.5:8080/render/?width=1564&height=299&_salt=1360994411.086&target=mostDeviant(2%2C%20prod.web*.apache.properlynamed_file_php)&title=Most%20Deviant%20Web%20Servers%20with%20respect%20to%poorlynamed.file.php

Check the schema to get the column name

sqlite> .schema account_mygraph
CREATE TABLE "account_mygraph" (
    "id" integer NOT NULL PRIMARY KEY,
    "profile_id" integer NOT NULL REFERENCES "account_profile" ("id"),
    "name" varchar(64) NOT NULL,
    "url" text NOT NULL
);

#Delete record
sqlite> delete from account_mygraph where id = 2

Done.
Check the UI

This site was helpful: http://www.sqlite.org/sqlite.html

No comments: