提交 1b266ef0 编写于 作者: H heyanlong

add sock

上级 fdf2a1c3
dnl $Id$
dnl config.m4 for extension skywalking
dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.
dnl If your extension references something external, use with:
dnl PHP_ARG_WITH(skywalking, for skywalking support,
dnl Make sure that the comment is aligned:
dnl [ --with-skywalking Include skywalking support])
dnl Otherwise use enable:
dnl PHP_ARG_ENABLE(skywalking, whether to enable skywalking support,
dnl Make sure that the comment is aligned:
dnl [ --enable-skywalking Enable skywalking support])
PHP_ARG_ENABLE(skywalking, whether to enable skywalking support,
[ --enable-skywalking Enable skywalking support])
PHP_ARG_WITH(libgrpc, for libgrpc support,
[ --with-libgrpc[=DIR] Include libxyz support])
if test -z "$PHP_DEBUG"; then
AC_ARG_ENABLE(debug,
[ --enable-debug compile with debugging system],
[PHP_DEBUG=$enableval], [PHP_DEBUG=no]
)
fi
[ --enable-skywalking Enable skywalking support])
if test "$PHP_SKYWALKING" != "no"; then
PHP_REQUIRE_CXX()
dnl search grpc
SEARCH_GRPC_PATH="/usr/local /usr"
SEARCH_GRPC_FOR="/include/grpc/grpc.h"
if test -r $PHP_LIBGRPC/$SEARCH_GRPC_FOR; then
LIBGRPC_DIR=$PHP_LIBGRPC
else
AC_MSG_CHECKING([for libgrpc files in default path])
for i in $SEARCH_GRPC_PATH ; do
if test -r $i/$SEARCH_GRPC_FOR; then
LIBGRPC_DIR=$i
AC_MSG_RESULT(found in $i)
fi
done
fi
if test -z "$LIBGRPC_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please install libgrpc - See https://github.com/grpc/grpc])
fi
PHP_ADD_INCLUDE($LIBGRPC_DIR/include)
PHP_ADD_INCLUDE(src/report/deps/boost)
PHP_CHECK_LIBRARY(grpc, grpc_channel_destroy,
[
PHP_ADD_LIBRARY_WITH_PATH(grpc, $LIBGRPC_DIR/lib, LIBGRPC_SHARED_LIBADD)
AC_DEFINE(HAVE_LIBGRPCLIB,1,[ ])
],[
AC_MSG_ERROR([wrong libgrpc lib version or lib not found])
],[
-L$LIBGRPC_DIR/lib
])
PHP_SUBST(LIBGRPC_SHARED_LIBADD)
dnl SKYWALKING_SHARED_LIBADD="-lpthread $SKYWALKING_SHARED_LIBADD"
dnl AC_MSG_ERROR($SKYWALKING_SHARED_LIBADD)
dnl KYWALKING_LIBS=`pkg-config --cflags --libs protobuf grpc++ grpc`
dnl KYWALKING_LIBS+=" -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl "
AC_OUTPUT_COMMANDS(
protoc -I ./src/protocol-6 --cpp_out=./src/grpc ./src/protocol-6/common/*.proto
protoc -I ./src/protocol-6 --cpp_out=./src/grpc ./src/protocol-6/register/*.proto
protoc -I ./src/protocol-6 --cpp_out=./src/grpc ./src/protocol-6/language-agent-v2/*.proto
protoc -I ./src/protocol-6 --grpc_out=./src/grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./src/protocol-6/common/*.proto
protoc -I ./src/protocol-6 --grpc_out=./src/grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./src/protocol-6/register/*.proto
protoc -I ./src/protocol-6 --grpc_out=./src/grpc --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ./src/protocol-6/language-agent-v2/*.proto
)
AC_OUTPUT_COMMANDS(
mv src/grpc/common/common.grpc.pb.cc src/grpc/common/common-grpc.pb.cc
mv src/grpc/register/Register.grpc.pb.cc src/grpc/register/Register-grpc.pb.cc
mv src/grpc/language-agent-v2/trace.grpc.pb.cc src/grpc/language-agent-v2/trace-grpc.pb.cc
mv src/grpc/register/InstancePing.grpc.pb.cc src/grpc/register/InstancePing-grpc.pb.cc
mv src/grpc/common/trace-common.grpc.pb.cc src/grpc/common/trace-common-grpc.pb.cc
)
dnl PHP_EVAL_LIBLINE($KYWALKING_LIBS, SKYWALKING_SHARED_LIBADD)
PHP_ADD_LIBRARY(stdc++, 1, SKYWALKING_SHARED_LIBADD)
PHP_ADD_BUILD_DIR($ext_builddir/src/grpc)
PHP_ADD_INCLUDE("src/grpc")
PHP_ADD_INCLUDE("src")
PHP_SUBST(SKYWALKING_SHARED_LIBADD)
PHP_NEW_EXTENSION(skywalking, \
skywalking.c \
src/greeter_client.cc \
src/decode.c \
src/encode.c \
src/grpc/common/common-grpc.pb.cc \
src/grpc/common/common.pb.cc \
src/grpc/register/Register-grpc.pb.cc \
src/grpc/register/Register.pb.cc \
src/grpc/language-agent-v2/trace-grpc.pb.cc \
src/grpc/language-agent-v2/trace.pb.cc \
src/grpc/register/InstancePing-grpc.pb.cc \
src/grpc/register/InstancePing.pb.cc \
src/grpc/common/trace-common-grpc.pb.cc \
src/grpc/common/trace-common.pb.cc \
, $ext_shared,, -Wall -Werror -std=c++11)
, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
fi
......@@ -51,12 +51,9 @@
#include <fcntl.h>
#include <dirent.h>
#include "b64.h"
extern int serviceRegister(char *grpc_server, char *code);
#include <sys/un.h>
extern int serviceInstanceRegister(char *grpc_server, int appId, long registertime, char *osname, char *hostname,
int processno, char *ipv4s);
#include "b64.h"
/* If you declare any globals in php_skywalking.h uncomment this:
*/
......@@ -64,11 +61,12 @@ ZEND_DECLARE_MODULE_GLOBALS(skywalking)
/* True global resources - no need for thread safety here */
static int le_skywalking;
static int application_instance = 0;
static int application_id = 0;
static int application_instance = -100000;
static int application_id = -100000;
static int sky_close = 0;
static int sky_increment_id = 0;
char *uuid = NULL;
const char *sock_path = "/tmp/sky_agent.sock";
/* {{{ PHP_INI
*/
......@@ -920,6 +918,47 @@ static void module_init() {
}
}
static int sky_register() {
if (application_id == -100000 || application_instance == -100000) {
struct sockaddr_un un;
un.sun_family = AF_UNIX;
strcpy(un.sun_path, sock_path);
int fd;
char message[4096];
char return_message[4096];
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd >= 0) {
int conn = connect(fd, (struct sockaddr *) &un, sizeof(un));
if (conn >= 0) {
bzero(message, sizeof(message));
sprintf(message, "0{\"app_code\":\"%s\",\"pid\":%d}\n", SKYWALKING_G(app_code), getppid());
write(fd, message, strlen(message));
bzero(return_message, sizeof(return_message));
read(fd, return_message, sizeof(return_message));
application_id = atoi(return_message);
if (application_id != -100000) {
bzero(message, sizeof(message));
sprintf(message, "1{\"application_id\":\"%d\",\"pid\":%d}\n", application_id, getppid());
write(fd, message, strlen(message));
bzero(return_message, sizeof(return_message));
read(fd, return_message, sizeof(return_message));
application_instance = atoi(return_message);
}
}
close(fd);
}
}
return 0;
}
/* {{{ PHP_MINIT_FUNCTION
*/
......@@ -931,15 +970,10 @@ PHP_MINIT_FUNCTION (skywalking) {
*/
if (SKYWALKING_G(enable)) {
if (strcasecmp("cli", sapi_module.name) == 0) {
sky_close = 1;
} else {
module_init();
return SUCCESS;
}
if (sky_close == 1) {
return SUCCESS;
}
// set_sampling_rate(SKY_G(global_sampling_rate));
// bind curl
zend_function *old_function;
if ((old_function = zend_hash_str_find_ptr(CG(function_table), "curl_exec", sizeof("curl_exec") - 1)) != NULL) {
orig_curl_exec = old_function->internal_function.handler;
......@@ -982,7 +1016,9 @@ PHP_RINIT_FUNCTION(skywalking)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
if (SKYWALKING_G(enable)) {
if (sky_close == 1) {
sky_register();
if(application_id == -100000 || application_instance == -100000) {
sky_close = 1;
return SUCCESS;
}
sky_increment_id++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册