Beispiel #1
0
def get_stats(email):
    channel = grpc.insecure_channel('%s:%s' % (SERVER_ADDRESS, SERVER_PORT))
    stub = status_command_pb2_grpc.StatsServiceStub(channel)

    resp = stub.GetStats(
        stats_command_pb2.GetStatsRequest(name=email, reset=False))
    print(resp)
Beispiel #2
0
def stat_user(email, reset=False):
    channel = grpc.insecure_channel('%s:%s' % (SERVER_ADDRESS, SERVER_PORT))
    stub = scommand_pb2_grpc.StatsServiceStub(channel)

    name = 'user>>>%s>>>traffic>>>downlink' % email

    resp = stub.GetStats(scommand_pb2.GetStatsRequest(
        name=name,
        reset=reset,
    ))
    print(resp)
Beispiel #3
0
    def _get_stats(self, email=None, tag=None, uplink=True, reset=False):
        if email:
            s = ''.join(['user>>>', email, '>>>traffic>>>'])
        else:
            s = ''.join(['inbound>>>', tag, '>>>traffic>>>'])
        if uplink:
            s = s + '>>>uplink'
        else:
            s = s + '>>>downlink'
        stub = stats_command_pb2_grpc.StatsServiceStub(self._channel)

        resp = stub.GetStats(
            stats_command_pb2.GetStatsRequest(name=s, reset=reset))
        return resp
def get_stats(email=None, tag=None, uplink=True):
    if email:
        s = ''.join(['user>>>', email, '>>>traffic>>>'])
    else:
        s = ''.join(['inbound>>>', email, '>>>traffic>>>'])
    if uplink:
        s = s + '>>>uplink'
    else:
        s = s + '>>>downlink'
    channel = grpc.insecure_channel('%s:%s' % (SERVER_ADDRESS, SERVER_PORT))
    stub = status_command_pb2_grpc.StatsServiceStub(channel)

    resp = stub.GetStats(stats_command_pb2.GetStatsRequest(name=s,
                                                           reset=False))
    print(resp)
Beispiel #5
0
 def get_user_traffic_uplink(self, email, reset=True):
     """
     获取用户上行流量,单位:字节
     若该email未产生流量或email有误,返回None
     :param email: 邮箱
     :param reset: 是否重置计数器
     """
     stub = stats_command_pb2_grpc.StatsServiceStub(self._channel)
     try:
         return stub.GetStats(stats_command_pb2.GetStatsRequest(
             name="user>>>{}>>>traffic>>>uplink".format(email),
             reset=reset
         )).stat.value
     except grpc.RpcError:
         return None
Beispiel #6
0
 def get_sys_traffic_uplink(self, tag, reset=False):
     """
     获取用户上行流量,单位:字节
     若该tag未产生流量或tag有误,返回None
     :param tag: 此传入连接的标识
     :param reset: 是否重置计数器
     """
     stub = stats_command_pb2_grpc.StatsServiceStub(self._channel)
     try:
         return stub.GetStats(
             stats_command_pb2.GetStatsRequest(
                 name=f"inbound>>>{tag}>>>traffic>>>uplink",
                 reset=reset)).stat.value
     except grpc.RpcError:
         return None
Beispiel #7
0
 def get_user_aliveips(self, email, reset=True):
     """
     获取用户在线ip list,如果没有则返回None
     :param email: 邮箱
     :param reset: 是否重置计数器
     """
     stub = stats_command_pb2_grpc.StatsServiceStub(self._channel)
     try:
         raw_ips = stub.GetStats(stats_command_pb2.GetStatsRequest(
             name="user>>>{}>>>traffic>>>ips".format(email),
             reset=reset
         )).stat.name
         temp_ips = raw_ips.strip().split(";")[1:]
         correct_ips =[]
         for ip in temp_ips:
             try:
                 ipaddress.ip_address(ip)
                 correct_ips.append(ip)
             except ValueError:
                 continue
         return correct_ips
     except grpc.RpcError:
         return None