Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #85: Added new metrics system.uptime #86

Merged

Conversation

MohammedSentry
Copy link
Contributor

The system_uptime metric provides the timestamp of the system's last boot. This metric is crucial for monitoring the system's uptime by offering the exact time at which the system was last restarted. Additionally, this metric includes labels that provide detailed information about the operating system.

Labels:

  • name: The name of the operating system (e.g., "Debian GNU/Linux", "Microsoft Windows Server 2019 Standard")
  • os_version: The version of the operating system (e.g., "6.1.0-18-amd64", "10.0.17763").
  • version: The detailed version or release name of the OS (e.g., "12 (bookworm)", "17763").
  • Value: The metric value is a timestamp representing the last boot time of the system, formatted in Unix epoch time.

@MohammedSentry MohammedSentry linked an issue Jun 24, 2024 that may be closed by this pull request
@NassimBtk NassimBtk changed the title Added new metrics system.uptime Issue #85: Added new metrics system.uptime Jun 24, 2024
Copy link
Member

@bertysentry bertysentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it's not easy to add this kind of information in a robust way on these connectors ;-)

osInformation:
type: commandLine
commandLine: |
os_info=$(cat /etc/os-release | grep -E '^(NAME|VERSION="[0-9].*")' | tr -d '"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually more efficient and robust to "execute" /etc/os-release and then echo the required env variables. The below script will achieve the same result with much less processes:

. /etc/os-release
echo "$NAME;$VERSION;`uname -r`"

kernel_version=$(cat /proc/version | awk '{print $3}')
echo "$os_info; $kernel_version"
computes:
- type: awk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This compute step is unnecessary.

version: $2
os_version: $3
metrics:
system.uptime: ${source::uptime}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgl! @NassimBtk Is this even supported? 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @bertysentry, I totally forgot we support that 🤦‍♂️, it will avoid unnecessary joins.

# Uptime (timestamp)
uptime:
type: commandLine
commandLine: expr $(date +%s) - $(awk '{print int($1)}' /proc/uptime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uptime is supposed to be the number of seconds since last boot, which is what we have in /proc/uptime (logically). You don't need to do all this logic, and you don't even need this uptime source.

Let's merge everything in 1 script:

      sources:
        osInformation:
          type: commandLine
          commandLine: |
            . /etc/os-release
            echo "$NAME;$VERSION;`uname -r`;`cut -d. -f1 /proc/uptime`"
      mapping:
        source: ${source::osInformation}
        attributes:
          id: $3
          name: $1
          version: $2
          os_version: $3
        metrics:
          system.uptime: $4

unit: By
system.uptime:
description: Timestamp of the system's last startup.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, uptime is the time elapsed since last boot.

uptime:
type: wmi
namespace: root\CIMv2
query: SELECT LastBootUpTime FROM Win32_OperatingSystem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SELECT SystemUpTime FROM Win32_PerfFormattedData_PerfOS_System to get the system uptime (and not the date of the last reboot).

namespace: root\CIMv2
query: SELECT SystemUpTime FROM Win32_PerfFormattedData_PerfOS_System
mapping:
source: ${source::osInformation}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I think it would be safer to make a table join on osInformation and uptime, because mapping is supposed to you 1 resulting source. Using system.uptime: ${source::uptime} works just by chance 😅

@NassimBtk NassimBtk merged commit b7b93ee into main Jul 8, 2024
1 check passed
@NassimBtk NassimBtk deleted the 85-add-os-information-to-linux-and-windows-connectors branch July 8, 2024 09:01
@NathalieLe NathalieLe added this to the 1.0.05 milestone Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add OS information to Linux and Windows connectors
4 participants