mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
stratum: fill fds and server name/url in stratums table
meant to detect socket leaks before its too late...
This commit is contained in:
parent
a364e305f2
commit
befb105e5d
5 changed files with 22 additions and 8 deletions
|
@ -87,17 +87,17 @@ void db_register_stratum(YAAMP_DB *db)
|
|||
int t = time(NULL);
|
||||
if(!db) return;
|
||||
|
||||
db_query(db, "INSERT INTO stratums (pid, time, started, algo, port) VALUES (%d, %d, %d, '%s', %d) "
|
||||
" ON DUPLICATE KEY UPDATE time=%d, algo='%s', port=%d",
|
||||
pid, t, t, g_stratum_algo, g_tcp_port,
|
||||
t, g_stratum_algo, g_tcp_port
|
||||
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', url='%s', port=%d",
|
||||
pid, t, t, g_stratum_algo, g_tcp_server, g_tcp_port,
|
||||
t, g_stratum_algo, g_tcp_server, g_tcp_port
|
||||
);
|
||||
}
|
||||
|
||||
void db_update_algos(YAAMP_DB *db)
|
||||
{
|
||||
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(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);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -188,8 +188,6 @@ YAAMP_ALGO *stratum_find_algo(const char *name)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <mysql.h>
|
||||
#include <errmsg.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
|
|
@ -674,6 +674,18 @@ long long current_timestamp_dms() // allow 0.1 ms time
|
|||
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)
|
||||
{
|
||||
for(int i = 0; s[i]; i++)
|
||||
|
|
|
@ -102,6 +102,8 @@ uint64_t get_hash_difficulty(unsigned char *input);
|
|||
long long current_timestamp();
|
||||
long long current_timestamp_dms();
|
||||
|
||||
int opened_files();
|
||||
|
||||
void string_lower(char *s);
|
||||
void string_upper(char *s);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue