Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
SkyAPM
SkyAPM-php-sdk
提交
cc47fb18
S
SkyAPM-php-sdk
项目概览
SkyAPM
/
SkyAPM-php-sdk
通知
14
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyAPM-php-sdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
cc47fb18
编写于
4月 30, 2019
作者:
何
何延龙
提交者:
GitHub
4月 30, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #59 from goerzh/heartbeat
Heartbeat
上级
67377034
a5e9aa71
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
71 addition
and
46 deletion
+71
-46
config.m4
config.m4
+1
-1
php_skywalking.h
php_skywalking.h
+1
-0
skywalking.c
skywalking.c
+25
-22
src/greeter_client.cc
src/greeter_client.cc
+14
-3
src/report/Makefile
src/report/Makefile
+2
-2
src/report/report_client.cc
src/report/report_client.cc
+28
-18
未找到文件。
config.m4
浏览文件 @
cc47fb18
...
...
@@ -30,7 +30,7 @@ fi
if test "$PHP_SKYWALKING" != "no"; then
CXXFLAGS+=" -std=c++11 -Isrc/report/deps/boost "
CXXFLAGS+=" -std=c++11 -Isrc/report/deps/boost
-DDEBUG
"
PHP_REQUIRE_CXX()
KYWALKING_LIBS=`pkg-config --cflags --libs protobuf grpc++ grpc`
...
...
php_skywalking.h
浏览文件 @
cc47fb18
...
...
@@ -170,6 +170,7 @@ ZEND_BEGIN_MODULE_GLOBALS(skywalking)
zval
curl_header_send
;
int
version
;
int
header_version
;
int
register_retry
;
ZEND_END_MODULE_GLOBALS
(
skywalking
)
extern
ZEND_DECLARE_MODULE_GLOBALS
(
skywalking
);
...
...
skywalking.c
浏览文件 @
cc47fb18
...
...
@@ -80,6 +80,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY
(
"skywalking.log_path"
,
"/tmp"
,
PHP_INI_ALL
,
OnUpdateString
,
log_path
,
zend_skywalking_globals
,
skywalking_globals
)
STD_PHP_INI_ENTRY
(
"skywalking.grpc"
,
"127.0.0.1:11800"
,
PHP_INI_ALL
,
OnUpdateString
,
grpc
,
zend_skywalking_globals
,
skywalking_globals
)
STD_PHP_INI_ENTRY
(
"skywalking.header_version"
,
"2"
,
PHP_INI_ALL
,
OnUpdateLong
,
header_version
,
zend_skywalking_globals
,
skywalking_globals
)
STD_PHP_INI_ENTRY
(
"skywalking.register_retry"
,
"10"
,
PHP_INI_ALL
,
OnUpdateLong
,
register_retry
,
zend_skywalking_globals
,
skywalking_globals
)
PHP_INI_END
()
/* }}} */
...
...
@@ -715,26 +716,23 @@ static char *get_page_request_peer() {
* @return return_type
// */
static
char
*
_get_current_machine_ip
(){
char
*
ip
;
ip
=
(
char
*
)
emalloc
(
sizeof
(
char
)
*
100
);
bzero
(
ip
,
100
);
char
*
ip
;
zval
*
carrier
=
NULL
;
ip
=
(
char
*
)
emalloc
(
sizeof
(
char
)
*
100
);
bzero
(
ip
,
100
);
carrier
=
&
PG
(
http_globals
)[
TRACK_VARS_SERVER
];
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
){
strcpy
(
ip
,
"127.0.0.1"
);
}
else
{
char
hname
[
128
];
struct
hostent
*
hent
;
gethostname
(
hname
,
sizeof
(
hname
));
hent
=
gethostbyname
(
hname
);
ip
=
inet_ntoa
(
*
(
struct
in_addr
*
)(
hent
->
h_addr_list
[
0
]));
}
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
)
{
strcpy
(
ip
,
"127.0.0.1"
);
}
else
{
char
hname
[
128
];
struct
hostent
*
hent
;
gethostname
(
hname
,
sizeof
(
hname
));
hent
=
gethostbyname
(
hname
);
if
(
hent
==
NULL
)
{
strcpy
(
ip
,
"127.0.0.1"
);
}
else
{
ip
=
inet_ntoa
(
*
(
struct
in_addr
*
)
(
hent
->
h_addr_list
[
0
]));
}
}
return
ip
;
}
...
...
@@ -886,7 +884,7 @@ static void module_init() {
}
i
++
;
}
while
(
application_id
==
-
100000
&&
i
<=
3
);
}
while
(
application_id
==
-
100000
&&
i
<=
SKYWALKING_G
(
register_retry
)
);
if
(
application_id
==
-
100000
)
{
sky_close
=
1
;
...
...
@@ -913,7 +911,7 @@ static void module_init() {
sleep
(
1
);
}
i
++
;
}
while
(
application_instance
==
-
100000
&&
i
<=
3
);
}
while
(
application_instance
==
-
100000
&&
i
<=
SKYWALKING_G
(
register_retry
)
);
if
(
application_instance
==
-
100000
)
{
...
...
@@ -932,7 +930,12 @@ PHP_MINIT_FUNCTION (skywalking) {
/* If you have INI entries, uncomment these lines
*/
if
(
SKYWALKING_G
(
enable
))
{
module_init
();
if
(
strcasecmp
(
"cli"
,
sapi_module
.
name
)
==
0
)
{
sky_close
=
1
;
}
else
{
module_init
();
}
if
(
sky_close
==
1
)
{
return
SUCCESS
;
}
...
...
src/greeter_client.cc
浏览文件 @
cc47fb18
...
...
@@ -62,7 +62,9 @@ public:
ServiceRegisterMapping
reply
;
ClientContext
context
;
#ifdef DEBUG
std
::
cout
<<
"Register service: "
<<
boost_uuid
<<
std
::
endl
;
#endif
Status
status
=
stub_
->
doServiceRegister
(
&
context
,
request
,
&
reply
);
if
(
status
.
ok
())
{
...
...
@@ -116,11 +118,20 @@ public:
Status
status
=
stub_
->
doServiceInstanceRegister
(
&
context
,
request
,
&
reply
);
#ifdef DEBUG
if
(
!
status
.
ok
())
{
std
::
cout
<<
"status code: "
<<
status
.
error_code
()
<<
std
::
endl
;
std
::
cout
<<
"err message: "
<<
status
.
error_message
()
<<
std
::
endl
;
std
::
cout
<<
"err detail: "
<<
status
.
error_details
()
<<
std
::
endl
;
}
#endif
if
(
status
.
ok
())
{
for
(
int
i
=
0
;
i
<
reply
.
serviceinstances_size
();
i
++
)
{
const
KeyIntValuePair
&
kv
=
reply
.
serviceinstances
(
i
);
// std::cout << "Register Instance:"<< std::endl;
// std::cout << kv.key() << ": " << kv.value() << std::endl;
#ifdef DEBUG
std
::
cout
<<
"Register Instance: "
<<
kv
.
key
()
<<
": "
<<
kv
.
value
()
<<
std
::
endl
;
#endif
if
(
kv
.
key
()
==
uuid
)
{
return
kv
.
value
();
...
...
src/report/Makefile
浏览文件 @
cc47fb18
...
...
@@ -46,8 +46,8 @@ OBJS = ../grpc/language-agent-v2/.libs/trace.o ../grpc/language-agent-v2/.libs/t
../grpc/register/.libs/InstancePing-grpc.o ../grpc/common/.libs/common.o ../grpc/common/.libs/common-grpc.o
\
../grpc/common/.libs/trace-common.o ../grpc/common/.libs/trace-common-grpc.o
report_client
:
$(OBJS)
$(CXX)
report_client.cpp
$^
$(LDFLAGS)
-Ideps
/boost
$(CXXFLAGS)
-o
$@
report_client
:
$(OBJS)
report_client.cc
$(CXX)
$^
$(LDFLAGS)
-Ideps
/boost
$(CXXFLAGS)
-o
$@
clean
:
rm
-rf
*
.o
*
.pb.cc
*
.pb.h report_client
\
...
...
src/report/report_client.c
pp
→
src/report/report_client.c
c
浏览文件 @
cc47fb18
...
...
@@ -59,6 +59,8 @@ using grpc::Status;
using
grpc
::
ClientWriter
;
using
json
=
nlohmann
::
json
;
using
namespace
std
::
chrono
;
class
GreeterClient
{
public:
GreeterClient
(
std
::
shared_ptr
<
Channel
>
channel
)
...
...
@@ -113,14 +115,14 @@ int main(int argc, char **argv) {
if
(
std
::
strncmp
(
"-h"
,
argv
[
i
],
sizeof
(
argv
[
i
])
-
1
)
==
0
||
std
::
strncmp
(
"--help"
,
argv
[
i
],
sizeof
(
argv
[
i
])
-
1
)
==
0
)
{
std
::
cout
<<
"report_client grpc log_path"
<<
std
::
endl
;
std
::
cout
<<
"e.g. report_client 12
0
.0.0.1:11800 /tmp"
<<
std
::
endl
;
std
::
cout
<<
"e.g. report_client 12
7
.0.0.1:11800 /tmp"
<<
std
::
endl
;
return
0
;
}
}
if
(
argc
==
1
)
{
std
::
cout
<<
"report_client grpc log_path"
<<
std
::
endl
;
std
::
cout
<<
"e.g. report_client 12
0
.0.0.1:11800 /tmp"
<<
std
::
endl
;
std
::
cout
<<
"e.g. report_client 12
7
.0.0.1:11800 /tmp"
<<
std
::
endl
;
return
0
;
}
...
...
@@ -130,6 +132,12 @@ int main(int argc, char **argv) {
std
::
map
<
int
,
std
::
string
>
instanceUUID
;
std
::
map
<
int
,
long
>
sendTime
;
milliseconds
guard
;
guard
=
duration_cast
<
milliseconds
>
(
system_clock
::
now
().
time_since_epoch
()
);
while
(
1
)
{
struct
dirent
*
dir
;
...
...
@@ -140,22 +148,24 @@ int main(int argc, char **argv) {
}
// heartbeat
for
(
auto
&
i
:
instancePid
)
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
if
(
tv
.
tv_sec
-
sendTime
[
i
.
first
]
>
40
)
{
kill
(
instancePid
[
i
.
first
],
0
);
if
((
duration_cast
<
milliseconds
>
(
system_clock
::
now
().
time_since_epoch
())
-
guard
)
>
seconds
(
60
))
{
guard
=
duration_cast
<
milliseconds
>
(
system_clock
::
now
().
time_since_epoch
());
for
(
auto
&
i
:
instancePid
)
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
// if (tv.tv_sec - sendTime[i.first] > 40) {
// kill(instancePid[i.first], 0);
// }
sendTime
[
i
.
first
]
=
tv
.
tv_sec
;
std
::
cout
<<
"send heartbeat, instance id: "
<<
i
.
first
<<
std
::
endl
;
ServiceInstancePingPkg
request
;
request
.
set_serviceinstanceid
(
i
.
first
);
request
.
set_time
(
tv
.
tv_sec
*
1000
+
tv
.
tv_usec
/
1000
);
request
.
set_serviceinstanceuuid
(
instanceUUID
[
i
.
first
]);
greeter
.
heartbeat
(
request
);
}
sendTime
[
i
.
first
]
=
tv
.
tv_sec
;
std
::
cout
<<
"send heartbeat ..."
<<
std
::
endl
;
ServiceInstancePingPkg
request
;
request
.
set_serviceinstanceid
(
i
.
first
);
request
.
set_time
(
tv
.
tv_sec
*
1000
+
tv
.
tv_usec
/
1000
);
request
.
set_serviceinstanceuuid
(
instanceUUID
[
i
.
first
]);
greeter
.
heartbeat
(
request
);
}
while
((
dir
=
readdir
(
dp
))
!=
NULL
)
{
...
...
@@ -331,7 +341,7 @@ int main(int argc, char **argv) {
}
closedir
(
dp
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
500
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录