# Copyright (C) 2015-2021 Swift Navigation Inc.
# Contact: https://support.swiftnav.com
#
# This source is subject to the license found in the file 'LICENSE' which must
# be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

package: swiftnav.sbp.linux
description: >
  Linux state monitoring.

stable: False
public: False

include:
  - types.yaml

definitions:

 - MSG_LINUX_CPU_STATE_DEP_A:
    id: 0x7F00
    short_desc: Deprecated
    desc: Deprecated.
    public: false
    replaced_by:
      - MSG_LINUX_CPU_STATE
    fields:
      - index:
          type: u8
          desc: sequence of this status message, values from 0-9
      - pid:
          type: u16
          desc: the PID of the process
      - pcpu:
          type: u8
          desc: percent of cpu used, expressed as a fraction of 256
      - tname:
          type: string
          size: 15
          desc: fixed length string representing the thread name
      - cmdline:
          type: string
          encoding: unterminated
          desc: the command line (as much as it fits in the remaining packet)

 - MSG_LINUX_MEM_STATE_DEP_A:
    id: 0x7F01
    short_desc: Deprecated
    desc: Deprecated.
    public: false
    replaced_by:
      - MSG_LINUX_MEM_STATE
    fields:
      - index:
          type: u8
          desc: sequence of this status message, values from 0-9
      - pid:
          type: u16
          desc: the PID of the process
      - pmem:
          type: u8
          desc: percent of memory used, expressed as a fraction of 256
      - tname:
          type: string
          size: 15
          desc: fixed length string representing the thread name
      - cmdline:
          type: string
          encoding: unterminated
          desc: the command line (as much as it fits in the remaining packet)

 - MSG_LINUX_SYS_STATE_DEP_A:
    id: 0x7F02
    short_desc: Deprecated
    desc: Deprecated.
    public: false
    replaced_by:
      - MSG_LINUX_SYS_STATE
    fields:
      - mem_total:
          type: u16
          desc: total system memory
      - pcpu:
          type: u8
          desc: percent of total cpu currently utilized
      - pmem:
          type: u8
          desc: percent of total memory currently utilized
      - procs_starting:
          type: u16
          desc: number of processes that started during collection phase
      - procs_stopping:
          type: u16
          desc: number of processes that stopped during collection phase
      - pid_count:
          type: u16
          desc: the count of processes on the system

 - MSG_LINUX_PROCESS_SOCKET_COUNTS:
    id: 0x7F03
    public: false
    short_desc: A list of processes with high socket counts
    desc: >
      Top 10 list of processes with high socket counts.
    fields:
      - index:
          type: u8
          desc: sequence of this status message, values from 0-9
      - pid:
          type: u16
          desc: the PID of the process in question
      - socket_count:
          type: u16
          desc: the number of sockets the process is using
      - socket_types:
         type: u16
         desc: >
           A bitfield indicating the socket types used:
           0x1 (tcp), 0x2 (udp), 0x4 (unix stream), 0x8 (unix dgram), 0x10 (netlink),
           and 0x8000 (unknown)
      - socket_states:
         type: u16
         desc: >
           A bitfield indicating the socket states:
           0x1 (established), 0x2 (syn-sent), 0x4 (syn-recv), 0x8 (fin-wait-1),
           0x10 (fin-wait-2), 0x20 (time-wait), 0x40 (closed), 0x80 (close-wait),
           0x100 (last-ack), 0x200 (listen), 0x400 (closing), 0x800 (unconnected),
           and 0x8000 (unknown)
      - cmdline:
          type: string
          encoding: unterminated
          desc: the command line of the process in question

 - MSG_LINUX_PROCESS_SOCKET_QUEUES:
    id: 0x7F04
    public: false
    short_desc: A list of processes with deep socket queues
    desc: >
      Top 10 list of sockets with deep queues.
    fields:
      - index:
          type: u8
          desc: sequence of this status message, values from 0-9
      - pid:
          type: u16
          desc: the PID of the process in question
      - recv_queued:
          type: u16
          desc: the total amount of receive data queued for this process
      - send_queued:
          type: u16
          desc: the total amount of send data queued for this process
      - socket_types:
         type: u16
         desc: >
           A bitfield indicating the socket types used:
           0x1 (tcp), 0x2 (udp), 0x4 (unix stream), 0x8 (unix dgram), 0x10 (netlink),
           and 0x8000 (unknown)
      - socket_states:
         type: u16
         desc: >
           A bitfield indicating the socket states:
           0x1 (established), 0x2 (syn-sent), 0x4 (syn-recv), 0x8 (fin-wait-1),
           0x10 (fin-wait-2), 0x20 (time-wait), 0x40 (closed), 0x80 (close-wait),
           0x100 (last-ack), 0x200 (listen), 0x400 (closing), 0x800 (unconnected),
           and 0x8000 (unknown)
      - address_of_largest:
          type: string
          size: 64
          desc: >
             Address of the largest queue, remote or local depending on the directionality
             of the connection.
      - cmdline:
          type: string
          encoding: unterminated
          desc: the command line of the process in question

 - MSG_LINUX_SOCKET_USAGE:
    id: 0x7F05
    public: false
    short_desc: Summary of socket usage across the system
    desc: >
      Summaries the socket usage across the system.
    fields:
      - avg_queue_depth:
          type: u32
          desc: average socket queue depths across all sockets on the system
      - max_queue_depth:
          type: u32
          desc: the max queue depth seen within the reporting period
      - socket_state_counts:
          type: array
          size: 16
          fill: u16
          desc: >
            A count for each socket type reported in the `socket_types_reported` field,
            the first entry corresponds to the first enabled bit in `types_reported`.
      - socket_type_counts:
          type: array
          size: 16
          fill: u16
          desc: >
            A count for each socket type reported in the `socket_types_reported` field,
            the first entry corresponds to the first enabled bit in `types_reported`.

 - MSG_LINUX_PROCESS_FD_COUNT:
    id: 0x7F06
    public: false
    short_desc: Summary of processes with large amounts of open file descriptors
    desc: >
      Top 10 list of processes with a large number of open file descriptors.
    fields:
      - index:
          type: u8
          desc: sequence of this status message, values from 0-9
      - pid:
          type: u16
          desc: the PID of the process in question
      - fd_count:
          type: u16
          desc: a count of the number of file descriptors opened by the process
      - cmdline:
          type: string
          encoding: unterminated
          desc: the command line of the process in question

 - MSG_LINUX_PROCESS_FD_SUMMARY:
    id: 0x7F07
    public: false
    short_desc: Summary of open file descriptors on the system
    desc: >
      Summary of open file descriptors on the system.
    fields:
      - sys_fd_count:
          type: u32
          desc: count of total FDs open on the system
      - most_opened:
          type: string
          encoding: double_null_terminated
          desc: >
             A null delimited list of strings which alternates between
             a string representation of the process count and the file
             name whose count it being reported.  That is, in C string
             syntax "32\0/var/log/syslog\012\0/tmp/foo\0" with the end
             of the list being 2 NULL terminators in a row.

 - MSG_LINUX_CPU_STATE:
     id: 0x7F08
     short_desc: List CPU state on the system
     public: false
     desc: >
       This message indicates the process state of the top 10 heaviest
       consumers of CPU on the system, including a timestamp.
     fields:
       - index:
           type: u8
           desc: sequence of this status message, values from 0-9
       - pid:
           type: u16
           desc: the PID of the process
       - pcpu:
           type: u8
           desc: percent of CPU used, expressed as a fraction of 256
       - time:
           type: u32
           desc: timestamp of message, refer to flags field for how to interpret
       - flags:
           type: u8
           desc: flags
           fields:
             - 0-2:
                 desc: timestamp type
                 values:
                   - 0: System time in seconds
                   - 1: GPS TOW in milliseconds
       - tname:
           type: string
           size: 15
           desc: fixed length string representing the thread name
       - cmdline:
           type: string
           encoding: unterminated
           desc: the command line (as much as it fits in the remaining packet)


 - MSG_LINUX_MEM_STATE:
     id: 0x7F09
     short_desc: List memory state on the system
     public: false
     desc: >
       This message indicates the process state of the top 10 heaviest
       consumers of memory on the system, including a timestamp.
     fields:
       - index:
           type: u8
           desc: sequence of this status message, values from 0-9
       - pid:
           type: u16
           desc: the PID of the process
       - pmem:
           type: u8
           desc: percent of memory used, expressed as a fraction of 256
       - time:
           type: u32
           desc: timestamp of message, refer to flags field for how to interpret
       - flags:
           type: u8
           desc: flags
           fields:
             - 0-2:
                 desc: timestamp type
                 values:
                   - 0: System time in seconds
                   - 1: GPS TOW in milliseconds
       - tname:
           type: string
           size: 15
           desc: fixed length string representing the thread name
       - cmdline:
           type: string
           encoding: unterminated
           desc: the command line (as much as it fits in the remaining packet)

 - MSG_LINUX_SYS_STATE:
     id: 0x7F0A
     public: false
     short_desc: CPU, Memory and Process Starts/Stops
     desc: >
       This presents a summary of CPU and memory utilization, including a timestamp.
     fields:
       - mem_total:
           type: u16
           desc: total system memory, in MiB
       - pcpu:
           type: u8
           desc: percent of CPU used, expressed as a fraction of 256
       - pmem:
           type: u8
           desc: percent of memory used, expressed as a fraction of 256
       - procs_starting:
           type: u16
           desc: number of processes that started during collection phase
       - procs_stopping:
           type: u16
           desc: number of processes that stopped during collection phase
       - pid_count:
           type: u16
           desc: the count of processes on the system
       - time:
           type: u32
           desc: timestamp of message, refer to flags field for how to interpret
       - flags:
           type: u8
           desc: flags
           fields:
             - 0-2:
                 desc: timestamp type
                 values:
                   - 0: System time in seconds
                   - 1: GPS TOW in milliseconds
