def get_cluster_health_msg_hour():
    clusters = Cluster.objects.all()
    for cluster in clusters:
        cluster.change_to()
        nodes = Node.objects.all()
        host = "prometheus.apps"
        for node in nodes:
            role_names = []
            for role in node.roles.all():
                role_names.append(role.name)
            if 'master' in role_names:
                host = host + node.name[7:]
                break
        config = {'host': host}
        prometheus_client = PrometheusClient(config)
        result = prometheus_client.handle_targets_message(
            prometheus_client.targets())
        if result['success']:
            month = datetime.datetime.now().strftime('%Y-%m')
            clusterHealthHistory = ClusterHealthHistory(
                project_id=cluster.id,
                available_rate=result['rate'],
                date_type=ClusterHealthHistory.
                CLUSTER_HEALTH_HISTORY_DATE_TYPE_HOUR,
                month=month)
            clusterHealthHistory.save()
示例#2
0
    def get(self, request, *args, **kwargs):
        project_name = self.kwargs['project_name']
        cluster = Cluster.objects.get(name=project_name)
        domain_suffix = Setting.objects.get(key="domain_suffix")
        host = "prometheus.apps." + cluster.name + "." + domain_suffix.value
        config = {'host': host}
        response = HttpResponse(content_type='application/json')
        prometheus_client = PrometheusClient(config)
        result = prometheus_client.handle_targets_message(
            prometheus_client.targets())

        response.write(json.dumps(result))
        return response
示例#3
0
    def get(self, request, *args, **kwargs):
        project_name = self.kwargs['project_name']
        cluster = Cluster.objects.get(name=project_name)
        response = HttpResponse(content_type='application/json')
        if cluster.status == Cluster.CLUSTER_STATUS_ERROR or cluster.status == Cluster.CLUSTER_STATUS_READY:
            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
        domain_suffix = Setting.objects.get(key="domain_suffix")
        host = "prometheus.apps." + cluster.name + "." + domain_suffix.value
        config = {'host': host}
        prometheus_client = PrometheusClient(config)
        result = prometheus_client.handle_targets_message(
            prometheus_client.targets())

        response.write(json.dumps(result))
        return response
def get_cluster_health_msg_hour():
    clusters = Cluster.objects.all()
    for cluster in clusters:
        domain_suffix = Setting.objects.get(key="domain_suffix")
        host = "prometheus.apps."+cluster.name+"."+domain_suffix.value
        config = {
            'host': host
        }
        prometheus_client = PrometheusClient(config)
        result = prometheus_client.handle_targets_message(prometheus_client.targets())
        if result['success']:
            month = datetime.datetime.now().strftime('%Y-%m')
            clusterHealthHistory = ClusterHealthHistory(project_id=cluster.id,available_rate=result['rate'],
                                                        date_type=ClusterHealthHistory.CLUSTER_HEALTH_HISTORY_DATE_TYPE_HOUR,
                                                        month=month)
            clusterHealthHistory.save()
示例#5
0
    def get(self, request, *args, **kwargs):
        project_name = self.kwargs['project_name']
        cluster = Cluster.objects.get(name=project_name)
        domain_suffix = Setting.objects.get(key="domain_suffix")
        host = "prometheus.apps." + cluster.name + "." + domain_suffix.value
        config = {'host': host}
        response = HttpResponse(content_type='application/json')
        prometheus_client = PrometheusClient(config)
        result = prometheus_client.handle_targets_message(
            prometheus_client.targets())

        # config = {
        #     'end': time.time(),
        #     'start': time.time()-60,
        #     'table_name': 'etcd_server_health_success',
        #     'param': ''
        # }
        # dataArray = []
        # allData = []
        # if res.get('data') and res.get('data').get('result'):
        #     array  = res.get('data').get('result')
        #     for a in array:
        #         hostName = ''
        #         try:
        #             hostName = Host.objects.get(ip=a.get('metric').get('instance').split(':')[0]).name
        #         except:
        #             pass
        #         if hostName != '':
        #             data = {
        #                 'key':hostName,
        #                 'value': a.get('value')[1]
        #             }
        #             dataArray.append(data)
        # etcd = {
        #     'type': 'etcd',
        #     'data': dataArray
        # }
        # allData.append(etcd)
        #
        # result = {
        #     'status': res['status'],
        #     'data': allData
        # }

        response.write(json.dumps(result))
        return response
示例#6
0
 def get(self, request, *args, **kwargs):
     project_name = self.kwargs['project_name']
     cluster = Cluster.objects.get(name=project_name)
     response = HttpResponse(content_type='application/json')
     if cluster.status == Cluster.CLUSTER_STATUS_READY:
         return Response(data={'msg': ': 集群未创建'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     host = "prometheus.apps." + cluster.name + "." + cluster.cluster_doamin_suffix
     config = {
         'host': host
     }
     prometheus_client = PrometheusClient(config)
     try:
         result = prometheus_client.handle_targets_message(prometheus_client.targets())
     except Exception as e:
         logger.error(e, exc_info=True)
         return Response(data={'msg': ': 数据读取失败!'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     response.write(json.dumps(result))
     return response