vnstat  2.9
About: vnStat is a console-based network traffic monitor (using the /proc filesystem).
  Fossies Dox: vnstat-2.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dbsql.h
Go to the documentation of this file.
1#ifndef DBSQL_H
2#define DBSQL_H
3
4#include <sqlite3.h>
5#include "iflist.h"
6
7typedef struct dbdatalist {
8 time_t timestamp;
9 int64_t rowid;
10 uint64_t rx, tx;
13
14typedef struct dbdatalistinfo {
15 uint32_t count;
17 uint64_t minrx, mintx;
18 uint64_t maxrx, maxtx;
19 uint64_t min, max;
20 uint64_t sumrx, sumtx;
22
23typedef struct interfaceinfo {
24 char name[32], alias[32];
25 int active;
28 uint64_t rxtotal, txtotal;
30
31int db_open_ro(void);
32int db_open_rw(const int createifnotfound);
33int db_open(const int createifnotfound, const int readonly);
34int db_validate(const int readonly);
35int db_setpragmas(void);
36int db_close(void);
37int db_exec(const char *sql);
38int db_create(void);
39int db_addinterface(const char *iface);
40int db_removeinterface(const char *iface);
41int db_renameinterface(const char *iface, const char *newifname);
42uint64_t db_getinterfacecount(void);
43uint64_t db_getinterfacecountbyname(const char *iface);
44sqlite3_int64 db_getinterfaceid(const char *iface, const int createifnotfound);
45char *db_getinterfaceidin(const char *iface);
46int db_setinterfacebyalias(char *iface, const char *alias, const int matchmethod);
47int db_setactive(const char *iface, const int active);
48int db_setupdated(const char *iface, const time_t timestamp);
49int db_setcounters(const char *iface, const uint64_t rxcounter, const uint64_t txcounter);
50int db_getcounters(const char *iface, uint64_t *rxcounter, uint64_t *txcounter);
51int db_getinterfaceinfo(const char *iface, interfaceinfo *info);
52int db_setalias(const char *iface, const char *alias);
53int db_setinfo(const char *name, const char *value, const int createifnotfound);
54char *db_getinfo(const char *name);
55int db_getiflist(iflist **ifl);
56int db_getiflist_sorted(iflist **ifl, const int orderbytraffic);
57char *db_get_date_generator(const int range, const short direct, const char *nowdate);
58int db_addtraffic(const char *iface, const uint64_t rx, const uint64_t tx);
59int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp);
60int db_setcreation(const char *iface, const time_t timestamp);
61int db_settotal(const char *iface, const uint64_t rx, const uint64_t tx);
62int db_insertdata(const char *table, const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp);
63int db_removeoldentries(void);
65int db_vacuum(void);
66int db_begintransaction(void);
67int db_committransaction(void);
69int db_iserrcodefatal(int errcode);
70int db_isdiskfull(int errcode);
71#if HAVE_DECL_SQLITE_CHECKPOINT_RESTART
72void db_walcheckpoint(void);
73#endif
74
75int db_getdata(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit);
76int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit, const char *databegin, const char *dataend);
77void updatelistinfo(dbdatalistinfo *listinfo, const uint64_t rx, const uint64_t tx, const time_t timestamp);
78int dbdatalistadd(dbdatalist **dbdata, const uint64_t rx, const uint64_t tx, const time_t timestamp, const int64_t rowid);
79void dbdatalistfree(dbdatalist **dbdata);
80
81unsigned int getqueryinterfacecount(const char *input);
82char *getifaceinquery(const char *input);
83
84/* global db */
85extern sqlite3 *db;
86extern int db_errcode;
87extern int db_intransaction;
88
89#endif
int db_close(void)
Definition: dbsql.c:248
int db_getcounters(const char *iface, uint64_t *rxcounter, uint64_t *txcounter)
Definition: dbsql.c:616
int db_open_ro(void)
Definition: dbsql.c:11
int db_removeoldentries_top(void)
Definition: dbsql.c:1048
int db_getiflist(iflist **ifl)
Definition: dbsql.c:766
int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp)
Definition: dbsql.c:848
int db_setcreation(const char *iface, const time_t timestamp)
Definition: dbsql.c:909
char * db_get_date_generator(const int range, const short direct, const char *nowdate)
Definition: dbsql.c:807
unsigned int getqueryinterfacecount(const char *input)
Definition: dbsql.c:1404
int db_open_rw(const int createifnotfound)
Definition: dbsql.c:16
sqlite3_int64 db_getinterfaceid(const char *iface, const int createifnotfound)
Definition: dbsql.c:466
int db_removeinterface(const char *iface)
Definition: dbsql.c:382
int db_validate(const int readonly)
Definition: dbsql.c:131
int db_renameinterface(const char *iface, const char *newifname)
Definition: dbsql.c:396
int dbdatalistadd(dbdatalist **dbdata, const uint64_t rx, const uint64_t tx, const time_t timestamp, const int64_t rowid)
Definition: dbsql.c:1373
struct dbdatalist dbdatalist
char * db_getinterfaceidin(const char *iface)
Definition: dbsql.c:496
int db_errcode
Definition: dbsql.c:8
int db_settotal(const char *iface, const uint64_t rx, const uint64_t tx)
Definition: dbsql.c:923
int db_setalias(const char *iface, const char *alias)
Definition: dbsql.c:708
int db_exec(const char *sql)
Definition: dbsql.c:270
int db_insertdata(const char *table, const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp)
Definition: dbsql.c:938
int db_addinterface(const char *iface)
Definition: dbsql.c:370
uint64_t db_getinterfacecount(void)
Definition: dbsql.c:414
struct interfaceinfo interfaceinfo
int db_setactive(const char *iface, const int active)
Definition: dbsql.c:574
uint64_t db_getinterfacecountbyname(const char *iface)
Definition: dbsql.c:419
char * db_getinfo(const char *name)
Definition: dbsql.c:739
int db_create(void)
Definition: dbsql.c:303
int db_removeoldentries(void)
Definition: dbsql.c:973
int db_isdiskfull(int errcode)
Definition: dbsql.c:1182
int db_begintransaction(void)
Definition: dbsql.c:1105
int db_setcounters(const char *iface, const uint64_t rxcounter, const uint64_t txcounter)
Definition: dbsql.c:602
int db_setpragmas(void)
Definition: dbsql.c:171
int db_iserrcodefatal(int errcode)
Definition: dbsql.c:1168
int db_getiflist_sorted(iflist **ifl, const int orderbytraffic)
Definition: dbsql.c:771
int db_setupdated(const char *iface, const time_t timestamp)
Definition: dbsql.c:588
int db_vacuum(void)
Definition: dbsql.c:1097
struct dbdatalistinfo dbdatalistinfo
int db_setinfo(const char *name, const char *value, const int createifnotfound)
Definition: dbsql.c:722
int db_rollbacktransaction(void)
Definition: dbsql.c:1148
int db_setinterfacebyalias(char *iface, const char *alias, const int matchmethod)
Definition: dbsql.c:527
int db_addtraffic(const char *iface, const uint64_t rx, const uint64_t tx)
Definition: dbsql.c:843
int db_getdata(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit)
Definition: dbsql.c:1212
char * getifaceinquery(const char *input)
Definition: dbsql.c:1425
void updatelistinfo(dbdatalistinfo *listinfo, const uint64_t rx, const uint64_t tx, const time_t timestamp)
Definition: dbsql.c:1329
sqlite3 * db
Definition: dbsql.c:7
int db_intransaction
Definition: dbsql.c:9
int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit, const char *databegin, const char *dataend)
Definition: dbsql.c:1217
int db_open(const int createifnotfound, const int readonly)
Definition: dbsql.c:21
void dbdatalistfree(dbdatalist **dbdata)
Definition: dbsql.c:1393
int db_getinterfaceinfo(const char *iface, interfaceinfo *info)
Definition: dbsql.c:651
int db_committransaction(void)
Definition: dbsql.c:1124
time_t timestamp
Definition: dbsql.h:8
struct dbdatalist * next
Definition: dbsql.h:11
int64_t rowid
Definition: dbsql.h:9
uint64_t rx
Definition: dbsql.h:10
uint64_t tx
Definition: dbsql.h:10
time_t mintime
Definition: dbsql.h:16
time_t maxtime
Definition: dbsql.h:16
uint64_t mintx
Definition: dbsql.h:17
uint64_t min
Definition: dbsql.h:19
uint64_t maxrx
Definition: dbsql.h:18
uint64_t minrx
Definition: dbsql.h:17
uint64_t sumrx
Definition: dbsql.h:20
uint64_t sumtx
Definition: dbsql.h:20
uint32_t count
Definition: dbsql.h:15
uint64_t max
Definition: dbsql.h:19
uint64_t maxtx
Definition: dbsql.h:18
Definition: iflist.h:4
int active
Definition: dbsql.h:25
char alias[32]
Definition: dbsql.h:24
uint64_t rxcounter
Definition: dbsql.h:27
time_t created
Definition: dbsql.h:26
time_t updated
Definition: dbsql.h:26
uint64_t txtotal
Definition: dbsql.h:28
char name[32]
Definition: dbsql.h:24
uint64_t rxtotal
Definition: dbsql.h:28
uint64_t txcounter
Definition: dbsql.h:27