Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2015 Attribyte, LLC
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and limitations under the License.
  *
  */
 
 package org.attribyte.essem.sysmon.linux;
 
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;

Expose values supplied by /proc/meminfo as gauges.

Schedule an instance to run periodically to gather statistics.

See also:
 
 public class MemoryInfo implements MetricSetRunnable {
 
     /*
      /proc/meminfo
         e.g.
         MemTotal:        8055664 kB
         MemFree:          740628 kB
     */

   
Holds a map of name, value pairs that describe the current memory state of the system. The units are system-specific (?), but seems always to be 'kB'.
 
    public static class CurrentMemValues {
 
       private CurrentMemValues() {
          File pathFile = new File();
          if(pathFile.exists()) {
             ImmutableMap<StringLong_fields;
             try {
                List<Stringlines = Files.asCharSource(new File(), .).readLines();
                ImmutableMap.Builder<StringLongbuilder = ImmutableMap.builder();
                for(String line : lines) {
                   Iterator<Stringtok = .split(line).iterator();
                   if(tok.hasNext()) {
                      String key = tok.next();
                      if(tok.hasNext()) {
                         long val = Long.parseLong(tok.next());
                         builder.put(keyval);
                      }
                   }
                }
                _fields = builder.build();
             } catch(IOException|NumberFormatException e) {
                _fields = ImmutableMap.of();
 
             }
             this. = _fields;
          } else {
             this. = ImmutableMap.of();
          }
       }
 
       public final ImmutableMap<StringLongfields;
       private static final String PATH = "/proc/meminfo";
       private static final Splitter tokenSplitter = Splitter.on(CharMatcher.anyOf(": \t")).trimResults().omitEmptyStrings();
    }

   
Creates memory information with arbitrary keys.

Parameters:
registerKeys The names of the keys for which gauges are created.
Throws:
java.io.IOException If memory information is unavailable.
 
    public MemoryInfo(final Collection<StringregisterKeysthrows IOException {
 
       File meminfoFile = new File(.);
       if(!meminfoFile.exists()) {
          throw new IOException("The '" + . + "' does not exist");
       }
      ImmutableMap.Builder<StringMetricbuilder = ImmutableMap.builder();
      for(final String key : registerKeys) {
         builder.put(filterKey(key), new Gauge<Long>() {
            public Long getValue() {
               Long val = ..get(key);
               return val != null ? val : 0L;
            }
         });
      }
      this. = builder.build();
   }
   private String filterKey(final String key) {
      return key.toLowerCase();
   }
   public void run() {
      this. = new CurrentMemValues();
   }

   
Gets the current values.

Returns:
The values.
   public CurrentMemValues values() {
      return new CurrentMemValues();
   }
   public Map<StringMetricgetMetrics() {
      return ;
   }
   private final ImmutableMap<StringMetricmetrics;
   private volatile CurrentMemValues currValues = new CurrentMemValues();
New to GrepCode? Check out our FAQ X