1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6import common
7from autotest_lib.client.common_lib.cros.graphite import autotest_stats
8from autotest_lib.site_utils.lib import infra
9from autotest_lib.site_utils.stats import registry
10
11
12@registry.loop_stat('sam')
13def time_wait(server):
14    """
15    Submits a stat for the number of TIME_WAIT sockets that are on the server.
16
17    @param server: The AFE server.
18    """
19    out = infra.execute_command(server, 'ss -o state time-wait | wc -l')
20    stat = autotest_stats.Gauge(server, bare=True)
21    # ss prints out a header for the columns also, so we subtract one to report
22    # about only the data.
23    stat.send('time_wait_sockets', int(out.strip())-1)
24
25