From 12f725e04c4e958b8a3e32526f6501d66458c0bf Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 24 Dec 2023 19:10:50 -0500 Subject: [PATCH 1/4] Added Linux Connector to Community repository - Developed Linux Connector - Added system.yaml for common grounds with other potential system connectors --- src/main/connector/system/Linux/Linux.yaml | 237 +++++++++++++++++++ src/main/connector/system/System/System.yaml | 39 +++ 2 files changed, 276 insertions(+) create mode 100644 src/main/connector/system/Linux/Linux.yaml create mode 100644 src/main/connector/system/System/System.yaml diff --git a/src/main/connector/system/Linux/Linux.yaml b/src/main/connector/system/Linux/Linux.yaml new file mode 100644 index 0000000..6048a8b --- /dev/null +++ b/src/main/connector/system/Linux/Linux.yaml @@ -0,0 +1,237 @@ +extends: +- ../System/System +connector: + displayName: "LinuxOS" + platform: "Any platform with LinuxOS" + reliesOn: "Linux OsCommands" + information: "Gives OS specific information and metrics" + detection: + connectionTypes: + - remote + - local + appliesTo: + - "linux" + criteria: + - type: osCommand + commandLine: "/usr/bin/uname -o" + expectedResult: "GNU/Linux" + errorMessage: "Not a valid Linux host." +monitors: + cpu: + discovery: + sources: + source(1): + # cpuId + type: osCommand + commandLine: /usr/bin/sar -P ALL 5 1 + computes: + - type: awk + script: "/Average: +[0-9]/ {print $2}" + mapping: + source: ${source::monitors.cpu.discovery.sources.source(1)} + attributes: + id: $1 + name: ${awk::sprintf("%s %s", "cpu", $1)} + system.cpu.logical_number: $1 + collect: + type: multiInstance + sources: + source(1): + # cpuId;%user;%nice;%system;%ioWait;%steal;%idle + type: osCommand + commandLine: /usr/bin/sar -P ALL 5 1 + computes: + - type: awk + script: '/Average: +[0-9]/ {print $2 ";" $3 / 100";" $4 / 100";" $5 / 100";" $6 / 100 ";" $7 / 100 ";" $8 / 100}' + source(2): + # cpuId;user;nice;system;idle;iowait + type: osCommand + commandLine: /usr/bin/cat /proc/stat + computes: + - type: awk + script: /cpu[0-9]/ {sub("cpu",""); print $1 ";" $2 / 1000 ";" $3 / 1000 ";" $4 / 1000 ";" $5 / 1000 ";" $6 / 1000} + source(3): + # cpuId;%user;%nice;%system;%ioWait;%steal;%idle;cpuId;user;nice;system;idle;iowait + type: tableJoin + leftTable: ${source::monitors.cpu.collect.sources.source(1)} + leftKeyColumn: 1 + rightTable: ${source::monitors.cpu.collect.sources.source(2)} + rightKeyColumn: 1 + mapping: + source: "${source::monitors.cpu.collect.sources.source(3)}" + attributes: + id: $1 + metrics: + system.cpu.utilization{system.cpu.state="user"}: $2 + system.cpu.utilization{system.cpu.state="nice"}: $3 + system.cpu.utilization{system.cpu.state="system"}: $4 + system.cpu.utilization{system.cpu.state="io_wait"}: $5 + system.cpu.utilization{system.cpu.state="steal"}: $6 + system.cpu.utilization{system.cpu.state="idle"}: $7 + system.cpu.time{system.cpu.state="user"}: $9 + system.cpu.time{system.cpu.state="nice"}: $10 + system.cpu.time{system.cpu.state="system"}: $11 + system.cpu.time{system.cpu.state="idle"}: $12 + system.cpu.time{system.cpu.state="io_wait"}: $13 + memory: + discovery: + sources: + source(1): + # totalMemory + type: osCommand + commandLine: free + computes: + - type: awk + script: /Mem:/ {print $2 * 1024} + mapping: + source: ${source::monitors.memory.discovery.sources.source(1)} + attributes: + id: memory_usage + system.memory.limit: $1 + collect: + type: multiInstance + sources: + source(1): + # memFree;memUsed;buffers;cached;commit;%commit + type: osCommand + commandLine: /usr/bin/sar -r 5 1 + computes: + - type: awk + script: /Average/ {print $2 * 1024 ";" $3 * 1024 ";" $5 * 1024 ";" $6 * 1024 ";" $7 * 1024 ";" $9 ";" $10 ";" $11} + mapping: + source: "${source::monitors.memory.collect.sources.source(1)}" + attributes: + id: memory_usage + metrics: + system.memory.usage{system.memory.usage="free"}: $1 + system.memory.usage{system.memory.usage="used"}: $2 + system.memory.usage{system.memory.usage="buffers"}: $3 + system.memory.usage{system.memory.usage="cached"}: $4 + system.memory.usage{system.memory.usage="commit"}: $5 + system.memory.usage{system.memory.usage="active"}: $6 + system.memory.usage{system.memory.usage="inactive"}: $7 + system.memory.usage{system.memory.usage="dirty"}: $8 + disk: + discovery: + sources: + source(1): + # id + type: osCommand + commandLine: /usr/bin/sar -d 5 1 + computes: + - type: awk + script: '/Average/ && /[0-9]/ {print $2}' + mapping: + source: "${source::monitors.disk.discovery.sources.source(1)}" + attributes: + id: $1 + collect: + type: multiInstance + sources: + source(1): + # id;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util + type: osCommand + commandLine: /usr/bin/sar -d 5 1 + computes: + - type: awk + script: '/Average/ && /[0-9]/ {print $2 ";" $3 ";" $4 ";" $5 ";" $6 ";" $7 ";" $8 ";" $9 ";" $10}' + mapping: + source: "${source::monitors.disk.collect.sources.source(1)}" + attributes: + id: $1 + system.disk.device: $1 + metrics: + system.disk.io_transactions_per_seconds: $2 + system.disk.operations{direction:read}: $3 + system.disk.operations{direction:write}: $4 + system.disk.io_average_size: $5 + system.disk.io_average_queue: $6 + system.disk.io_average_wait: $7 + system.disk.io_time: $8 + service: + discovery: + sources: + source(1): + # id + type: osCommand + commandLine: systemctl list-units --type=service --all + computes: + - type: awk + script: /\.service/ {sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", ""); printf $1 ";"; for (i=5; i<=NF; i++) printf "%s ", $i; printf "\n"} + mapping: + source: "${source::monitors.service.discovery.sources.source(1)}" + attributes: + id: $1 + description: $2 + collect: + type: multiInstance + sources: + source(1): + # serviceName;load;active;sub + type: osCommand + commandLine: systemctl list-units --type=service --all + computes: + - type: awk + script: /\.service/ {sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", "");print $1 ";" $2 ";" $3 ";" $4} + mapping: + source: "${source::monitors.service.collect.sources.source(1)}" + attributes: + id: $1 + metrics: + system.service.loaded: $2 + system.service.active: $3 + system.service.sub: $4 + filesystem: + discovery: + sources: + source(1): + # filesystem;mountpoint;type + type: osCommand + commandLine: df --output=source,target,fstype + computes: + - type: awk + script: 'NR > 1 {print $1 "(" $2 ")" ";" $2 ";" $3}' + mapping: + source: "${source::monitors.filesystem.discovery.sources.source(1)}" + attributes: + id: $1 + system.filesystem.device: $1 + system.filesystem.mountpoint: $2 + system.filesystem.type: $3 + collect: + type: multiInstance + sources: + source(1): + # filesystem;used;available + type: osCommand + commandLine: df -B1 --output=source,target,used,avail + computes: + - type: awk + script: 'NR > 1 {print $1 "(" $2 ")" ";" $3 ";" $4}' + mapping: + source: "${source::monitors.filesystem.collect.sources.source(1)}" + attributes: + id: $1 + metrics: + system.filesystem.usage{system.filesystem.state=used}: $2 + system.filesystem.usage{system.filesystem.state=free}: $3 +metrics: + system.service.loaded: + description: Service Loaded State + type: + stateSet: + - loaded + - not-found + system.service.active: + description: Service Active State + type: + stateSet: + - active + - inactive + system.service.sub: + description: Service Sub State + type: + stateSet: + - running + - dead + - exited \ No newline at end of file diff --git a/src/main/connector/system/System/System.yaml b/src/main/connector/system/System/System.yaml new file mode 100644 index 0000000..d04a919 --- /dev/null +++ b/src/main/connector/system/System/System.yaml @@ -0,0 +1,39 @@ +metrics: + system.cpu.utilization: + description: 'CPU utilization for each possible state.' + type: Gauge + unit: "1" + system.cpu.time: + description: 'Total CPU time spent for each possible state.' + type: Counter + unit: s + system.disk.io_transactions_per_seconds: + description: 'Disk transactions per seconds.' + type: Gauge + unit: tps + system.disk.io_average_size: + description: 'Average size in sectors of requests.' + type: Gauge + unit: "{sectors}" + system.disk.io_average_queue: + description: 'Average number of requests in the queue waiting to be served.' + type: Gauge + unit: "{requests}" + system.disk.io_average_wait: + description: 'Average time taken for I/O requests to be served.' + type: Gauge + unit: s + system.disk.io_time: + description: 'Average time taken to complete I/O requests.' + type: Gauge + unit: s + system.filesystem.usage: + description: 'File System usage for each possible state.' + type: Gauge + unit: By + system.memory.usage: + description: 'Memory utilization for each possible state.' + type: Gauge + unit: By + + \ No newline at end of file From dc793cc3affa7a226e0b99b783825cf63d1057ff Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 8 Jan 2024 01:23:41 -0500 Subject: [PATCH 2/4] Code review changes - Usage of /proc/ tools instead of sar - Usage of simple job instead of discovery/collect - Added an embedded file for memory awk compute --- src/main/connector/system/Linux/Linux.yaml | 223 ++++++------------- src/main/connector/system/Linux/memory.awk | 5 + src/main/connector/system/System/System.yaml | 120 ++++++++-- 3 files changed, 179 insertions(+), 169 deletions(-) create mode 100644 src/main/connector/system/Linux/memory.awk diff --git a/src/main/connector/system/Linux/Linux.yaml b/src/main/connector/system/Linux/Linux.yaml index 6048a8b..82b15e1 100644 --- a/src/main/connector/system/Linux/Linux.yaml +++ b/src/main/connector/system/Linux/Linux.yaml @@ -1,5 +1,25 @@ extends: - ../System/System +metrics: + system.service.loaded: + description: Service Loaded State + type: + stateSet: + - loaded + - not-found + system.service.active: + description: Service Active State + type: + stateSet: + - active + - inactive + system.service.sub: + description: Service Sub State + type: + stateSet: + - running + - dead + - exited connector: displayName: "LinuxOS" platform: "Any platform with LinuxOS" @@ -18,220 +38,119 @@ connector: errorMessage: "Not a valid Linux host." monitors: cpu: - discovery: - sources: - source(1): - # cpuId - type: osCommand - commandLine: /usr/bin/sar -P ALL 5 1 - computes: - - type: awk - script: "/Average: +[0-9]/ {print $2}" - mapping: - source: ${source::monitors.cpu.discovery.sources.source(1)} - attributes: - id: $1 - name: ${awk::sprintf("%s %s", "cpu", $1)} - system.cpu.logical_number: $1 - collect: + simple: type: multiInstance sources: source(1): - # cpuId;%user;%nice;%system;%ioWait;%steal;%idle - type: osCommand - commandLine: /usr/bin/sar -P ALL 5 1 - computes: - - type: awk - script: '/Average: +[0-9]/ {print $2 ";" $3 / 100";" $4 / 100";" $5 / 100";" $6 / 100 ";" $7 / 100 ";" $8 / 100}' - source(2): # cpuId;user;nice;system;idle;iowait type: osCommand commandLine: /usr/bin/cat /proc/stat computes: - type: awk script: /cpu[0-9]/ {sub("cpu",""); print $1 ";" $2 / 1000 ";" $3 / 1000 ";" $4 / 1000 ";" $5 / 1000 ";" $6 / 1000} - source(3): - # cpuId;%user;%nice;%system;%ioWait;%steal;%idle;cpuId;user;nice;system;idle;iowait - type: tableJoin - leftTable: ${source::monitors.cpu.collect.sources.source(1)} - leftKeyColumn: 1 - rightTable: ${source::monitors.cpu.collect.sources.source(2)} - rightKeyColumn: 1 mapping: - source: "${source::monitors.cpu.collect.sources.source(3)}" + source: "${source::monitors.cpu.simple.sources.source(1)}" attributes: id: $1 + name: ${awk::sprintf("%s %s", "cpu", $1)} + system.cpu.logical_number: $1 metrics: - system.cpu.utilization{system.cpu.state="user"}: $2 - system.cpu.utilization{system.cpu.state="nice"}: $3 - system.cpu.utilization{system.cpu.state="system"}: $4 - system.cpu.utilization{system.cpu.state="io_wait"}: $5 - system.cpu.utilization{system.cpu.state="steal"}: $6 - system.cpu.utilization{system.cpu.state="idle"}: $7 - system.cpu.time{system.cpu.state="user"}: $9 - system.cpu.time{system.cpu.state="nice"}: $10 - system.cpu.time{system.cpu.state="system"}: $11 - system.cpu.time{system.cpu.state="idle"}: $12 - system.cpu.time{system.cpu.state="io_wait"}: $13 + system.cpu.utilization{system.cpu.state="user"}: rate($2) + system.cpu.utilization{system.cpu.state="nice"}: rate($3) + system.cpu.utilization{system.cpu.state="system"}: rate($4) + system.cpu.utilization{system.cpu.state="idle"}: rate($5) + system.cpu.utilization{system.cpu.state="io_wait"}: rate($6) + system.cpu.time{system.cpu.state="user"}: $2 + system.cpu.time{system.cpu.state="nice"}: $3 + system.cpu.time{system.cpu.state="system"}: $4 + system.cpu.time{system.cpu.state="idle"}: $5 + system.cpu.time{system.cpu.state="io_wait"}: $6 memory: - discovery: + simple: sources: source(1): - # totalMemory + # memTotal;memFree;memUsed;memBuffers;memCached;memFreeUtilization;memUsedUtilization;memBuffersUtilization;memCachedUtilization type: osCommand - commandLine: free + commandLine: cat /proc/meminfo computes: - type: awk - script: /Mem:/ {print $2 * 1024} + script: "${file::memory.awk}" mapping: - source: ${source::monitors.memory.discovery.sources.source(1)} + source: "${source::monitors.memory.simple.sources.source(1)}" attributes: id: memory_usage system.memory.limit: $1 - collect: - type: multiInstance - sources: - source(1): - # memFree;memUsed;buffers;cached;commit;%commit - type: osCommand - commandLine: /usr/bin/sar -r 5 1 - computes: - - type: awk - script: /Average/ {print $2 * 1024 ";" $3 * 1024 ";" $5 * 1024 ";" $6 * 1024 ";" $7 * 1024 ";" $9 ";" $10 ";" $11} - mapping: - source: "${source::monitors.memory.collect.sources.source(1)}" - attributes: - id: memory_usage metrics: - system.memory.usage{system.memory.usage="free"}: $1 - system.memory.usage{system.memory.usage="used"}: $2 - system.memory.usage{system.memory.usage="buffers"}: $3 - system.memory.usage{system.memory.usage="cached"}: $4 - system.memory.usage{system.memory.usage="commit"}: $5 - system.memory.usage{system.memory.usage="active"}: $6 - system.memory.usage{system.memory.usage="inactive"}: $7 - system.memory.usage{system.memory.usage="dirty"}: $8 + system.memory.usage{system.memory.usage="free"}: $2 + system.memory.usage{system.memory.usage="used"}: $3 + system.memory.usage{system.memory.usage="buffers"}: $4 + system.memory.usage{system.memory.usage="cached"}: $5 + system.memory.utilization{system.memory.usage="free"}: $6 + system.memory.utilization{system.memory.usage="used"}: $7 + system.memory.utilization{system.memory.usage="buffers"}: $8 + system.memory.utilization{system.memory.usage="cached"}: $9 disk: - discovery: - sources: - source(1): - # id - type: osCommand - commandLine: /usr/bin/sar -d 5 1 - computes: - - type: awk - script: '/Average/ && /[0-9]/ {print $2}' - mapping: - source: "${source::monitors.disk.discovery.sources.source(1)}" - attributes: - id: $1 - collect: + simple: type: multiInstance sources: source(1): - # id;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util + # id;reads;readsMerged;readTime;writes;writesMerged;writeTime;ioTime type: osCommand - commandLine: /usr/bin/sar -d 5 1 + commandLine: cat /proc/diskstats computes: - type: awk - script: '/Average/ && /[0-9]/ {print $2 ";" $3 ";" $4 ";" $5 ";" $6 ";" $7 ";" $8 ";" $9 ";" $10}' + script: '{print $3 ";" $4 ";" $5 ";" $7 / 1000 ";" $8 ";" $9 ";" $11 / 1000 ";" $13 / 1000}' mapping: - source: "${source::monitors.disk.collect.sources.source(1)}" + source: "${source::monitors.disk.simple.sources.source(1)}" attributes: id: $1 system.disk.device: $1 metrics: - system.disk.io_transactions_per_seconds: $2 - system.disk.operations{direction:read}: $3 - system.disk.operations{direction:write}: $4 - system.disk.io_average_size: $5 - system.disk.io_average_queue: $6 - system.disk.io_average_wait: $7 + system.disk.operations{direction:read}: $2 + system.disk.merged{direction:read}: $3 + system.disk.operation_time{direction:read}: $4 + system.disk.operations{direction:write}: $5 + system.disk.merged{direction:write}: $6 + system.disk.operation_time{direction:write}: $7 system.disk.io_time: $8 service: - discovery: - sources: - source(1): - # id - type: osCommand - commandLine: systemctl list-units --type=service --all - computes: - - type: awk - script: /\.service/ {sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", ""); printf $1 ";"; for (i=5; i<=NF; i++) printf "%s ", $i; printf "\n"} - mapping: - source: "${source::monitors.service.discovery.sources.source(1)}" - attributes: - id: $1 - description: $2 - collect: + simple: type: multiInstance sources: source(1): - # serviceName;load;active;sub + # serviceName;load;active;sub;description type: osCommand commandLine: systemctl list-units --type=service --all computes: - type: awk - script: /\.service/ {sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", "");print $1 ";" $2 ";" $3 ";" $4} + script: /\.service/ {sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", ""); printf $1 ";" $2 ";" $3 ";" $4 ";"; for (i=5; i<=NF; i++) printf "%s ", $i; printf "\n"} mapping: - source: "${source::monitors.service.collect.sources.source(1)}" + source: "${source::monitors.service.simple.sources.source(1)}" attributes: id: $1 + description: $5 metrics: system.service.loaded: $2 system.service.active: $3 system.service.sub: $4 filesystem: - discovery: + simple: + type: multiInstance sources: source(1): - # filesystem;mountpoint;type + # filesystem;mountpoint;type;used;available type: osCommand - commandLine: df --output=source,target,fstype + commandLine: /usr/bin/df -B1 --output=source,target,fstype,used,avail computes: - type: awk - script: 'NR > 1 {print $1 "(" $2 ")" ";" $2 ";" $3}' + script: 'NR > 1 {print $1 "(" $2 ")" ";" $2 ";" $3 ";" $4 ";" $5}' mapping: - source: "${source::monitors.filesystem.discovery.sources.source(1)}" + source: "${source::monitors.filesystem.simple.sources.source(1)}" attributes: id: $1 system.filesystem.device: $1 system.filesystem.mountpoint: $2 system.filesystem.type: $3 - collect: - type: multiInstance - sources: - source(1): - # filesystem;used;available - type: osCommand - commandLine: df -B1 --output=source,target,used,avail - computes: - - type: awk - script: 'NR > 1 {print $1 "(" $2 ")" ";" $3 ";" $4}' - mapping: - source: "${source::monitors.filesystem.collect.sources.source(1)}" - attributes: - id: $1 metrics: - system.filesystem.usage{system.filesystem.state=used}: $2 - system.filesystem.usage{system.filesystem.state=free}: $3 -metrics: - system.service.loaded: - description: Service Loaded State - type: - stateSet: - - loaded - - not-found - system.service.active: - description: Service Active State - type: - stateSet: - - active - - inactive - system.service.sub: - description: Service Sub State - type: - stateSet: - - running - - dead - - exited \ No newline at end of file + system.filesystem.usage{system.filesystem.state=used}: $4 + system.filesystem.usage{system.filesystem.state=free}: $5 \ No newline at end of file diff --git a/src/main/connector/system/Linux/memory.awk b/src/main/connector/system/Linux/memory.awk new file mode 100644 index 0000000..0031fa5 --- /dev/null +++ b/src/main/connector/system/Linux/memory.awk @@ -0,0 +1,5 @@ +/MemTotal/ {memTotal = ($2 * 1024)} +/MemFree/ {memFree = ($2 * 1024); memFreeUtilization = (memFree / memTotal); memUsed = (memTotal - memFree); memUsedUtilization = (memUsed / memTotal)} +/Buffers/ {memBuffers = ($2 * 1024); memBuffersUtilization = (memBuffers / memTotal)} +/Cached/ {memCached = ($2 * 1024); memCachedUtilization = (memCached / memTotal)} +END {printf("%s;%s;%s;%s;%s;%s;%s;%s;%s\n", memTotal, memFree, memUsed, memBuffers, memCached, memFreeUtilization, memUsedUtilization, memBuffersUtilization, memCachedUtilization)} \ No newline at end of file diff --git a/src/main/connector/system/System/System.yaml b/src/main/connector/system/System/System.yaml index d04a919..59d954c 100644 --- a/src/main/connector/system/System/System.yaml +++ b/src/main/connector/system/System/System.yaml @@ -1,39 +1,125 @@ metrics: + system.cpu.time: + description: Seconds each logical CPU spent on each mode + type: Counter + unit: s system.cpu.utilization: - description: 'CPU utilization for each possible state.' + description: Difference in system.cpu.time since the last measurement, divided by the elapsed time and number of logical CPUs type: Gauge unit: "1" - system.cpu.time: - description: 'Total CPU time spent for each possible state.' + system.cpu.physical.count: + description: Reports the number of actual physical processor cores on the hardware + type: UpDownCounter + unit: "{cpu}" + system.cpu.logical.count: + description: Reports the number of logical (virtual) processor cores created by the operating system to manage multitasking + type: UpDownCounter + unit: "{cpu}" + system.cpu.frequency: + description: Reports the current frequency of the CPU in Hz + type: Gauge + unit: "{Hz}" + system.memory.usage: + description: Reports memory in use by state + type: UpDownCounter + unit: By + system.memory.limit: + description: Total memory available in the system + type: UpDownCounter + unit: By + system.memory.utilization: + description: Memory utilization for each possible state + type: Gauge + unit: "1" + system.paging.usage: + description: Unix swap or Windows pagefile usage + type: UpDownCounter + unit: By + system.paging.utilization: + description: Memory paging utilization for each possible state + type: Gauge + unit: "1" + system.paging.faults: + description: Count of major and minor page faults + type: Counter + unit: "{fault}" + system.paging.operations: + description: Count of page-in (swap-in) and page-out (swap-out) operations + type: Counter + unit: "{operation}" + system.disk.io: + description: Disk I/O count + type: Counter + unit: By + system.disk.operations: + description: Count of read and write operations + type: Counter + unit: "{operation}" + system.disk.io_time: + description: Time disk spent activated + type: Counter + unit: s + system.disk.operation_time: + description: Sum of the time each operation took to complete type: Counter unit: s + system.disk.merged: + description: Count of merged read and write operations + type: Counter + unit: "{operation}" system.disk.io_transactions_per_seconds: - description: 'Disk transactions per seconds.' + description: Disk transactions per seconds type: Gauge unit: tps system.disk.io_average_size: - description: 'Average size in sectors of requests.' + description: Average size in sectors of requests type: Gauge unit: "{sectors}" system.disk.io_average_queue: - description: 'Average number of requests in the queue waiting to be served.' + description: Average number of requests in the queue waiting to be served type: Gauge unit: "{requests}" system.disk.io_average_wait: - description: 'Average time taken for I/O requests to be served.' - type: Gauge - unit: s - system.disk.io_time: - description: 'Average time taken to complete I/O requests.' + description: Average time taken for I/O requests to be served type: Gauge unit: s system.filesystem.usage: - description: 'File System usage for each possible state.' - type: Gauge + description: Filesystem usage + type: UpDownCounter unit: By - system.memory.usage: - description: 'Memory utilization for each possible state.' + system.filesystem.utilization: + description: Filesystem utilization for each possible state type: Gauge + unit: "1" + system.network.dropped: + description: Count of dropped packets + type: Counter + unit: "{packet}" + system.network.packets: + description: Count of transmitted and received packets + type: Counter + unit: "{packet}" + system.network.errors: + description: Count of network errors detected + type: Counter + unit: "{error}" + system.network.io: + description: Network I/O count + type: Counter unit: By - - \ No newline at end of file + system.network.connections: + description: Count of network connections + type: UpDownCounter + unit: "{connection}" + system.processes.count: + description: Total number of processes in each state + type: UpDownCounter + unit: "{process}" + system.processes.created: + description: Total number of processes created over uptime of the host + type: Counter + unit: "{process}" + system.linux.memory.available: + description: An estimate of how much memory is available for starting new applications, without causing swapping + type: UpDownCounter + unit: By \ No newline at end of file From e6b96f75f846e77b2372b3c9f7402627c441fccc Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 8 Jan 2024 10:46:59 -0500 Subject: [PATCH 3/4] Code review changes - Removed superfluous quotation marks - Simplified awk scripts where possible - Formatting of code --- src/main/connector/system/Linux/Linux.yaml | 69 ++++++++++++++-------- src/main/connector/system/Linux/memory.awk | 29 +++++++-- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/main/connector/system/Linux/Linux.yaml b/src/main/connector/system/Linux/Linux.yaml index 82b15e1..5d481b7 100644 --- a/src/main/connector/system/Linux/Linux.yaml +++ b/src/main/connector/system/Linux/Linux.yaml @@ -21,21 +21,21 @@ metrics: - dead - exited connector: - displayName: "LinuxOS" - platform: "Any platform with LinuxOS" - reliesOn: "Linux OsCommands" - information: "Gives OS specific information and metrics" + displayName: LinuxOS + platform: Any platform with LinuxOS + reliesOn: Linux OsCommands + information: Gives OS specific information and metrics detection: connectionTypes: - remote - local appliesTo: - - "linux" + - linux criteria: - - type: osCommand - commandLine: "/usr/bin/uname -o" - expectedResult: "GNU/Linux" - errorMessage: "Not a valid Linux host." + - type: osCommand + commandLine: /usr/bin/uname -o + expectedResult: GNU/Linux + errorMessage: Not a valid Linux host. monitors: cpu: simple: @@ -46,10 +46,14 @@ monitors: type: osCommand commandLine: /usr/bin/cat /proc/stat computes: - - type: awk - script: /cpu[0-9]/ {sub("cpu",""); print $1 ";" $2 / 1000 ";" $3 / 1000 ";" $4 / 1000 ";" $5 / 1000 ";" $6 / 1000} + - type: awk + script: | + /cpu[0-9]/ { + sub("cpu",""); + print $1 ";" $2 / 1000 ";" $3 / 1000 ";" $4 / 1000 ";" $5 / 1000 ";" $6 / 1000 + } mapping: - source: "${source::monitors.cpu.simple.sources.source(1)}" + source: ${source::monitors.cpu.simple.sources.source(1)} attributes: id: $1 name: ${awk::sprintf("%s %s", "cpu", $1)} @@ -73,10 +77,10 @@ monitors: type: osCommand commandLine: cat /proc/meminfo computes: - - type: awk - script: "${file::memory.awk}" + - type: awk + script: ${file::memory.awk} mapping: - source: "${source::monitors.memory.simple.sources.source(1)}" + source: ${source::monitors.memory.simple.sources.source(1)} attributes: id: memory_usage system.memory.limit: $1 @@ -97,11 +101,19 @@ monitors: # id;reads;readsMerged;readTime;writes;writesMerged;writeTime;ioTime type: osCommand commandLine: cat /proc/diskstats + selectColumns: 3,4,5,7,8,9,11,13 computes: - - type: awk - script: '{print $3 ";" $4 ";" $5 ";" $7 / 1000 ";" $8 ";" $9 ";" $11 / 1000 ";" $13 / 1000}' + - type: divide + column: 2 + value: 1000 + - type: divide + column: 5 + value: 1000 + - type: divide + column: 8 + value: 1000 mapping: - source: "${source::monitors.disk.simple.sources.source(1)}" + source: ${source::monitors.disk.simple.sources.source(1)} attributes: id: $1 system.disk.device: $1 @@ -120,12 +132,17 @@ monitors: source(1): # serviceName;load;active;sub;description type: osCommand - commandLine: systemctl list-units --type=service --all + commandLine: /usr/bin/systemctl list-units --type=service --all computes: - - type: awk - script: /\.service/ {sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", ""); printf $1 ";" $2 ";" $3 ";" $4 ";"; for (i=5; i<=NF; i++) printf "%s ", $i; printf "\n"} + - type: awk + script: | + /\.service/ { + sub(/^[^[:alnum:]]+\s*/, ""); + sub("\.service", ""); + printf $1 ";" $2 ";" $3 ";" $4 ";"; for (i=5; i<=NF; i++) printf "%s ", $i; printf "\n" + } mapping: - source: "${source::monitors.service.simple.sources.source(1)}" + source: ${source::monitors.service.simple.sources.source(1)} attributes: id: $1 description: $5 @@ -141,11 +158,13 @@ monitors: # filesystem;mountpoint;type;used;available type: osCommand commandLine: /usr/bin/df -B1 --output=source,target,fstype,used,avail + separators: \t + selectColumns: 1,2,3,4,5 computes: - - type: awk - script: 'NR > 1 {print $1 "(" $2 ")" ";" $2 ";" $3 ";" $4 ";" $5}' + - type: awk + script: NR > 1 {print $1 "(" $2 ")" ";" $2 ";" $3 ";" $4 ";" $5} mapping: - source: "${source::monitors.filesystem.simple.sources.source(1)}" + source: ${source::monitors.filesystem.simple.sources.source(1)} attributes: id: $1 system.filesystem.device: $1 diff --git a/src/main/connector/system/Linux/memory.awk b/src/main/connector/system/Linux/memory.awk index 0031fa5..4f8faea 100644 --- a/src/main/connector/system/Linux/memory.awk +++ b/src/main/connector/system/Linux/memory.awk @@ -1,5 +1,24 @@ -/MemTotal/ {memTotal = ($2 * 1024)} -/MemFree/ {memFree = ($2 * 1024); memFreeUtilization = (memFree / memTotal); memUsed = (memTotal - memFree); memUsedUtilization = (memUsed / memTotal)} -/Buffers/ {memBuffers = ($2 * 1024); memBuffersUtilization = (memBuffers / memTotal)} -/Cached/ {memCached = ($2 * 1024); memCachedUtilization = (memCached / memTotal)} -END {printf("%s;%s;%s;%s;%s;%s;%s;%s;%s\n", memTotal, memFree, memUsed, memBuffers, memCached, memFreeUtilization, memUsedUtilization, memBuffersUtilization, memCachedUtilization)} \ No newline at end of file +/MemTotal/ { + memTotal = $2 * 1024 +} + +/MemFree/ { + memFree = $2 * 1024 + memFreeUtilization = memFree / memTotal + memUsed = memTotal - memFree + memUsedUtilization = memUsed / memTotal +} + +/Buffers/ { + memBuffers = $2 * 1024 + memBuffersUtilization = memBuffers / memTotal +} + +/Cached/ { + memCached = $2 * 1024 + memCachedUtilization = memCached / memTotal +} + +END { + printf("%s;%s;%s;%s;%s;%s;%s;%s;%s\n", memTotal, memFree, memUsed, memBuffers, memCached, memFreeUtilization, memUsedUtilization, memBuffersUtilization, memCachedUtilization) +} \ No newline at end of file From edce9ea4843cc8f2a90baa2f5dd17fa850966d52 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 9 Jan 2024 01:07:28 -0500 Subject: [PATCH 4/4] Code review changes - Awk formatting - Change to service states --- src/main/connector/system/Linux/Linux.yaml | 47 ++++++++++++---------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/main/connector/system/Linux/Linux.yaml b/src/main/connector/system/Linux/Linux.yaml index 5d481b7..413a820 100644 --- a/src/main/connector/system/Linux/Linux.yaml +++ b/src/main/connector/system/Linux/Linux.yaml @@ -1,20 +1,8 @@ extends: - ../System/System metrics: - system.service.loaded: - description: Service Loaded State - type: - stateSet: - - loaded - - not-found - system.service.active: - description: Service Active State - type: - stateSet: - - active - - inactive - system.service.sub: - description: Service Sub State + system.service.status: + description: Service Status type: stateSet: - running @@ -139,17 +127,27 @@ monitors: /\.service/ { sub(/^[^[:alnum:]]+\s*/, ""); sub("\.service", ""); - printf $1 ";" $2 ";" $3 ";" $4 ";"; for (i=5; i<=NF; i++) printf "%s ", $i; printf "\n" + printf($1 ";" $2 ";" $3 ";" $4 ";") + for (i=5; i<=NF; i++) { + printf("%s ", $i) + } + printf("\n") } + - type: translate + column: 2 + translationTable: ${translation::serviceLoadedTranslationTable} + - type: translate + column: 3 + translationTable: ${translation::serviceActiveTranslationTable} mapping: source: ${source::monitors.service.simple.sources.source(1)} attributes: id: $1 description: $5 metrics: - system.service.loaded: $2 - system.service.active: $3 - system.service.sub: $4 + system.service.status{state="loaded"}: $2 + system.service.status{state="active"}: $3 + system.service.status: $4 filesystem: simple: type: multiInstance @@ -157,9 +155,7 @@ monitors: source(1): # filesystem;mountpoint;type;used;available type: osCommand - commandLine: /usr/bin/df -B1 --output=source,target,fstype,used,avail - separators: \t - selectColumns: 1,2,3,4,5 + commandLine: /usr/bin/df -B1 --output=source,target,fstype,used,avail computes: - type: awk script: NR > 1 {print $1 "(" $2 ")" ";" $2 ";" $3 ";" $4 ";" $5} @@ -172,4 +168,11 @@ monitors: system.filesystem.type: $3 metrics: system.filesystem.usage{system.filesystem.state=used}: $4 - system.filesystem.usage{system.filesystem.state=free}: $5 \ No newline at end of file + system.filesystem.usage{system.filesystem.state=free}: $5 +translations: + serviceLoadedTranslationTable: + not-found: "0" + loaded: "1" + serviceActiveTranslationTable: + inactive: "0" + active: "1" \ No newline at end of file