首页 > 编程语言 >保持cerebro的通知及查询Node的box_type

保持cerebro的通知及查询Node的box_type

时间:2023-02-04 18:00:39浏览次数:48  
标签:Node box return name function cerebro alert 节点

今天介绍通过chrome谷歌浏览器, 改进cerebro的两个小功能. 

1. 保持cerebro的通知显示.

默认cerebro的通知显示只有几秒,还没有看清楚是什么问题,通知框就消失了.尤其是是服务器出现故障,频繁掉节点/或者索引有变动时, 还没看清是哪个节点出故障,或者别人删除/添加了哪个索引时,通知内容就消失了.

这个问题,可以通过修改cerebro的脚本,并通过chrome的本地覆盖(overrides)功能 实现通知上添加时间, 同时不再自动消失. 

浏览器F12->源码->js 里的app.js, 右键点击 "保存并覆盖" , 在打开的app.js tab 里找到如下代码:

  this.addAlert = function(alert, timeout) {
    this.alerts.unshift(alert);
    var service = this;
    setTimeout(function() {
      service.remove(alert.id);
    }, timeout);
    if (this.alerts.length >= this.maxAlerts) {
      this.alerts.length = 3;
    }
    return alert.id;
  };

改为如下代码即可:

  this.addAlert = function(alert, timeout) {
    this.alerts.unshift(alert);
    // 为通知增加一个时间
    alert.message = alert.message + " - " + time.toLocaleTimeString();
    var service = this;
    /*
    setTimeout(function() {
      service.remove(alert.id);
    }, timeout);
    if (this.alerts.length >= this.maxAlerts) {
      this.alerts.length = 3;
    }
    */
    return alert.id;
  };

这样就可以让cerebro的通知持续显示, 并显示通知时间了

注意: 这个本地覆盖只有在加载本地代码时才生效. 所以需要每次打开cerebro后. 按一下F12,启动本地代码后.才可以生效.

 

2. cerebro 在节点筛选时也有个小问题. 就是不能按节点的attribute的box_type筛选, 我们的ES节点增加很多后, 无法根据name筛选出hot节点或者warm节点. 也可以用上述方法修改部分代码解决.

1. 同样是修改app.js  修改:

  this.matches = function(node) {
    if (this.isBlank()) {
      return true;
    } else {
      return this.matchesName(node.name) && this.matchesType(node);  <---修改这行的 this.matchesName(node.name) 为 this.matchesName(node)
    }
  };

2. 找到:

  this.matchesName = function(name) {
    if (this.name) {
      return name.toLowerCase().indexOf(this.name.toLowerCase()) != -1;
    } else {
      return true;
    }
  };

修改为

  this.matchesName = function(node) {
    if (this.name) {
      // 当输入搜索条件为hot或warm时,找出box_type是对应值的节点
      if (this.name == 'hot' || this.name == 'warm')
        return node.attributes["box_type"] == this.name;
      else
        return node.name.toLowerCase().indexOf(this.name.toLowerCase()) != -1;
    } else {
      return true;
    }
  };

这样在name搜索栏. 输入 hot或者warm 时, 即可搜索到 hot节点和warm节点. 

 

上述方法仅在一些特定场景下有需要,利用情况较少. 所以没有搞到油猴脚本或者做的更复杂. 优点就是非常简单, 到任何新机器上都可以1分钟搞定来解决问题. 

本篇属于奇技淫巧, 使用上需要先按F12. 略有不足. 有其他问题留言

 

标签:Node,box,return,name,function,cerebro,alert,节点
From: https://www.cnblogs.com/kirc/p/17092057.html

相关文章