stratum: fill fds and server name/url in stratums table

meant to detect socket leaks before its too late...
This commit is contained in:
Tanguy Pruvot 2018-03-01 23:28:06 +01:00
parent a364e305f2
commit befb105e5d
5 changed files with 22 additions and 8 deletions

View file

@ -87,17 +87,17 @@ void db_register_stratum(YAAMP_DB *db)
int t = time(NULL); int t = time(NULL);
if(!db) return; if(!db) return;
db_query(db, "INSERT INTO stratums (pid, time, started, algo, port) VALUES (%d, %d, %d, '%s', %d) " db_query(db, "INSERT INTO stratums (pid, time, started, algo, url, port) VALUES (%d,%d,%d,'%s','%s',%d) "
" ON DUPLICATE KEY UPDATE time=%d, algo='%s', port=%d", " ON DUPLICATE KEY UPDATE time=%d, algo='%s', url='%s', port=%d",
pid, t, t, g_stratum_algo, g_tcp_port, pid, t, t, g_stratum_algo, g_tcp_server, g_tcp_port,
t, g_stratum_algo, g_tcp_port t, g_stratum_algo, g_tcp_server, g_tcp_port
); );
} }
void db_update_algos(YAAMP_DB *db) void db_update_algos(YAAMP_DB *db)
{ {
int pid = getpid(); int pid = getpid();
//int fds = 0; // todo, sample: ls -l /proc/$PID/fd | grep socket | grep -c . int fds = opened_files();
if(!db) return; if(!db) return;
if(g_current_algo->overflow) if(g_current_algo->overflow)
@ -117,7 +117,8 @@ void db_update_algos(YAAMP_DB *db)
} }
} }
db_query(db, "UPDATE stratums SET workers=%d, symbol=%s WHERE pid=%d", g_list_client.count, symbol, pid); db_query(db, "UPDATE stratums SET workers=%d, fds=%d, symbol=%s WHERE pid=%d",
g_list_client.count, fds, symbol, pid);
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -188,8 +188,6 @@ YAAMP_ALGO *stratum_find_algo(const char *name)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
#include <dirent.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if(argc < 2) if(argc < 2)

View file

@ -19,6 +19,7 @@
#include <mysql.h> #include <mysql.h>
#include <errmsg.h> #include <errmsg.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <dirent.h>
#include <iostream> #include <iostream>
#include <vector> #include <vector>

View file

@ -674,6 +674,18 @@ long long current_timestamp_dms() // allow 0.1 ms time
return dms; return dms;
} }
int opened_files()
{
int fds = 0;
DIR *d = opendir("/proc/self/fd");
if (d) {
struct dirent *ent;
while (readdir(d)) fds++;
closedir(d);
}
return fds;
}
void string_lower(char *s) void string_lower(char *s)
{ {
for(int i = 0; s[i]; i++) for(int i = 0; s[i]; i++)

View file

@ -102,6 +102,8 @@ uint64_t get_hash_difficulty(unsigned char *input);
long long current_timestamp(); long long current_timestamp();
long long current_timestamp_dms(); long long current_timestamp_dms();
int opened_files();
void string_lower(char *s); void string_lower(char *s);
void string_upper(char *s); void string_upper(char *s);