private void sendNodeOsStats(OsStats osStats) {
    String prefix = this.getPrefix("os");

    double[] loadAverage = osStats.getLoadAverage();
    if (loadAverage.length > 0) {
      this.sendGauge(prefix + ".load_average", "1m", loadAverage[0]);
      this.sendGauge(prefix + ".load_average", "5m", loadAverage[1]);
      this.sendGauge(prefix + ".load_average", "15m", loadAverage[2]);
    }

    if (osStats.cpu() != null) {
      this.sendGauge(prefix + ".cpu", "sys", osStats.cpu().sys());
      this.sendGauge(prefix + ".cpu", "user", osStats.cpu().user());
      this.sendGauge(prefix + ".cpu", "idle", osStats.cpu().idle());
      this.sendGauge(prefix + ".cpu", "stolen", osStats.cpu().stolen());
    }

    if (osStats.mem() != null) {
      this.sendGauge(prefix + ".mem", "free_in_bytes", osStats.mem().free().bytes());
      this.sendGauge(prefix + ".mem", "used_in_bytes", osStats.mem().used().bytes());
      this.sendGauge(prefix + ".mem", "free_percent", osStats.mem().freePercent());
      this.sendGauge(prefix + ".mem", "used_percent", osStats.mem().usedPercent());
      this.sendGauge(prefix + ".mem", "actual_free_in_bytes", osStats.mem().actualFree().bytes());
      this.sendGauge(prefix + ".mem", "actual_used_in_bytes", osStats.mem().actualUsed().bytes());
    }

    if (osStats.swap() != null) {
      this.sendGauge(prefix + ".swap", "free_in_bytes", osStats.swap().free().bytes());
      this.sendGauge(prefix + ".swap", "used_in_bytes", osStats.swap().used().bytes());
    }
  }
示例#2
0
  public OsStats osStats() {
    OsStats stats = new OsStats();
    stats.timestamp = System.currentTimeMillis();
    stats.cpu = new OsStats.Cpu();
    stats.cpu.percent = getSystemCpuPercent();
    stats.cpu.loadAverage = getSystemLoadAverage();

    OsStats.Mem mem = new OsStats.Mem();
    mem.total = getTotalPhysicalMemorySize();
    mem.free = getFreePhysicalMemorySize();
    stats.mem = mem;

    OsStats.Swap swap = new OsStats.Swap();
    swap.total = getTotalSwapSpaceSize();
    swap.free = getFreeSwapSpaceSize();
    stats.swap = swap;

    return stats;
  }
示例#3
0
    @Override
    protected void configure() {
      functionBinder =
          MapBinder.newMapBinder(binder(), FunctionIdent.class, FunctionImplementation.class);
      functionBinder.addBinding(TestFunction.ident).toInstance(new TestFunction());
      bind(Functions.class).asEagerSingleton();
      bind(ReferenceInfos.class).toInstance(mock(ReferenceInfos.class));
      bind(ThreadPool.class).toInstance(testThreadPool);

      BulkRetryCoordinator bulkRetryCoordinator = mock(BulkRetryCoordinator.class);
      BulkRetryCoordinatorPool bulkRetryCoordinatorPool = mock(BulkRetryCoordinatorPool.class);
      when(bulkRetryCoordinatorPool.coordinator(any(ShardId.class)))
          .thenReturn(bulkRetryCoordinator);
      bind(BulkRetryCoordinatorPool.class).toInstance(bulkRetryCoordinatorPool);

      bind(TransportBulkCreateIndicesAction.class)
          .toInstance(mock(TransportBulkCreateIndicesAction.class));
      bind(CircuitBreakerService.class).toInstance(new NoneCircuitBreakerService());
      bind(ActionFilters.class).toInstance(mock(ActionFilters.class));
      bind(ScriptService.class).toInstance(mock(ScriptService.class));
      bind(SearchService.class).toInstance(mock(InternalSearchService.class));
      bind(AllocationService.class).toInstance(mock(AllocationService.class));
      bind(MetaDataCreateIndexService.class).toInstance(mock(MetaDataCreateIndexService.class));
      bind(DynamicSettings.class)
          .annotatedWith(ClusterDynamicSettings.class)
          .toInstance(mock(DynamicSettings.class));
      bind(MetaDataDeleteIndexService.class).toInstance(mock(MetaDataDeleteIndexService.class));
      bind(ClusterInfoService.class).toInstance(mock(ClusterInfoService.class));
      bind(TransportService.class).toInstance(mock(TransportService.class));
      bind(MapperService.class).toInstance(mock(MapperService.class));

      OsService osService = mock(OsService.class);
      OsStats osStats = mock(OsStats.class);
      when(osService.stats()).thenReturn(osStats);
      OsStats.Cpu osCpu = mock(OsStats.Cpu.class);
      when(osCpu.stolen()).thenReturn((short) 1);
      when(osStats.cpu()).thenReturn(osCpu);

      bind(OsService.class).toInstance(osService);
      bind(NodeService.class).toInstance(mock(NodeService.class));
      bind(Discovery.class).toInstance(mock(Discovery.class));
      bind(NetworkService.class).toInstance(mock(NetworkService.class));

      bind(TransportShardBulkAction.class).toInstance(mock(TransportShardBulkAction.class));
      bind(TransportCreateIndexAction.class).toInstance(mock(TransportCreateIndexAction.class));

      discoveryService = mock(DiscoveryService.class);
      DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
      when(discoveryNode.id()).thenReturn(TEST_NODE_ID);
      when(discoveryService.localNode()).thenReturn(discoveryNode);

      ClusterService clusterService = mock(ClusterService.class);
      ClusterState state = mock(ClusterState.class);
      DiscoveryNodes discoveryNodes = mock(DiscoveryNodes.class);
      when(discoveryNodes.localNodeId()).thenReturn(TEST_NODE_ID);
      when(state.nodes()).thenReturn(discoveryNodes);
      when(clusterService.state()).thenReturn(state);
      when(clusterService.localNode()).thenReturn(discoveryNode);
      bind(ClusterService.class).toInstance(clusterService);

      IndicesService indicesService = mock(IndicesService.class);
      bind(IndicesService.class).toInstance(indicesService);
      bind(Settings.class).toInstance(ImmutableSettings.EMPTY);

      bind(MetaDataUpdateSettingsService.class)
          .toInstance(mock(MetaDataUpdateSettingsService.class));
      bind(Client.class).toInstance(mock(Client.class));

      Provider<TransportCreateIndexAction> transportCreateIndexActionProvider =
          mock(Provider.class);
      when(transportCreateIndexActionProvider.get())
          .thenReturn(mock(TransportCreateIndexAction.class));
      Provider<TransportDeleteIndexAction> transportDeleteActionProvider = mock(Provider.class);
      when(transportDeleteActionProvider.get()).thenReturn(mock(TransportDeleteIndexAction.class));
      Provider<TransportUpdateSettingsAction> transportUpdateSettingsActionProvider =
          mock(Provider.class);
      when(transportUpdateSettingsActionProvider.get())
          .thenReturn(mock(TransportUpdateSettingsAction.class));

      BlobIndices blobIndices =
          new BlobIndices(
              ImmutableSettings.EMPTY,
              transportCreateIndexActionProvider,
              transportDeleteActionProvider,
              transportUpdateSettingsActionProvider,
              indicesService,
              mock(IndicesLifecycle.class),
              mock(BlobEnvironment.class),
              clusterService);
      bind(BlobIndices.class).toInstance(blobIndices);

      bind(ReferenceResolver.class).to(GlobalReferenceResolver.class);

      TransportPutIndexTemplateAction transportPutIndexTemplateAction =
          mock(TransportPutIndexTemplateAction.class);
      bind(TransportPutIndexTemplateAction.class).toInstance(transportPutIndexTemplateAction);

      bind(IndexService.class).toInstance(indexService);
    }