Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
php_utils
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
php_utils
Commits
406bf6fa
Commit
406bf6fa
authored
Jun 22, 2021
by
yujiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:依赖基础数据库增加mon 打点
parent
55b92d6d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
14 deletions
+32
-14
MonUtil.php
src/Mon/MonUtil.php
+12
-8
MongoBase.php
src/Mongo/MongoBase.php
+4
-4
MysqlClusterBase.php
src/Mysql/MysqlClusterBase.php
+8
-1
RedisUtil.php
src/Redis/RedisUtil.php
+8
-1
No files found.
src/Mon/MonUtil.php
View file @
406bf6fa
...
@@ -84,26 +84,30 @@ class MonUtil{
...
@@ -84,26 +84,30 @@ class MonUtil{
return
$result
;
return
$result
;
}
}
/**
public
static
function
mongoMon
(
$mongo_host
,
$operator
,
$request_time
=
-
799
)
* @param $db_host string 链接数据的集群
* @param $operator string 数据库操作
* @param $db_name string 数据库名字 比如mysql ,mongodb
* @param int $request_time
*/
public
static
function
dbMon
(
$db_host
,
$operator
,
$db_name
,
$request_time
=
-
799
)
{
{
if
(
empty
(
$operator
)
||
!
is_string
(
$
mongo_host
))
{
if
(
empty
(
$operator
)
||
!
is_string
(
$
db_host
)
||
empty
(
$db_name
))
{
return
;
return
;
}
}
$host
=
''
;
if
(
empty
(
$
mongo
_host
))
{
if
(
empty
(
$
db
_host
))
{
$host
=
'unknow'
;
$host
=
'unknow'
;
}
else
{
}
else
{
$host
=
str_replace
(
array
(
"."
,
":"
,
"/"
),
array
(
"_"
,
"_"
,
"-"
),
$
mongo
_host
);
$host
=
str_replace
(
array
(
"."
,
":"
,
"/"
),
array
(
"_"
,
"_"
,
"-"
),
$
db
_host
);
}
}
//记录请求量
//记录请求量
self
::
counting
(
'mongodb.'
.
$host
,
(
string
)
$operator
,
0
);
self
::
counting
(
$db_name
.
'.'
.
$host
.
(
string
)
$operator
,
0
,
1
);
//耗时打点
//耗时打点
if
(
!
empty
(
$request_time
)
&&
is_numeric
(
$request_time
)
&&
$request_time
!=
-
799
){
if
(
!
empty
(
$request_time
)
&&
is_numeric
(
$request_time
)
&&
$request_time
!=
-
799
){
$result
=
self
::
timing
((
string
)(
'mongodb
.'
.
$host
.
$operator
),
"TotalTime"
,
$request_time
);
$result
=
self
::
timing
((
$db_name
.
'
.'
.
$host
.
$operator
),
"TotalTime"
,
$request_time
);
}
}
}
}
...
...
src/Mongo/MongoBase.php
View file @
406bf6fa
...
@@ -217,7 +217,7 @@ abstract class MongoBase
...
@@ -217,7 +217,7 @@ abstract class MongoBase
$start_time
=
microtime
(
true
);
$start_time
=
microtime
(
true
);
$res
=
$this
->
collection
->
insertOne
(
$document
,
$options
);
$res
=
$this
->
collection
->
insertOne
(
$document
,
$options
);
$end_time
=
microtime
(
true
);
$end_time
=
microtime
(
true
);
MonUtil
::
mongoMon
(
$this
->
host
??
'unknow'
,
'insertOne
'
,
$end_time
-
$start_time
);
MonUtil
::
dbMon
(
$this
->
host
??
'unknow'
,
'insertOne'
,
'mongodb
'
,
$end_time
-
$start_time
);
return
$res
;
return
$res
;
}
}
...
@@ -241,7 +241,7 @@ abstract class MongoBase
...
@@ -241,7 +241,7 @@ abstract class MongoBase
$start_time
=
microtime
(
true
);
$start_time
=
microtime
(
true
);
$res
=
$this
->
collection
->
insertMany
(
$documents
,
$options
);
$res
=
$this
->
collection
->
insertMany
(
$documents
,
$options
);
$end_time
=
microtime
(
true
);
$end_time
=
microtime
(
true
);
MonUtil
::
mongoMon
(
$this
->
host
??
'unknow'
,
'insertMany
'
,
$end_time
-
$start_time
);
MonUtil
::
dbMon
(
$this
->
host
??
'unknow'
,
'insertMany'
,
'mongodb
'
,
$end_time
-
$start_time
);
return
$res
;
return
$res
;
}
}
...
@@ -265,7 +265,7 @@ abstract class MongoBase
...
@@ -265,7 +265,7 @@ abstract class MongoBase
$start_time
=
microtime
(
true
);
$start_time
=
microtime
(
true
);
$res
=
$this
->
collection
->
deleteOne
(
$filter
,
$options
);
$res
=
$this
->
collection
->
deleteOne
(
$filter
,
$options
);
$end_time
=
microtime
(
true
);
$end_time
=
microtime
(
true
);
MonUtil
::
mongoMon
(
$this
->
host
??
'unknow'
,
'deleteOne
'
,
$end_time
-
$start_time
);
MonUtil
::
dbMon
(
$this
->
host
??
'unknow'
,
'deleteOne'
,
'mongodb
'
,
$end_time
-
$start_time
);
return
$res
;
return
$res
;
}
}
...
@@ -307,7 +307,7 @@ abstract class MongoBase
...
@@ -307,7 +307,7 @@ abstract class MongoBase
$start_time
=
microtime
(
true
);
$start_time
=
microtime
(
true
);
$res
=
$this
->
collection
->
findOne
(
$filter
,
$options
);
$res
=
$this
->
collection
->
findOne
(
$filter
,
$options
);
$end_time
=
microtime
(
true
);
$end_time
=
microtime
(
true
);
MonUtil
::
mongoMon
(
$this
->
host
??
'unknow'
,
'findOne
'
,
$end_time
-
$start_time
);
MonUtil
::
dbMon
(
$this
->
host
??
'unknow'
,
'findOne'
,
'mongodb
'
,
$end_time
-
$start_time
);
return
$res
;
return
$res
;
}
}
...
...
src/Mysql/MysqlClusterBase.php
View file @
406bf6fa
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
Api\PhpUtils\Mysql
;
namespace
Api\PhpUtils\Mysql
;
use
Api\PhpUtils\Mon\MonUtil
;
use
Api\PhpUtils\Mysql\Medoo
;
use
Api\PhpUtils\Mysql\Medoo
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\FileLog
;
...
@@ -183,6 +184,9 @@ abstract class MysqlClusterBase
...
@@ -183,6 +184,9 @@ abstract class MysqlClusterBase
}
}
self
::
$dbCurrentConnect
=
self
::
$dbConnect
[
$type
.
':'
.
$dbShardingIndex
];
self
::
$dbCurrentConnect
=
self
::
$dbConnect
[
$type
.
':'
.
$dbShardingIndex
];
//增加mon 打点
$start_time
=
microtime
(
true
);
self
::
$sqlResut
=
call_user_func_array
([
self
::
$dbConnect
[
$type
.
':'
.
$dbShardingIndex
],
$method
],
$arguments
);
self
::
$sqlResut
=
call_user_func_array
([
self
::
$dbConnect
[
$type
.
':'
.
$dbShardingIndex
],
$method
],
$arguments
);
if
(
!
self
::
catchError
(
$method
,
$arguments
))
{
if
(
!
self
::
catchError
(
$method
,
$arguments
))
{
...
@@ -193,6 +197,9 @@ abstract class MysqlClusterBase
...
@@ -193,6 +197,9 @@ abstract class MysqlClusterBase
return
false
;
return
false
;
}
}
}
}
$end_time
=
microtime
(
true
);
MonUtil
::
dbMon
(
self
::
dbCurrentConnect
[
'server'
]
.
'_'
.
self
::
dbCurrentConnect
[
'port'
]
??
'unknow_mysql'
,
$method
,
'mysql'
,
$end_time
-
$start_time
);
return
self
::
formatResult
(
$method
,
$arguments
);
return
self
::
formatResult
(
$method
,
$arguments
);
}
}
...
@@ -201,7 +208,7 @@ abstract class MysqlClusterBase
...
@@ -201,7 +208,7 @@ abstract class MysqlClusterBase
*
*
* @param [string] $type 读或写
* @param [string] $type 读或写
* @param boolean $flush 是否强制重新连接,重试等场景使用
* @param boolean $flush 是否强制重新连接,重试等场景使用
* @return
void
* @return
*/
*/
public
static
function
getConnection
(
$type
,
$dbShardingIndex
,
$flush
=
false
)
public
static
function
getConnection
(
$type
,
$dbShardingIndex
,
$flush
=
false
)
{
{
...
...
src/Redis/RedisUtil.php
View file @
406bf6fa
...
@@ -4,6 +4,7 @@ namespace Api\PhpUtils\Redis;
...
@@ -4,6 +4,7 @@ namespace Api\PhpUtils\Redis;
use
Api\PhpUtils\Http\Request
;
use
Api\PhpUtils\Http\Request
;
use
Api\PhpUtils\Cache\ApcuUtil
;
use
Api\PhpUtils\Cache\ApcuUtil
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Log\FileLog
;
use
Api\PhpUtils\Mon\MonUtil
;
use
Redis
;
use
Redis
;
class
RedisUtil
class
RedisUtil
...
@@ -653,6 +654,12 @@ class RedisUtil
...
@@ -653,6 +654,12 @@ class RedisUtil
if
(
!
$this
->
redis
)
{
if
(
!
$this
->
redis
)
{
return
false
;
return
false
;
}
}
return
call_user_func_array
([
$this
->
redis
,
$method
],
$args
);
//增加mon打点
$start_time
=
microtime
(
true
);
$res
=
call_user_func_array
([
$this
->
redis
,
$method
],
$args
);
$end_time
=
microtime
(
true
);
MonUtil
::
dbMon
(
$this
->
connectServer
??
'unknow_redis'
,
$method
,
'redis'
,
$end_time
-
$start_time
);
return
$res
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment