16 #ifndef windows_platform
17 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
28 #include <boost/system/error_code.hpp>
29 #include <boost/asio.hpp>
30 #include <boost/algorithm/string.hpp>
41 const char *delim1 =
"#";
42 const char *delim2 =
",";
43 int rc1 = 0, rc2 = 0, rc3 = 0, rc4 = 0;
49 time_t tps = time(
NULL );
50 struct tm *now = localtime( &tps );
59 std::vector<std::string> output_tokens;
60 boost::algorithm::split( output_tokens,
output, boost::is_any_of( delim1 ) );
61 output_tokens.erase( output_tokens.begin() );
62 if ( output_tokens.size() != 9 ) {
63 rodsLog(
LOG_ERROR,
"rodsMonPerfLog: output_tokens is of incorrect size: size [%ju], output [%s]", ( uintmax_t )output_tokens.size(),
output );
66 std::vector<std::string> resc_tokens;
67 boost::algorithm::split( resc_tokens, resc, boost::is_any_of( delim2 ) );
68 std::vector<std::string> disk_tokens;
69 boost::algorithm::split( disk_tokens, output_tokens[4], boost::is_any_of( delim2 ) );
70 std::vector<std::string> value_tokens;
71 boost::algorithm::split( value_tokens, output_tokens[7], boost::is_any_of( delim2 ) );
72 if ( resc_tokens.size() != disk_tokens.size() || resc_tokens.size() != value_tokens.size() ) {
73 rodsLog(
LOG_ERROR,
"rodsMonPerfLog: resc_tokens [%ju], disk_tokens [%ju], value_tokens [%ju]. output [%s]", ( uintmax_t )resc_tokens.size(), ( uintmax_t )disk_tokens.size(), ( uintmax_t )value_tokens.size(),
output );
77 for ( std::vector<std::string>::size_type index = 0; index < resc_tokens.size(); ++index ) {
79 disk_tokens[index] =
"-1";
80 value_tokens[index] =
"-1";
82 snprintf( msg,
sizeof( msg ),
"server=%s resource=%s cpu=%s, mem=%s, swp=%s, rql=%s, dsk=%s, nin=%s, nout=%s, dskAv(MB)=%s\n",
83 serverName, resc_tokens[index].c_str(), output_tokens[0].c_str(), output_tokens[1].c_str(), output_tokens[2].c_str(),
84 output_tokens[3].c_str(), disk_tokens[index].c_str(), output_tokens[5].c_str(), output_tokens[6].c_str(), value_tokens[index].c_str() );
85 snprintf( suffix,
sizeof( suffix ),
"%d.%d.%d", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday );
88 const time_t timestamp = time( &tps );
91 generalRowInsertInp.
tableName =
"serverload";
92 generalRowInsertInp.
arg1 = serverName;
93 generalRowInsertInp.
arg2 = resc_tokens[index].c_str();
94 generalRowInsertInp.
arg3 = output_tokens[0].c_str();
95 generalRowInsertInp.
arg4 = output_tokens[1].c_str();
96 generalRowInsertInp.
arg5 = output_tokens[2].c_str();
97 generalRowInsertInp.
arg6 = output_tokens[3].c_str();
98 generalRowInsertInp.
arg7 = disk_tokens[index].c_str();
99 generalRowInsertInp.
arg8 = output_tokens[5].c_str();
100 generalRowInsertInp.
arg9 = output_tokens[6].c_str();
102 generalAdminInp1.
arg0 =
"modify";
103 generalAdminInp1.
arg1 =
"resource";
104 generalAdminInp1.
arg2 = resc_tokens[index].c_str();
105 generalAdminInp1.
arg3 =
"freespace";
106 generalAdminInp1.
arg4 = value_tokens[index].c_str();
107 generalAdminInp2.
arg0 =
"modify";
108 generalAdminInp2.
arg1 =
"resource";
109 generalAdminInp2.
arg2 = resc_tokens[index].c_str();
110 generalAdminInp2.
arg3 =
"status";
111 generalAdminInp2.
arg4 = monStatus;
112 memset( &genQueryInp, 0,
sizeof( genQueryInp ) );
114 snprintf( condstr,
MAX_NAME_LEN,
"= '%s'", resc_tokens[index].c_str() );
117 #ifndef windows_platform
121 FILE *foutput = fopen( fname,
"a" );
122 if ( foutput !=
NULL ) {
123 fprintf( foutput,
"time=%ji %s", ( intmax_t )timestamp, msg );
132 if ( strcmp( result,
"\0" ) == 0 || ( strncmp( result,
"auto-", 5 ) == 0 && strcmp( result, monStatus ) != 0 ) ) {
137 rodsLog(
LOG_ERROR,
"msiServerMonPerf: unable to retrieve the status metadata for the resource %s", resc_tokens[index].c_str() );
139 #ifndef windows_platform
142 if ( foutput !=
NULL ) {
144 fprintf( foutput,
"time=%ji : unable to insert the entries for server %s into the iCAT\n",
145 ( intmax_t )timestamp, serverName );
150 rodsLog(
LOG_ERROR,
"msiServerMonPerf: unable to register the free space metadata for the resource %s", resc_tokens[index].c_str() );
153 rodsLog(
LOG_ERROR,
"msiServerMonPerf: unable to register the status metadata for the resource %s", resc_tokens[index].c_str() );
193 if ( genQueryOut->
rowCnt > 0 ) {
195 for ( i = 0; i < genQueryOut->
attriCnt; i++ ) {
196 for ( j = 0; j < genQueryOut->
rowCnt; j++ ) {
202 if ( nservers >= 0 ) {
203 for ( k = 0; k < nservers; k++ ) {
204 if ( strcmp( serverList[k], tResult ) == 0 ) {
214 if ( index[j] != -1 ) {
219 if ( index[j] != -1 ) {
224 if ( index[j] != -1 ) {
229 if ( index[j] != -1 ) {
251 msParam_t msp1, msp2, msp3, msp4, msp5, msout;
256 #ifndef windows_platform
257 pthread_setcancelstate( PTHREAD_CANCEL_ENABLE,
NULL );
258 pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS,
NULL );
276 #ifndef windows_platform
277 pthread_exit( (
void * )&retval );
293 #ifndef windows_platform
294 pthread_exit( (
void * )&retval );
313 #ifndef windows_platform
314 pthread_exit( (
void * )&retval );
319 const std::string& _user_name,
320 const std::string& _host_client,
321 const std::string& _groups_name ) {
322 namespace ip = boost::asio::ip;
324 std::string cfg_file;
334 ret = cfg.
load( cfg_file );
340 std::vector< std::string > group_list;
344 boost::is_any_of(
"\t " ),
345 boost::token_compress_on );
348 for (
const auto& el : cfg.
get<
const std::vector<boost::any> >(
"access_entries") ) {
350 const auto& access_entry = boost::any_cast<const std::unordered_map<std::string, boost::any>&>(el);
351 const auto& user = boost::any_cast<const std::string&>(access_entry.at(
"user"));
352 const auto& group = boost::any_cast<const std::string&>(access_entry.at(
"group"));
353 const auto& addy = boost::any_cast<const std::string&>(access_entry.at(
"address"));
354 const auto& mask = boost::any_cast<const std::string&>(access_entry.at(
"mask"));
356 boost::system::error_code error_code;
357 ip::address_v4 address_entry(
358 ip::address_v4::from_string(
361 if ( error_code.value() ) {
366 ip::address_v4 mask_entry(
367 ip::address_v4::from_string(
370 if ( error_code.value() ) {
375 ip::address_v4 host_client(
376 ip::address_v4::from_string(
379 if ( error_code.value() ) {
384 bool user_match =
false;
385 if ( user == _user_name ||
391 bool group_match =
false;
392 if (
"all" == group ) {
398 i < group_list.size();
400 if ( group == group_list[ i ] ) {
409 if ( group_match || user_match ) {
412 if ( ( ( host_client.to_ulong() ^
413 address_entry.to_ulong() ) &
414 ~mask_entry.to_ulong() ) == 0 ) {
418 }
catch (
const boost::bad_any_cast&
e ) {
421 }
catch (
const std::out_of_range&
e ) {
471 char group[
MAX_NAME_LEN], *hostclient, *result, *username;
487 hostclient = inet_ntoa( rsComm->
remoteAddr.sin_addr );
489 memset( &genQueryInp, 0,
sizeof( genQueryInp ) );
496 for ( i = 0; i < genQueryOut->
rowCnt; i++ ) {
499 strcat( group, result );
500 strcat( group,
" " );
511 rodsLog(
LOG_NOTICE,
"Access to user %s from host %s has been refused.\n", username, hostclient );
570 const char *delim =
" \n";
572 int check, i, indx, j, looptime, maxtime, nresc, nservers, thrCount, threadsNotfinished;
573 const char *probtimeDef =
"10";
578 int addPathToArgv = 0;
587 std::stringstream valinit_stream;
590 if ( strcmp( verbosity,
"verbose" ) == 0 ) {
591 valinit_stream <<
"-v ";
595 valinit_stream <<
" -t ";
597 snprintf( probtime,
sizeof( probtime ),
"%s", (
char * ) ptime->
inOutStruct );
598 if ( atoi( probtime ) > 0 ) {
599 valinit_stream << probtime;
600 snprintf( measTime,
sizeof( measTime ),
"%s", probtime );
603 valinit_stream << probtimeDef;
604 snprintf( measTime,
sizeof( measTime ),
"%s", probtimeDef );
617 if (
line[0] !=
'#' ) {
618 std::vector<std::string> tokens;
619 boost::algorithm::split( tokens,
line, boost::is_any_of( delim ) );
620 snprintf( serverList[i],
MAX_NAME_LEN,
"%s", tokens[0].c_str() );
629 getListOfResc( rsComm, serverList, nservers, rescList, &nresc );
639 #ifndef windows_platform
640 pthread_t *threads = ( pthread_t* )malloc(
sizeof( pthread_t ) * nresc );
646 for ( i = 0; i < nresc; i++ ) {
652 for ( j = 0; j < thrCount; j++ ) {
653 if ( strcmp( thrInput[j].execAddr, rescList[i].serverName ) == 0 ) {
659 const char * path = strcmp( rescList[thrCount].rescType,
"unixfilesystem" ) == 0 ?
661 snprintf( thrInput[thrCount].cmdArgv,
sizeof( thrInput[thrCount].cmdArgv ),
662 "%s -fs %s", valinit_stream.str().c_str(), path );
667 thrInput[thrCount].
threadId = thrCount;
669 memcpy( &( thrInput[thrCount].rei ), rei,
sizeof(
ruleExecInfo_t ) );
675 if ( strcmp( rescList[i].rescType,
"unixfilesystem" ) == 0 ) {
676 rstrcat( thrInput[indx].cmdArgv,
",",
sizeof( thrInput[indx].cmdArgv ) );
677 rstrcat( thrInput[indx].cmdArgv, rescList[i].vaultPath,
sizeof( thrInput[indx].cmdArgv ) );
680 rstrcat( thrInput[indx].cmdArgv,
",none",
sizeof( thrInput[indx].cmdArgv ) );
686 for ( i = 0; i < thrCount; i++ ) {
687 #ifndef windows_platform
688 if ( pthread_create( &threads[i],
NULL, *
startMonScript, (
void * ) &thrInput[i] ) < 0 ) {
695 maxtime = atoi( measTime ) +
TIMEOUT;
700 if ( looptime >= maxtime ) {
701 for ( i = 0; i < thrCount; i++ ) {
703 #ifndef windows_platform
704 int rc = pthread_cancel( threads[i] );
709 thrInput[i].rescName,
711 &( thrInput[i].rei ) );
717 threadsNotfinished = 1;
718 for ( i = 0; i < thrCount; i++ ) {
720 threadsNotfinished = 0;
723 if ( threadsNotfinished ) {
728 #ifndef windows_platform
775 int elapseTime, defaultTimespan, rc;
776 char secAgo[
MAXLEN], *tablename, *timespan;
782 defaultTimespan = 24;
791 if ( inpParam1 ==
NULL ) {
793 "msiFlushMonStat: input Param1 is NULL" );
802 "msiFlushMonStat: Unsupported input Param1 type %s",
807 if ( inpParam2 ==
NULL ) {
809 "msiFlushMonStat: input Param2 is NULL" );
818 "msiFlushMonStat: Unsupported input Param2 type %s",
823 if ( atoi( timespan ) > 0 ) {
824 elapseTime = atoi( timespan ) * 3600;
827 elapseTime = defaultTimespan * 3600;
830 if ( strcmp( tablename,
"serverload" ) != 0 &&
831 strcmp( tablename,
"serverloaddigest" ) != 0 ) {
833 "msiFlushMonStat: table %s does not exist", tablename );
837 generalRowPurgeInp.
tableName = tablename;
838 snprintf( secAgo,
MAXLEN,
"%i", elapseTime );
909 int i, j, loadFactor, nresc, rc,
status, totalWeight, weight[
NRESULT];
919 "msiDigestMonStat: input rei or rsComm is NULL" );
925 if ( cpu_wght ==
NULL || mem_wght ==
NULL || swap_wght ==
NULL || runq_wght ==
NULL
926 || disk_wght ==
NULL || netin_wght ==
NULL || netout_wght ==
NULL ) {
928 "msiDigestMonStat: at least one of the input param is NULL" );
933 weight[0] = atoi( (
const char* )cpu_wght->
inOutStruct );
937 "msiDigestMonStat: Unsupported input cpu_wght type %s",
943 weight[1] = atoi( (
const char* )mem_wght->
inOutStruct );
947 "msiDigestMonStat: Unsupported input mem_wght type %s",
953 weight[2] = atoi( (
const char* )swap_wght->
inOutStruct );
957 "msiDigestMonStat: Unsupported input swap_wght type %s",
963 weight[3] = atoi( (
const char* )runq_wght->
inOutStruct );
967 "msiDigestMonStat: Unsupported input runq_wght type %s",
973 weight[4] = atoi( (
const char* )disk_wght->
inOutStruct );
977 "msiDigestMonStat: Unsupported input disk_wght type %s",
983 weight[5] = atoi( (
const char* )netin_wght->
inOutStruct );
987 "msiDigestMonStat: Unsupported input netin_wght type %s",
993 weight[6] = atoi( (
const char* )netout_wght->
inOutStruct );
997 "msiDigestMonStat: Unsupported input netout_wght type %s",
1003 for ( i = 0; i <
NRESULT; i++ ) {
1004 totalWeight += weight[i];
1007 memset( &genQueryInp, 0,
sizeof( genQueryInp ) );
1012 if (
NULL == genQueryOut ) {
1017 nresc = genQueryOut->
rowCnt;
1018 for ( i = 0; i < genQueryOut->
attriCnt; i++ ) {
1019 for ( j = 0; j < nresc; j++ ) {
1033 from R_SERVER_LOAD" );
1037 memset( &genQueryInp, 0,
sizeof( genQueryInp ) );
1046 generalRowInsertInp.
tableName =
"serverloaddigest";
1047 for ( i = 0; i < nresc; i++ ) {
1049 snprintf( condStr1,
MAX_NAME_LEN,
"= '%s'", rescList[i] );
1051 snprintf( condStr2,
MAX_NAME_LEN,
"= '%s'", timeList[i] );
1056 for ( j = 0; j < genQueryOut->
attriCnt; j++ ) {
1058 loadFactor += atoi( tResult ) * weight[j];
1060 loadFactor = loadFactor / totalWeight;
1061 generalRowInsertInp.
arg1 = rescList[i];
1063 generalRowInsertInp.
arg2 = loadStr;
1067 information into from R_SERVER_LOAD_DIGEST table" );