Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The faulty server is modified to top10 #16

Merged
merged 2 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ZbxContent(models.Model):
id = models.UUIDField(blank=True, primary_key=True, auto_created=True, default=uuid.uuid4)
eventid = models.IntegerField(unique=True, verbose_name=u'事件ID')
title = models.CharField(max_length=255, verbose_name=u'故障简述')
host = models.CharField(max_length=120, verbose_name='故障服务器', null=True)
host = models.CharField(max_length=120, verbose_name='故障服务器Top10', null=True)
author = models.CharField(max_length=10, default='ZABBIX', verbose_name=u'ZBX用户')
level = models.CharField(max_length=60, verbose_name=u'故障级别')
type = models.CharField(max_length=120, verbose_name=u'zbx应用集', blank=True, null=True)
Expand Down
6 changes: 6 additions & 0 deletions dashboard/zbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ def index_data(request):

# 最近三个月数据
for i in items_pie:

_content = ZbxContent.objects.raw('SELECT id,%s as item,count(id) as count FROM content_zbxcontent WHERE DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(start_time) GROUP BY %s' % (i, i))
#获取到top10的故障服务器
if i=='host':
content = ZbxContent.objects.raw('select * from (SELECT id,%s as item,count(id) as count FROM content_zbxcontent WHERE DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(start_time) GROUP BY %s) a order by count desc' % (i, i))
_content = content[:10] if content
data[i] = get_pie_data(_content, i)

# 根据故障项目分类,今年故障数量统计
content_history = ZbxContent.objects.raw(
'SELECT id,count(*) as count,DATE_FORMAT(start_time,"%%Y-%%m") as date from content_zbxcontent where YEAR(start_time) = YEAR(CURDATE()) GROUP by DATE_FORMAT(start_time,"%%Y-%%m")')
Expand Down