├── .editorconfig ├── .gitattributes ├── .github ├── release-drafter.yml └── workflows │ ├── gradle-wrapper-validation.yml │ ├── release-drafter.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── contrib ├── hpux-sar-A.sh ├── macsar.sh └── sarl ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── kSar └── samples │ ├── sar-10.2.1-full-output │ ├── sar-10.2.1-historical │ ├── sar-11.6.1-full-output │ ├── sar-12.0.2-historical │ ├── sar-12.3.2-historical │ ├── sar-AIX-7.2 │ └── sar-Solaris-11.3 ├── renovate.json ├── settings.gradle.kts └── src ├── main ├── checkstyle │ ├── google-checks.xml │ ├── ksar-checks.xml │ ├── ksar-eclipse-java-google-style.xml │ └── ksar-intellij-java-google-style.xml ├── java │ └── net │ │ └── atomique │ │ └── ksar │ │ ├── AllParser.java │ │ ├── Config.java │ │ ├── FileRead.java │ │ ├── GlobalOptions.java │ │ ├── LocalCommand.java │ │ ├── Main.java │ │ ├── OSParser.java │ │ ├── SSHCommand.java │ │ ├── VersionNumber.java │ │ ├── XMLConfig.java │ │ ├── export │ │ ├── FileCSV.java │ │ └── FilePDF.java │ │ ├── graph │ │ ├── Graph.java │ │ ├── IEEE1541Number.java │ │ ├── ISNumber.java │ │ └── List.java │ │ ├── kSar.java │ │ ├── parser │ │ ├── AIX.java │ │ ├── HPUX.java │ │ ├── Linux.java │ │ └── SunOS.java │ │ ├── ui │ │ ├── AboutBox.form │ │ ├── AboutBox.java │ │ ├── DataView.form │ │ ├── DataView.java │ │ ├── Desktop.form │ │ ├── Desktop.java │ │ ├── GraphSelection.form │ │ ├── GraphSelection.java │ │ ├── GraphView.form │ │ ├── GraphView.java │ │ ├── HostInfoView.form │ │ ├── HostInfoView.java │ │ ├── LinuxDateFormat.form │ │ ├── LinuxDateFormat.java │ │ ├── NaturalComparator.java │ │ ├── ParentNodeInfo.java │ │ ├── Preferences.form │ │ ├── Preferences.java │ │ ├── SortedTreeNode.java │ │ └── TreeNodeInfo.java │ │ └── xml │ │ ├── CnxHistory.java │ │ ├── ColumnConfig.java │ │ ├── GraphConfig.java │ │ ├── HostInfo.java │ │ ├── OSConfig.java │ │ ├── PlotStackConfig.java │ │ └── StatConfig.java └── resources │ ├── AIX.xml │ ├── Config.xml │ ├── Esar.xml │ ├── HPUX.xml │ ├── Linux.xml │ ├── SunOS.xml │ ├── config.dtd │ ├── logback.xml │ ├── logo_ksar.jpg │ └── net │ └── atomique │ └── ksar │ └── Language │ ├── Message.properties │ └── Message_fr_FR.properties └── test ├── java └── net │ └── atomique │ └── ksar │ ├── graph │ ├── IEEE1541NumberTest.java │ └── ISNumberTest.java │ ├── parser │ ├── HpuxHeaderTest.java │ ├── LinuxHeaderTest.java │ └── SolarisHeaderTest.java │ └── ui │ └── NaturalComparatorTest.java └── resources ├── hpux-sar.txt ├── sar-10.1.5 └── testSolaris.txt /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space 8 | 9 | [{*.sh,gradlew}] 10 | end_of_line = lf 11 | 12 | [{*.bat,*.cmd}] 13 | end_of_line = crlf 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | 18 | [*.java] 19 | indent_size = 2 20 | tab_width = 2 21 | ij_continuation_indent_size = 4 22 | # Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0 23 | # $ means "static" 24 | # STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE 25 | ij_java_imports_layout = $*,|,*,|,java.**,javax.** 26 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | gradlew text eol=lf 3 | sarl text eol=lf 4 | *.bat text eol=crlf 5 | *.java text 6 | *.sql text 7 | *.sh text eol=lf 8 | *.yaml text 9 | *.yml text 10 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: 'v$RESOLVED_VERSION 🌈' 2 | tag-template: 'v$RESOLVED_VERSION' 3 | categories: 4 | - title: '🚀 Features' 5 | labels: 6 | - 'feature' 7 | - 'enhancement' 8 | - title: '🐛 Bug Fixes' 9 | labels: 10 | - 'fix' 11 | - 'bugfix' 12 | - 'bug' 13 | - title: '🧰 Maintenance' 14 | label: 'chore' 15 | change-template: '- $TITLE @$AUTHOR (#$NUMBER)' 16 | change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. 17 | version-resolver: 18 | major: 19 | labels: 20 | - 'major' 21 | minor: 22 | labels: 23 | - 'minor' 24 | patch: 25 | labels: 26 | - 'patch' 27 | default: patch 28 | template: | 29 | ## Changes 30 | 31 | $CHANGES 32 | # See https://github.com/release-drafter/release-drafter#autolabeler 33 | autolabeler: 34 | - label: 'chore' 35 | files: 36 | - '*.md' 37 | - '*gradle*' 38 | branch: 39 | - '/docs{0,1}\/.+/' 40 | - label: 'bug' 41 | branch: 42 | - '/fix\/.+/' 43 | title: 44 | - '/fix/i' 45 | - label: 'enhancement' 46 | branch: 47 | - '/feature\/.+/' 48 | -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yml: -------------------------------------------------------------------------------- 1 | name: "Validate Gradle Wrapper" 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | validation: 6 | name: "Validation" 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - uses: gradle/wrapper-validation-action@v3 11 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | # branches to consider in the event; optional, defaults to all 6 | branches: 7 | - master 8 | # pull_request event is required only for autolabeler 9 | pull_request: 10 | # Only following types are handled by the action, but one can default to all as well 11 | types: [opened, reopened, synchronize] 12 | # pull_request_target event is required for autolabeler to support PRs from forks 13 | pull_request_target: 14 | types: [opened, reopened, synchronize] 15 | 16 | jobs: 17 | update_release_draft: 18 | # Skip release drafts in forks 19 | if: github.repository_owner == 'vlsi' 20 | name: Update Release Draft 21 | runs-on: ubuntu-latest 22 | env: 23 | # Publish pre-release files to a draft release 24 | PUBLISH_SNAPSHOT: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} 25 | steps: 26 | # (Optional) GitHub Enterprise requires GHE_HOST variable set 27 | #- name: Set GHE_HOST 28 | # run: | 29 | # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV 30 | 31 | # Drafts your next Release notes as Pull Requests are merged into "master" 32 | - name: Update release body draft 33 | uses: release-drafter/release-drafter@v6 34 | id: prepare_release 35 | # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml 36 | # with: 37 | # config-name: my-config.yml 38 | # disable-autolabeler: true 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | - name: Checkout sources 42 | if: ${{ env.PUBLISH_SNAPSHOT }} 43 | uses: actions/checkout@v4 44 | - name: Set up JDK 17 45 | if: ${{ env.PUBLISH_SNAPSHOT }} 46 | uses: actions/setup-java@v4 47 | with: 48 | java-version: 17 49 | distribution: liberica 50 | - name: Build 51 | if: ${{ env.PUBLISH_SNAPSHOT }} 52 | uses: burrunan/gradle-cache-action@v3 53 | with: 54 | job-id: jdk17 55 | arguments: --scan --no-parallel --no-daemon shadowJar 56 | - name: Attach files to release 57 | if: ${{ env.PUBLISH_SNAPSHOT }} 58 | uses: actions/github-script@v7 59 | env: 60 | # https://github.com/release-drafter/release-drafter#action-outputs 61 | RELEASE_ID: ${{ steps.prepare_release.outputs.id }} 62 | with: 63 | # language=JavaScript 64 | script: | 65 | const fs = require('fs'); 66 | const {RELEASE_ID} = process.env; 67 | // remove old jar files from the release 68 | const assets = await github.rest.repos.listReleaseAssets({ 69 | owner: context.repo.owner, 70 | repo: context.repo.repo, 71 | release_id: RELEASE_ID 72 | }); 73 | for (const asset of assets.data) { 74 | if (asset.name.endsWith('-all.jar')) { 75 | await github.rest.repos.deleteReleaseAsset({ 76 | owner: context.repo.owner, 77 | repo: context.repo.repo, 78 | asset_id: asset.id 79 | }); 80 | } 81 | } 82 | const globber = await glob.create('build/libs/ksar-*-all.jar'); 83 | const files = await globber.glob(); 84 | await github.rest.repos.uploadReleaseAsset({ 85 | owner: context.repo.owner, 86 | repo: context.repo.repo, 87 | name: files[0].replace(/^(.*build\/libs\/ksar-)/, "ksar-"), 88 | release_id: RELEASE_ID, 89 | data: fs.readFileSync(files[0]) 90 | }) 91 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v[0-9]+.[0-9]+.[0-9]+' 7 | 8 | jobs: 9 | release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout sources 13 | uses: actions/checkout@v4 14 | - name: Set up JDK 17 15 | uses: actions/setup-java@v4 16 | with: 17 | java-version: 17 18 | distribution: liberica 19 | - name: Build 20 | uses: burrunan/gradle-cache-action@v3 21 | with: 22 | job-id: jdk17 23 | arguments: --scan --no-parallel --no-daemon -Prelease build 24 | - name: Prepare GitHub Release 25 | id: prepare_release 26 | uses: release-drafter/release-drafter@v6 27 | with: 28 | tag: ${{ github.ref_name }} 29 | env: 30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 | - name: Attach files to release 32 | uses: actions/github-script@v7 33 | env: 34 | TAG: ${{ github.ref_name }} 35 | # https://github.com/release-drafter/release-drafter#action-outputs 36 | RELEASE_ID: ${{ steps.prepare_release.outputs.id }} 37 | with: 38 | # language=JavaScript 39 | script: | 40 | const fs = require('fs'); 41 | const {TAG, RELEASE_ID} = process.env; 42 | // remove old jar files from the release 43 | const assets = await github.rest.repos.listReleaseAssets({ 44 | owner: context.repo.owner, 45 | repo: context.repo.repo, 46 | release_id: RELEASE_ID 47 | }); 48 | for (const asset of assets.data) { 49 | if (asset.name.endsWith('-all.jar')) { 50 | await github.rest.repos.deleteReleaseAsset({ 51 | owner: context.repo.owner, 52 | repo: context.repo.repo, 53 | asset_id: asset.id 54 | }); 55 | } 56 | } 57 | const version = TAG.substring(1); // remove leading v 58 | await github.rest.repos.uploadReleaseAsset({ 59 | owner: context.repo.owner, 60 | repo: context.repo.repo, 61 | name: "ksar-" + version + ".jar", 62 | release_id: RELEASE_ID, 63 | data: fs.readFileSync("build/libs/ksar-" + version + "-all.jar") 64 | }) 65 | - name: Publish GitHub Release 66 | id: publish_release 67 | uses: release-drafter/release-drafter@v6 68 | with: 69 | publish: true 70 | tag: ${{ github.ref_name }} 71 | env: 72 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 73 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Test 5 | 6 | on: 7 | push: 8 | branches: 9 | - '*' 10 | pull_request: 11 | branches: [ master ] 12 | 13 | jobs: 14 | build: 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | java-version: 19 | - 17 20 | - 21 21 | runs-on: ubuntu-latest 22 | name: 'Test (JDK ${{ matrix.java-version }})' 23 | steps: 24 | - uses: actions/checkout@v4 25 | - name: 'Set up JDK ${{ matrix.java-version }}' 26 | uses: actions/setup-java@v4 27 | with: 28 | java-version: ${{ matrix.java-version }} 29 | distribution: liberica 30 | - name: 'Run tests' 31 | uses: burrunan/gradle-cache-action@v3 32 | with: 33 | job-id: jdk${{ matrix.java-version }} 34 | arguments: --scan --no-parallel --no-daemon build 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | .nb-gradle/ 4 | 5 | # Temporary files 6 | *.bak 7 | *~ 8 | 9 | # Ignore Gradle GUI config 10 | gradle-app.setting 11 | 12 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 13 | !gradle-wrapper.jar 14 | 15 | # Cache of project 16 | .gradletasknamecache 17 | 18 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 19 | # gradle/wrapper/gradle-wrapper.properties 20 | 21 | # IDEA project 22 | 23 | .idea/ 24 | ksar_all.log 25 | out/ 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2008, Atomique.net. 4 | All rights reserved. 5 | 6 | Redistribution and use of this software in source and binary forms, with or without modification, are 7 | permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above 10 | copyright notice, this list of conditions and the 11 | following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the 15 | following disclaimer in the documentation and/or other 16 | materials provided with the distribution. 17 | 18 | * Neither the name of Atomique.net nor the names of its 19 | contributors may be used to endorse or promote products 20 | derived from this software without specific prior 21 | written permission of Atomique.net. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 24 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 29 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 30 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | kSar 2 | ==== 3 | 4 | [![Build Status](https://github.com/vlsi/ksar/workflows/Test/badge.svg?branch=master)](https://github.com/vlsi/ksar/actions?query=branch%3Amaster) 5 | 6 | Quick Start 7 | ----------- 8 | 9 | ksar is a sar graphing tool that can graph for now linux, maOS and solaris sar output. sar statistics graph can be output to a pdf file. 10 | This is a fork of http://sourceforge.net/projects/ksar/ 11 | 12 | Prerequisite: 13 | 14 | - Java 17 or later 15 | 16 | Download a pre-built jar from [GitHub releases page](https://github.com/vlsi/ksar/releases). 17 | 18 | ``` 19 | $ java -jar ksar-6.0.0-all.jar 20 | ``` 21 | 22 | Building from source 23 | -------------------- 24 | 25 | Prerequisite: 26 | 27 | - JDK 17 or later 28 | 29 | The following command would build and launch kSar from sources: 30 | 31 | ``` 32 | $ ./gradlew runShadow 33 | ``` 34 | 35 | or 36 | 37 | ``` 38 | $ ./gradlew shadowJar 39 | $ java -jar build/libs/ksar-6.0.0-SNAPSHOT-all.jar 40 | ``` 41 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java") 3 | id("application") 4 | id("com.github.johnrengelman.shadow") version "8.1.1" 5 | id("checkstyle") 6 | id("com.github.vlsi.gradle-extensions") version "1.90" 7 | } 8 | 9 | group = "com.github.vlsi.ksar" 10 | 11 | if (!project.hasProperty("release")) { 12 | version = "$version-SNAPSHOT" 13 | } 14 | 15 | println("Building kSar $version") 16 | 17 | java { 18 | sourceCompatibility = JavaVersion.VERSION_17 19 | targetCompatibility = JavaVersion.VERSION_17 20 | } 21 | 22 | application { 23 | mainClass.set("net.atomique.ksar.Main") 24 | } 25 | 26 | repositories { 27 | mavenCentral() 28 | } 29 | 30 | dependencies { 31 | implementation("org.slf4j:slf4j-api:2.0.17") 32 | implementation("ch.qos.logback:logback-core:1.5.18") 33 | implementation("ch.qos.logback:logback-classic:1.5.18") 34 | 35 | implementation("com.itextpdf:itextpdf:5.5.13.4") 36 | implementation("com.jcraft:jsch:0.1.55") 37 | implementation("org.jfree:jfreechart:1.5.6") 38 | 39 | testImplementation("org.junit.jupiter:junit-jupiter:5.12.2") 40 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 41 | } 42 | 43 | tasks.withType().configureEach { 44 | options.compilerArgs.add("-Xlint:unchecked") 45 | options.compilerArgs.add("-Xlint:deprecation") 46 | } 47 | 48 | tasks.withType().configureEach { 49 | useJUnitPlatform() 50 | } 51 | 52 | val writeVersion by tasks.registering { 53 | val outDir = project.layout.buildDirectory.dir("generated/version") 54 | val versionText = version.toString() 55 | inputs.property("ksar.version", versionText) 56 | outputs.dir(outDir) 57 | doLast { 58 | outDir.get().apply { 59 | asFile.mkdirs() 60 | file("kSar.version").asFile.writeText(versionText) 61 | } 62 | } 63 | } 64 | 65 | sourceSets.main.get().resources.srcDir(writeVersion) 66 | 67 | checkstyle { 68 | config = project.resources.text.fromFile("src/main/checkstyle/ksar-checks.xml", "UTF-8") 69 | } 70 | 71 | tasks.jar { 72 | manifest { 73 | attributes( 74 | "Implementation-Title" to "kSAR", 75 | "Implementation-Version" to archiveVersion, 76 | "SplashScreen-Image" to "logo_ksar.jpg", 77 | ) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /contrib/hpux-sar-A.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SAR=/usr/bin/sar 4 | 5 | if [ "`uname -s`" != "HP-UX" ] ; then 6 | echo "Only For HP-UX" 7 | exit 1 8 | fi 9 | 10 | ARG="u d q b w c a y v m" 11 | 12 | usage() 13 | { 14 | echo "$0: [-f sar filename ]" 15 | echo "" 16 | exit 1; 17 | } 18 | 19 | while getopts f: i 2>/dev/null 20 | do 21 | case "$i" in 22 | f) sarfile="$OPTARG";; 23 | \?) usage;; 24 | esac 25 | done 26 | 27 | 28 | if [ -n "$OPTIND" ] ; then 29 | shift `expr $OPTIND - 1` 30 | fi 31 | 32 | if [ -z "$sarfile" ] ; then 33 | sarfile=/var/adm/sa/sa`date +%d` 34 | fi 35 | 36 | if [ ! -r "$sarfile" ] ; then 37 | echo "unable to read : $sarfile ....exiting" 38 | exit 1 39 | fi 40 | 41 | for i in $ARG 42 | do 43 | $SAR "-${i}" -f $sarfile 44 | if [ $? != 0 ] ; then exit 1; fi 45 | done 46 | 47 | exit 0 48 | 49 | -------------------------------------------------------------------------------- /contrib/macsar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | # 5 | # add header to original mac sar 6 | # 7 | # uname -s ; uname -n ; uname -r ; uname -p ; date '+%m/%d/%y' 8 | 9 | OS=`uname -s -n -r -p 2>/dev/null` 10 | DT=`date '+%m/%d/%y' 2>/dev/null` 11 | ARG="$*" 12 | 13 | lastdashf=0 14 | for i in $* 15 | do 16 | if [ $lastdashf == 1 ] ; then file=$i ; fi 17 | if [ "$i" == "-f" ] ; then lastdashf=1; else lastdashf=0; fi 18 | done 19 | 20 | 21 | if [ -n "$file" ] ; then 22 | D1=`echo $file| sed -e 's/\(.*\)sa\([0-90-9]\)/\2/' 2>/dev/null` 23 | DT=`date '+%d' 2>/dev/null` 24 | D2=`date '+%m' 2>/dev/null` 25 | D3=`date '+%y' 2>/dev/null` 26 | if [ "$D1" -gt "$DT" ] ; then 27 | D2=`expr $D2 - 1 2>/dev/null` 28 | if [ "$D2" -eq "0" ] ; then 29 | D2=12 30 | D3=`expr $D3 - 1 2>/dev/null` 31 | fi 32 | fi 33 | DATESTR="$D2/$D1/$D3" 34 | else 35 | DATESTR="$DT" 36 | fi 37 | 38 | echo "" 39 | echo "$OS $DATESTR" 40 | sar $ARG 41 | -------------------------------------------------------------------------------- /contrib/sarl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## sarl ( 4 | # written by FBA/XCH 5 | 6 | 7 | PATH=/usr/lib64/sa:/usr/lib/sa:/bin:/usr/bin 8 | LANG=C 9 | TEMP=$1 10 | SEC=${TEMP:-60} 11 | 12 | DATE=`date +%d` 13 | for i in /var/adm/sa /var/log/sa ; do 14 | if [ -d $i ] ; then DDIR=$i ; break ; fi 15 | done 16 | 17 | DFILE=$DDIR/sa$DATE 18 | cd $DDIR 19 | 20 | 21 | H=`date '+%H'` 22 | M=`date '+%M'` 23 | 24 | LEFT=`expr \( 3600 \* 24 - 1 - $H \* 3600 - $M \* 60 \) / $SEC` 25 | LEFT=`expr \( 60 \* 24 - 1 - $H \* 60 - $M \) ` 26 | 27 | 28 | ( exec sadc $SEC $LEFT $DFILE /dev/null 2>&1 ) & 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2018-2023 The kSAR Project. All rights reserved. 3 | # See the LICENSE file in the project root for more information. 4 | # 5 | 6 | version = 6.0.0 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vlsi/ksar/0332fdf7f398880fc7658579f713872d40203868/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionSha256Sum=845952a9d6afa783db70bb3b0effaae45ae5542ca2bb7929619e8af49cb634cf 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ], 6 | "schedule": ["every 3 weeks on Monday"], 7 | "packageRules": [ 8 | { 9 | "matchPackagePrefixes": ["ch.qos.logback"], 10 | "groupName": "ch.qos.logback" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "ksar" 2 | -------------------------------------------------------------------------------- /src/main/checkstyle/ksar-intellij-java-google-style.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 133 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/AllParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import net.atomique.ksar.xml.OSConfig; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.time.LocalDate; 13 | import java.time.LocalDateTime; 14 | import java.time.LocalTime; 15 | import java.time.format.DateTimeFormatter; 16 | import java.time.format.DateTimeParseException; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | import java.util.TreeSet; 20 | 21 | public abstract class AllParser { 22 | 23 | private static final Logger log = LoggerFactory.getLogger(AllParser.class); 24 | private static final Map DATE_FORMAT_REGEXPS = new HashMap() { 25 | { 26 | put("^\\d{8}$", "yyyyMMdd"); 27 | put("^\\d{1,2}-\\d{1,2}-\\d{4}$", "dd-MM-yyyy"); 28 | put("^\\d{4}-\\d{1,2}-\\d{1,2}$", "yyyy-MM-dd"); 29 | put("^\\d{1,2}/\\d{1,2}/\\d{4}$", "MM/dd/yyyy"); 30 | put("^\\d{4}/\\d{1,2}/\\d{1,2}$", "yyyy/MM/dd"); 31 | put("^\\d{1,2}\\s[a-z]{3}\\s\\d{4}$", "dd MMM yyyy"); 32 | put("^\\d{1,2}\\s[a-z]{4,}\\s\\d{4}$", "dd MMMM yyyy"); 33 | put("^\\d{1,2}-\\d{1,2}-\\d{2}$", "dd-MM-yy"); 34 | put("^\\d{1,2}/\\d{1,2}/\\d{2}$", "MM/dd/yy"); 35 | } 36 | }; 37 | 38 | public AllParser() { 39 | 40 | } 41 | 42 | public void init(kSar hissar, String header) { 43 | String parserName = header.split("\\s+", 2)[0]; 44 | mysar = hissar; 45 | ParserName = parserName; 46 | parse_header(header); 47 | } 48 | 49 | public AllParser(kSar hissar, String header) { 50 | init(hissar, header); 51 | } 52 | 53 | public int parse(String line, String[] columns) { 54 | log.error("not implemented"); 55 | return -1; 56 | } 57 | 58 | /** 59 | * Set {@link #startOfGraph} and {@link #endOfGraph} to the given value if none are available yet 60 | * or update either of both, depending on if the given value is earlier/later than the formerly 61 | * stored corresponding one. 62 | * 63 | * @param nowStat Date/time of the currently parsed line. 64 | */ 65 | protected void setStartAndEndOfGraph(LocalDateTime nowStat) { 66 | if (startOfGraph == null) { 67 | startOfGraph = nowStat; 68 | } 69 | if (endOfGraph == null) { 70 | endOfGraph = nowStat; 71 | } 72 | 73 | if (nowStat.compareTo(startOfGraph) < 0) { 74 | startOfGraph = nowStat; 75 | } 76 | if (nowStat.compareTo(endOfGraph) > 0) { 77 | endOfGraph = nowStat; 78 | } 79 | } 80 | 81 | public LocalDateTime getStartOfGraph() { 82 | return startOfGraph; 83 | } 84 | 85 | public LocalDateTime getEndOfGraph() { 86 | return endOfGraph; 87 | } 88 | 89 | public String getParserName() { 90 | return ParserName; 91 | } 92 | 93 | public boolean setDate(String s) { 94 | LocalDate currentDate; 95 | LocalDate startDate; 96 | LocalDate endDate; 97 | 98 | if (sarStartDate == null) { 99 | sarStartDate = s; 100 | } 101 | if (sarEndDate == null) { 102 | sarEndDate = s; 103 | } 104 | 105 | try { 106 | DateTimeFormatter formatter; 107 | if ("Automatic Detection".equals(dateFormat)) { 108 | formatter = DateTimeFormatter.ofPattern(determineDateFormat(s)); 109 | 110 | } else { 111 | formatter = DateTimeFormatter.ofPattern(dateFormat); 112 | } 113 | 114 | log.debug("Date formatter: {}",formatter); 115 | currentDate = LocalDate.parse(s, formatter); 116 | 117 | startDate = LocalDate.parse(sarStartDate, formatter); 118 | endDate = LocalDate.parse(sarEndDate, formatter); 119 | 120 | } catch (DateTimeParseException ex) { 121 | log.error("unable to parse date {}", s, ex); 122 | return false; 123 | } 124 | 125 | parsedate = currentDate; 126 | 127 | if (currentDate.compareTo(startDate) < 0) { 128 | sarStartDate = s; 129 | } 130 | if (currentDate.compareTo(endDate) > 0) { 131 | sarEndDate = s; 132 | } 133 | log.debug("parsedDate: {}, startDate: {}, EndDate: {}",currentDate, sarStartDate, sarEndDate); 134 | return true; 135 | } 136 | 137 | public String getDate() { 138 | if (sarStartDate.equals(sarEndDate)) { 139 | return sarStartDate; 140 | } else { 141 | return sarStartDate + " to " + sarEndDate; 142 | } 143 | } 144 | 145 | public TreeSet getDateSamples() { 146 | return DateSamples; 147 | } 148 | 149 | public String getCurrentStat() { 150 | return currentStat; 151 | } 152 | 153 | public static String determineDateFormat(String dateString) { 154 | for (String regexp : DATE_FORMAT_REGEXPS.keySet()) { 155 | if (dateString.toLowerCase().matches(regexp)) { 156 | return DATE_FORMAT_REGEXPS.get(regexp); 157 | } 158 | } 159 | return null; // Unknown format. 160 | } 161 | 162 | protected String sarStartDate = null; 163 | protected String sarEndDate = null; 164 | 165 | private LocalDateTime startOfGraph = null; 166 | private LocalDateTime endOfGraph = null; 167 | 168 | protected TreeSet DateSamples = new TreeSet(); 169 | protected int firstdatacolumn = 0; 170 | 171 | abstract public String getInfo(); 172 | 173 | abstract public void parse_header(String s); 174 | 175 | abstract public void updateUITitle(); 176 | 177 | protected kSar mysar = null; 178 | protected OSConfig myosconfig = null; 179 | protected String ParserName = null; 180 | 181 | protected LocalTime parsetime = null; 182 | protected LocalDate parsedate = null; 183 | 184 | protected String currentStat = "NONE"; 185 | protected String dateFormat = "MM/dd/yy"; 186 | protected String timeFormat = "HH:mm:ss"; 187 | protected int timeColumn = 1; 188 | } 189 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.awt.Font; 12 | import java.io.BufferedWriter; 13 | import java.io.File; 14 | import java.io.FileWriter; 15 | import java.io.IOException; 16 | import java.util.ArrayList; 17 | import java.util.Properties; 18 | import java.util.prefs.BackingStoreException; 19 | import java.util.prefs.Preferences; 20 | import javax.swing.UIManager; 21 | 22 | public class Config { 23 | 24 | private static final Logger log = LoggerFactory.getLogger(GlobalOptions.class); 25 | 26 | private static Preferences myPref; 27 | private static Config instance = new Config(); 28 | 29 | static Config getInstance() { 30 | return instance; 31 | } 32 | 33 | private Config() { 34 | 35 | log.trace("load Config"); 36 | 37 | myPref = Preferences.userNodeForPackage(Config.class); 38 | if (myPref.getInt("local_configfile", -1) == -1) { 39 | // new 40 | try { 41 | myPref.clear(); 42 | myPref.flush(); 43 | } catch (BackingStoreException e) { 44 | log.error("BackingStoreException", e); 45 | } 46 | local_configfile = store_configdir(); 47 | myPref.putInt("local_configfile", local_configfile); 48 | 49 | } 50 | load(); 51 | } 52 | 53 | private static void load() { 54 | /* 55 | * load default value or stored value 56 | */ 57 | setLandf(myPref.get("landf", UIManager.getLookAndFeel().getName())); 58 | setLastReadDirectory(myPref.get("lastReadDirectory", null)); 59 | setLastExportDirectory(myPref.get("lastExportDirectory", null)); 60 | 61 | setImageHeight(myPref.getInt("ImageHeight", 600)); 62 | setImageWidth(myPref.getInt("ImageWidth", 800)); 63 | setPDFPageFormat(myPref.get("PDFPageFormat", "A4")); 64 | setLinuxDateFormat(myPref.get("LinuxDateFormat", "Always ask")); 65 | 66 | setNumber_host_history(myPref.getInt("HostHistory", 0)); 67 | for (int i = 0; i < getNumber_host_history(); i++) { 68 | host_history.add(myPref.get("HostHistory_" + i, null)); 69 | } 70 | setLocal_configfile(myPref.getInt("local_configfile", -1)); 71 | } 72 | 73 | public static void save() { 74 | if (myPref == null) { 75 | return; 76 | } 77 | myPref.put("landf", landf); 78 | if (lastReadDirectory != null) { 79 | myPref.put("lastReadDirectory", lastReadDirectory.toString()); 80 | } 81 | if (lastExportDirectory != null) { 82 | myPref.put("lastExportDirectory", lastExportDirectory.toString()); 83 | } 84 | 85 | myPref.putInt("ImageHeight", ImageHeight); 86 | myPref.putInt("ImageWidth", ImageWidth); 87 | myPref.put("PDFPageFormat", PDFPageFormat); 88 | myPref.put("LinuxDateFormat", LinuxDateFormat); 89 | 90 | for (int i = 0; i < host_history.size(); i++) { 91 | myPref.put("HostHistory_" + i, host_history.get(i)); 92 | } 93 | myPref.putInt("HostHistory", host_history.size()); 94 | 95 | myPref.putInt("local_configfile", local_configfile); 96 | 97 | } 98 | 99 | public static String getLandf() { 100 | return landf; 101 | } 102 | 103 | public static void setLandf(String landf) { 104 | Config.landf = landf; 105 | } 106 | 107 | static File getLastReadDirectory() { 108 | return lastReadDirectory; 109 | } 110 | 111 | private static void setLastReadDirectory(String lastReadDirectory) { 112 | if (lastReadDirectory != null) { 113 | Config.lastReadDirectory = new File(lastReadDirectory); 114 | } 115 | } 116 | 117 | static void setLastReadDirectory(File lastReadDirectory) { 118 | Config.lastReadDirectory = lastReadDirectory; 119 | } 120 | 121 | public static File getLastExportDirectory() { 122 | return lastExportDirectory; 123 | } 124 | 125 | public static void setLastExportDirectory(String lastExportDirectory) { 126 | if (lastExportDirectory != null) { 127 | Config.lastExportDirectory = new File(lastExportDirectory); 128 | } 129 | } 130 | 131 | public static void setLastExportDirectory(File lastExportDirectory) { 132 | Config.lastExportDirectory = lastExportDirectory; 133 | } 134 | 135 | public static String getLastCommand() { 136 | return lastCommand; 137 | } 138 | 139 | public static void setLastCommand(String lastCommand) { 140 | Config.lastCommand = lastCommand; 141 | } 142 | 143 | public static ArrayList getHost_history() { 144 | return host_history; 145 | } 146 | 147 | public static void addHost_history(String e) { 148 | host_history.add(e); 149 | } 150 | 151 | private static int getNumber_host_history() { 152 | return number_host_history; 153 | } 154 | 155 | private static void setNumber_host_history(int number_host_history) { 156 | Config.number_host_history = number_host_history; 157 | } 158 | 159 | public static Font getDEFAULT_FONT() { 160 | return DEFAULT_FONT; 161 | } 162 | 163 | public static int getImageHeight() { 164 | return ImageHeight; 165 | } 166 | 167 | public static void setImageHeight(int ImageHeight) { 168 | Config.ImageHeight = ImageHeight; 169 | } 170 | 171 | public static int getImageWidth() { 172 | return ImageWidth; 173 | } 174 | 175 | public static void setImageWidth(int ImageWidth) { 176 | Config.ImageWidth = ImageWidth; 177 | } 178 | 179 | public static String getPDFPageFormat() { 180 | return PDFPageFormat; 181 | } 182 | 183 | public static void setPDFPageFormat(String PDFPageFormat) { 184 | Config.PDFPageFormat = PDFPageFormat; 185 | } 186 | 187 | 188 | private static int store_configdir() { 189 | Properties systemprops = System.getProperties(); 190 | String userhome = (String) systemprops.get("user.home") + systemprops.get("file.separator"); 191 | String username = (String) systemprops.get("user.name"); 192 | String fileseparator = (String) systemprops.get("file.separator"); 193 | // mkdir userhome/.ksar 194 | String buffer = "\n\n\n\n\n"; 195 | boolean home = new File(userhome + ".ksarcfg").mkdir(); 196 | if (!home) { 197 | return 0; 198 | } 199 | 200 | BufferedWriter out; 201 | try { 202 | out = 203 | new BufferedWriter(new FileWriter(userhome + ".ksarcfg" + fileseparator + "Config.xml")); 204 | out.write(buffer); 205 | out.flush(); 206 | out.close(); 207 | return 1; 208 | } catch (IOException e) { 209 | return 0; 210 | } 211 | 212 | } 213 | 214 | public static int getLocal_configfile() { 215 | return local_configfile; 216 | } 217 | 218 | private static void setLocal_configfile(int local_configfile) { 219 | Config.local_configfile = local_configfile; 220 | } 221 | 222 | public static String getLinuxDateFormat() { 223 | return LinuxDateFormat; 224 | } 225 | 226 | public static void setLinuxDateFormat(String LinuxDateFormat) { 227 | Config.LinuxDateFormat = LinuxDateFormat; 228 | } 229 | 230 | 231 | private static String landf; 232 | private static File lastReadDirectory; 233 | private static File lastExportDirectory; 234 | private static String lastCommand; 235 | private static int number_host_history; 236 | private static int local_configfile; 237 | private static ArrayList host_history = new ArrayList<>(); 238 | private static final Font DEFAULT_FONT = new Font("SansSerif", Font.BOLD, 18); 239 | 240 | private static String LinuxDateFormat; 241 | private static String PDFPageFormat; 242 | private static int ImageWidth; 243 | private static int ImageHeight; 244 | 245 | } 246 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/FileRead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.FileNotFoundException; 12 | import java.io.FileReader; 13 | import java.io.IOException; 14 | import javax.swing.JFileChooser; 15 | 16 | public class FileRead extends Thread { 17 | 18 | private static final org.slf4j.Logger log = LoggerFactory.getLogger(FileRead.class); 19 | 20 | public FileRead(kSar hissar) { 21 | mysar = hissar; 22 | JFileChooser fc = new JFileChooser(); 23 | if (Config.getLastReadDirectory() != null) { 24 | fc.setCurrentDirectory(Config.getLastReadDirectory()); 25 | } 26 | int returnVal = fc.showDialog(GlobalOptions.getUI(), "Open"); 27 | if (returnVal == JFileChooser.APPROVE_OPTION) { 28 | sarfilename = fc.getSelectedFile().getAbsolutePath(); 29 | if (fc.getSelectedFile().isDirectory()) { 30 | Config.setLastReadDirectory(fc.getSelectedFile()); 31 | } else { 32 | Config.setLastReadDirectory(fc.getSelectedFile().getParentFile()); 33 | } 34 | Config.save(); 35 | } 36 | } 37 | 38 | public FileRead(kSar hissar, String filename) { 39 | mysar = hissar; 40 | sarfilename = filename; 41 | } 42 | 43 | public String get_action() { 44 | if (sarfilename != null) { 45 | return "file://" + sarfilename; 46 | } else { 47 | return null; 48 | } 49 | } 50 | 51 | private void close() { 52 | try { 53 | if (myfilereader != null) { 54 | myfilereader.close(); 55 | } 56 | if (tmpfile != null) { 57 | tmpfile.close(); 58 | } 59 | } catch (IOException ex) { 60 | log.error("IO Exception", ex); 61 | } 62 | } 63 | 64 | public void run() { 65 | if (sarfilename == null) { 66 | return; 67 | } 68 | 69 | try { 70 | tmpfile = new FileReader(sarfilename); 71 | 72 | log.debug("FileEncoding : {}", tmpfile.getEncoding()); 73 | 74 | } catch (FileNotFoundException ex) { 75 | log.error("IO Exception", ex); 76 | } 77 | 78 | myfilereader = new BufferedReader(tmpfile); 79 | 80 | mysar.parse(myfilereader); 81 | 82 | close(); 83 | } 84 | 85 | private kSar mysar = null; 86 | private String sarfilename = null; 87 | private FileReader tmpfile = null; 88 | private BufferedReader myfilereader = null; 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/GlobalOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import net.atomique.ksar.ui.Desktop; 9 | import net.atomique.ksar.xml.CnxHistory; 10 | import net.atomique.ksar.xml.ColumnConfig; 11 | import net.atomique.ksar.xml.HostInfo; 12 | import net.atomique.ksar.xml.OSConfig; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | import java.awt.Color; 17 | import java.io.BufferedWriter; 18 | import java.io.File; 19 | import java.io.FileWriter; 20 | import java.io.IOException; 21 | import java.util.HashMap; 22 | import java.util.Iterator; 23 | import java.util.Properties; 24 | 25 | public class GlobalOptions { 26 | 27 | private static final Logger log = LoggerFactory.getLogger(GlobalOptions.class); 28 | 29 | private static GlobalOptions instance = new GlobalOptions(); 30 | 31 | static GlobalOptions getInstance() { 32 | return instance; 33 | } 34 | 35 | public static boolean hasUI() { 36 | return (UI != null); 37 | } 38 | 39 | private GlobalOptions() { 40 | 41 | log.trace("load GlobalOptions"); 42 | 43 | String[] OSParserNames = {"AIX", "HPUX", "Linux", "SunOS"}; 44 | String filename; 45 | XMLConfig tmp; 46 | systemprops = System.getProperties(); 47 | username = (String) systemprops.get("user.name"); 48 | userhome = (String) systemprops.get("user.home") + systemprops.get("file.separator"); 49 | fileseparator = (String) systemprops.get("file.separator"); 50 | columnlist = new HashMap<>(); 51 | OSlist = new HashMap<>(); 52 | ParserMap = new HashMap<>(); 53 | HistoryList = new HashMap<>(); 54 | HostInfoList = new HashMap<>(); 55 | tmp = new XMLConfig(); 56 | tmp.loadFromResources("/Config.xml"); 57 | for (String OSName : OSParserNames) { 58 | try { 59 | Class tmpclass = Class.forName("net.atomique.ksar.parser." + OSName); 60 | ParserMap.put(OSName, tmpclass); 61 | } catch (ClassNotFoundException ex) { 62 | log.error("Parser class not found", ex); 63 | } 64 | 65 | } 66 | for (String parsername : ParserMap.keySet()) { 67 | tmp.loadFromResources("/" + parsername + ".xml"); 68 | } 69 | 70 | filename = userhome + ".ksarcfg" + fileseparator + "Config.xml"; 71 | File file = new File(filename); 72 | if (file.canRead()) { 73 | tmp.loadConfig(file); 74 | } 75 | filename = userhome + ".ksarcfg" + fileseparator + "History.xml"; 76 | file = new File(filename); 77 | if (file.canRead()) { 78 | tmp.loadConfig(file); 79 | } 80 | 81 | } 82 | 83 | public static Desktop getUI() { 84 | return UI; 85 | } 86 | 87 | public static void setUI(Desktop UI) { 88 | GlobalOptions.UI = UI; 89 | } 90 | 91 | public static String getUserhome() { 92 | return userhome; 93 | } 94 | 95 | public static String getUsername() { 96 | return username; 97 | } 98 | 99 | static HashMap getColorlist() { 100 | return columnlist; 101 | } 102 | 103 | static HashMap getOSlist() { 104 | return OSlist; 105 | } 106 | 107 | public static ColumnConfig getColumnConfig(String s) { 108 | if (columnlist.isEmpty()) { 109 | return null; 110 | } 111 | return columnlist.get(s); 112 | } 113 | 114 | public static Color getDataColor(String s) { 115 | ColumnConfig tmp = columnlist.get(s); 116 | if (tmp != null) { 117 | return tmp.getData_color(); 118 | } else { 119 | log.warn("color not found for tag {}", s); 120 | } 121 | return null; 122 | } 123 | 124 | static OSConfig getOSinfo(String s) { 125 | return OSlist.get(s); 126 | } 127 | 128 | static String getCLfilename() { 129 | return CLfilename; 130 | } 131 | 132 | static void setCLfilename(String CL_filename) { 133 | CLfilename = CL_filename; 134 | } 135 | 136 | public static String getFileseparator() { 137 | return fileseparator; 138 | } 139 | 140 | static Class getParser(String s) { 141 | String tmp = s.replaceAll("-", ""); 142 | if (ParserMap.isEmpty()) { 143 | return null; 144 | } 145 | return ParserMap.get(tmp); 146 | } 147 | 148 | static HashMap getHostInfoList() { 149 | return HostInfoList; 150 | } 151 | 152 | public static HostInfo getHostInfo(String s) { 153 | if (HostInfoList.isEmpty()) { 154 | return null; 155 | } 156 | return HostInfoList.get(s); 157 | } 158 | 159 | public static void addHostInfo(HostInfo s) { 160 | HostInfoList.put(s.getHostname(), s); 161 | saveHistory(); 162 | } 163 | 164 | static HashMap getHistoryList() { 165 | return HistoryList; 166 | } 167 | 168 | static CnxHistory getHistory(String s) { 169 | if (HistoryList.isEmpty()) { 170 | return null; 171 | } 172 | return HistoryList.get(s); 173 | } 174 | 175 | static void addHistory(CnxHistory s) { 176 | CnxHistory tmp = HistoryList.get(s.getLink()); 177 | if (tmp != null) { 178 | Iterator ite = s.getCommandList().iterator(); 179 | while (ite.hasNext()) { 180 | tmp.addCommand(ite.next()); 181 | } 182 | } else { 183 | HistoryList.put(s.getLink(), s); 184 | } 185 | saveHistory(); 186 | } 187 | 188 | 189 | static void saveHistory() { 190 | File tmpfile = null; 191 | BufferedWriter tmpfile_out = null; 192 | 193 | if (HistoryList.isEmpty() && HostInfoList.isEmpty()) { 194 | log.info("list is null"); 195 | return; 196 | } 197 | 198 | try { 199 | tmpfile = new File(userhome + ".ksarcfg" + fileseparator + "History.xmltemp"); 200 | 201 | if (tmpfile.exists()) { 202 | tmpfile.delete(); 203 | } 204 | if (tmpfile.createNewFile() && tmpfile.canWrite()) { 205 | tmpfile_out = new BufferedWriter(new FileWriter(tmpfile)); 206 | } 207 | //xml header 208 | tmpfile_out.write("\n\n"); 209 | tmpfile_out.write("\t\n"); 210 | Iterator ite = HistoryList.keySet().iterator(); 211 | while (ite.hasNext()) { 212 | CnxHistory tmp = HistoryList.get(ite.next()); 213 | tmpfile_out.write(tmp.save()); 214 | } 215 | //xml footer 216 | tmpfile_out.write("\t\n"); 217 | tmpfile_out.write("\t\n"); 218 | Iterator ite2 = HostInfoList.keySet().iterator(); 219 | while (ite2.hasNext()) { 220 | HostInfo tmp = HostInfoList.get(ite2.next()); 221 | tmpfile_out.write(tmp.save()); 222 | } 223 | //xml footer 224 | tmpfile_out.write("\t\n"); 225 | tmpfile_out.write("\n"); 226 | tmpfile_out.flush(); 227 | tmpfile_out.close(); 228 | File oldfile = new File(userhome + ".ksarcfg" + fileseparator + "History.xml"); 229 | oldfile.delete(); 230 | tmpfile.renameTo(oldfile); 231 | 232 | } catch (IOException ex) { 233 | log.error("IO exception", ex); 234 | } 235 | 236 | } 237 | 238 | private static Desktop UI = null; 239 | private static Properties systemprops; 240 | private static String userhome; 241 | private static String username; 242 | private static String fileseparator; 243 | private static HashMap columnlist; 244 | private static HashMap OSlist; 245 | private static HashMap HistoryList; 246 | private static HashMap HostInfoList; 247 | private static String CLfilename = null; 248 | private static HashMap ParserMap; 249 | private static boolean firstrun = true; 250 | } 251 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/LocalCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.BufferedReader; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.InputStreamReader; 15 | import java.util.ArrayList; 16 | import java.util.Arrays; 17 | import java.util.List; 18 | import javax.swing.JOptionPane; 19 | 20 | public class LocalCommand extends Thread { 21 | 22 | private static final Logger log = LoggerFactory.getLogger(LocalCommand.class); 23 | 24 | LocalCommand(kSar hissar) { 25 | mysar = hissar; 26 | try { 27 | command = JOptionPane.showInputDialog(GlobalOptions.getUI(), "Enter local command ", "sar -A"); 28 | if (command == null) { 29 | return; 30 | } 31 | String[] cmdArray = command.split(" +"); 32 | List cmdList = new ArrayList<>(Arrays.asList(cmdArray)); 33 | ProcessBuilder pb = new ProcessBuilder(cmdList); 34 | pb.environment().put("LC_ALL", "C"); 35 | p = pb.start(); 36 | in = p.getInputStream(); 37 | } catch (Exception e) { 38 | JOptionPane.showMessageDialog(GlobalOptions.getUI(), "There was a problem while running the command ", 39 | "Local error", JOptionPane.ERROR_MESSAGE); 40 | in = null; 41 | } 42 | 43 | } 44 | 45 | LocalCommand(kSar hissar, String hiscommand) { 46 | mysar = hissar; 47 | command = hiscommand; 48 | try { 49 | String[] envvar; 50 | envvar = new String[1]; 51 | envvar[0] = "LC_ALL=C"; 52 | 53 | p = Runtime.getRuntime().exec(command, envvar); 54 | in = p.getInputStream(); 55 | } catch (Exception e) { 56 | if (GlobalOptions.hasUI()) { 57 | JOptionPane.showMessageDialog(GlobalOptions.getUI(), 58 | "There was a problem while running the command " + command, "Local error", 59 | JOptionPane.ERROR_MESSAGE); 60 | } else { 61 | log.error("There was a problem while running the command {}", command); 62 | } 63 | in = null; 64 | } 65 | 66 | } 67 | 68 | private void close() { 69 | if (p != null) { 70 | p.destroy(); 71 | } 72 | } 73 | 74 | public void run() { 75 | 76 | if (in == null) { 77 | return; 78 | } 79 | 80 | try { 81 | BufferedReader myfilereader = new BufferedReader(new InputStreamReader(in)); 82 | mysar.parse(myfilereader); 83 | myfilereader.close(); 84 | } catch (IOException ex) { 85 | log.error("IO Exception", ex); 86 | } 87 | 88 | 89 | close(); 90 | } 91 | 92 | String get_action() { 93 | if (command != null) { 94 | return "cmd://" + command; 95 | } else { 96 | return null; 97 | } 98 | } 99 | 100 | private kSar mysar; 101 | private InputStream in = null; 102 | private String command = null; 103 | private Process p = null; 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import ch.qos.logback.classic.Level; 9 | import net.atomique.ksar.ui.Desktop; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import java.util.Arrays; 14 | import java.util.ResourceBundle; 15 | import javax.swing.SwingUtilities; 16 | import javax.swing.UIManager; 17 | import javax.swing.UnsupportedLookAndFeelException; 18 | 19 | public class Main { 20 | 21 | private static final Logger log = LoggerFactory.getLogger(Main.class); 22 | static { 23 | ((ch.qos.logback.classic.Logger)log).setLevel(Level.INFO); 24 | } 25 | 26 | static Config config = null; 27 | static GlobalOptions globaloptions = null; 28 | static ResourceBundle resource = ResourceBundle.getBundle("net/atomique/ksar/Language/Message"); 29 | 30 | public static void usage() { 31 | log.info("Usage: ksar [OPTIONS]"); 32 | log.info("OPTIONS:"); 33 | log.info(" -input INPUTFILE load INPUTFILE sa sar data"); 34 | log.info(" -debug enable debug level output"); 35 | log.info(" -test an alist for -debug option"); 36 | log.info(" -trace enable trace level output"); 37 | log.info(" -version print the version information"); 38 | log.info(" -help print this help message"); 39 | } 40 | 41 | public static void show_version() { 42 | log.info("ksar Version : {}", VersionNumber.getVersionString()); 43 | } 44 | 45 | private static void set_lookandfeel() { 46 | for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { 47 | if (Config.getLandf().equals(laf.getName())) { 48 | try { 49 | UIManager.setLookAndFeel(laf.getClassName()); 50 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 51 | log.error("lookandfeel Exception", ex); 52 | } 53 | } 54 | } 55 | } 56 | 57 | public static void make_ui() { 58 | 59 | log.trace("MainScreen"); 60 | set_lookandfeel(); 61 | 62 | javax.swing.SwingUtilities.invokeLater(() -> { 63 | GlobalOptions.setUI(new Desktop()); 64 | SwingUtilities.updateComponentTreeUI(GlobalOptions.getUI()); 65 | GlobalOptions.getUI().add_window(); 66 | GlobalOptions.getUI().maxall(); 67 | }); 68 | 69 | } 70 | 71 | public static void main(String[] args) { 72 | int i = 0; 73 | String arg; 74 | 75 | ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); 76 | 77 | log.info("ksar Version : {}", VersionNumber.getVersionString()); 78 | log.info("Java runtime Version : {}", System.getProperty("java.runtime.version")); 79 | log.info("Java runtime architecture : {}", System.getProperty("os.arch")); 80 | 81 | /// load default - Mac OS X Application Properties 82 | String mrjVersion = System.getProperty("mrj.version"); 83 | if (mrjVersion != null) { 84 | System.setProperty("com.apple.mrj.application.growbox.intrudes", "false"); 85 | System.setProperty("com.apple.mrj.application.apple.menu.about.name", "kSar"); 86 | System.setProperty("apple.laf.useScreenMenuBar", "true"); 87 | } 88 | 89 | config = Config.getInstance(); 90 | globaloptions = GlobalOptions.getInstance(); 91 | 92 | 93 | if (args.length > 0) { 94 | while (i < args.length && args[i].startsWith("-")) { 95 | arg = args[i++]; 96 | if ("-version".equals(arg)) { 97 | show_version(); 98 | System.exit(0); 99 | } 100 | if ("-help".equals(arg) || "--help".equals(arg) || "-h".equals(arg)) { 101 | usage(); 102 | System.exit(0); 103 | } 104 | if ("-test".equals(arg) || "-debug".equals(arg)) { 105 | root.setLevel(Level.DEBUG); 106 | continue; 107 | } 108 | if ("-trace".equals(arg)) { 109 | root.setLevel(Level.TRACE); 110 | continue; 111 | } 112 | if ("-input".equals(arg)) { 113 | if (i < args.length) { 114 | GlobalOptions.setCLfilename(args[i++]); 115 | continue; 116 | } else { 117 | exit_error(resource.getString("INPUT_REQUIRE_ARG")); 118 | } 119 | } 120 | exit_error(resource.getString("UNKNOWN_OPTION"), arg); 121 | } 122 | 123 | if (i < args.length) { 124 | exit_error(resource.getString("TOO_MANY_ARGUMENTS"), 125 | String.join(" ", Arrays.copyOfRange(args, i, args.length))); 126 | } 127 | } 128 | 129 | make_ui(); 130 | 131 | } 132 | 133 | public static void exit_error(final String format, final String... args) { 134 | log.error(format, (Object[]) args); 135 | System.exit(1); 136 | 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/OSParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import net.atomique.ksar.xml.OSConfig; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.time.DateTimeException; 13 | import java.time.format.DateTimeFormatter; 14 | import java.time.format.FormatStyle; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | public abstract class OSParser extends AllParser { 19 | 20 | private static final Logger log = LoggerFactory.getLogger(OSParser.class); 21 | 22 | public OSParser() { 23 | 24 | } 25 | 26 | public void init(kSar hissar, String header) { 27 | 28 | log.debug("Initialize Parser: {}", this.getClass().getName()); 29 | String parserName = header.split("\\s+", 2)[0]; 30 | mysar = hissar; 31 | ParserName = parserName; 32 | myosconfig = GlobalOptions.getOSinfo(parserName); 33 | parse_header(header); 34 | } 35 | 36 | public OSParser(kSar hissar, String header) { 37 | init(hissar, header); 38 | } 39 | 40 | 41 | public OSConfig get_OSConfig() { 42 | return myosconfig; 43 | } 44 | 45 | 46 | public void setHostname(String s) { 47 | Hostname = s; 48 | } 49 | 50 | public void setOSversion(String s) { 51 | OSversion = s; 52 | } 53 | 54 | public void setKernel(String s) { 55 | Kernel = s; 56 | } 57 | 58 | public void setCpuType(String s) { 59 | CpuType = s; 60 | } 61 | 62 | 63 | public void setMacAddress(String s) { 64 | MacAddress = s; 65 | } 66 | 67 | public void setMemory(String s) { 68 | Memory = s; 69 | } 70 | 71 | public void setNBDisk(String s) { 72 | NBDisk = s; 73 | } 74 | 75 | public void setNBCpu(String s) { 76 | NBCpu = s; 77 | } 78 | 79 | public void setENT(String s) { 80 | ENT = s; 81 | } 82 | 83 | 84 | public String getInfo() { 85 | StringBuilder tmpstr = new StringBuilder(); 86 | tmpstr.append("OS Type: ").append(ostype); 87 | if (OSversion != null) { 88 | tmpstr.append("OS Version: ").append(OSversion).append("\n"); 89 | } 90 | if (Kernel != null) { 91 | tmpstr.append("Kernel Release: ").append(Kernel).append("\n"); 92 | } 93 | if (CpuType != null) { 94 | tmpstr.append("CPU Type: ").append(CpuType).append("\n"); 95 | } 96 | if (Hostname != null) { 97 | tmpstr.append("Hostname: ").append(Hostname).append("\n"); 98 | } 99 | if (MacAddress != null) { 100 | tmpstr.append("Mac Address: ").append(MacAddress).append("\n"); 101 | } 102 | if (Memory != null) { 103 | tmpstr.append("Memory: ").append(Memory).append("\n"); 104 | } 105 | if (NBDisk != null) { 106 | tmpstr.append("Number of disks: ").append(NBDisk).append("\n"); 107 | } 108 | if (NBCpu != null) { 109 | tmpstr.append("Number of CPU: ").append(NBCpu).append("\n"); 110 | } 111 | if (ENT != null) { 112 | tmpstr.append("Ent: ").append(ENT).append("\n"); 113 | } 114 | if (sarStartDate != null) { 115 | tmpstr.append("Start of SAR: ").append(sarStartDate).append("\n"); 116 | } 117 | if (sarEndDate != null) { 118 | tmpstr.append("End of SAR: ").append(sarEndDate).append("\n"); 119 | } 120 | 121 | tmpstr.append("\n"); 122 | 123 | return tmpstr.toString(); 124 | } 125 | 126 | 127 | public String gethostName() { 128 | return Hostname; 129 | } 130 | 131 | public String getOstype() { 132 | return ostype; 133 | } 134 | 135 | public void setOstype(String ostype) { 136 | this.ostype = ostype; 137 | } 138 | 139 | final public void updateUITitle() { 140 | if (mysar.getDataView() != null) { 141 | 142 | String asFormattedDateTimeStart = null; 143 | String asFormattedDateTimeEnd = null; 144 | 145 | try { 146 | 147 | //Locale test = new Locale(System.getProperty("user.language"), System.getProperty("user.country")); 148 | DateTimeFormatter formatter = 149 | DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); //.withLocale(test); 150 | 151 | if (this.getStartOfGraph() != null) { 152 | asFormattedDateTimeStart = this.getStartOfGraph().format(formatter); 153 | } 154 | if (this.getEndOfGraph() != null) { 155 | //asFormattedDateTimeEnd = endofgraph.format(DateTimeFormatter.ISO_DATE_TIME); 156 | asFormattedDateTimeEnd = this.getEndOfGraph().format(formatter); 157 | } 158 | 159 | } catch (DateTimeException ex) { 160 | log.error("unable to format time", ex); 161 | } 162 | 163 | if (asFormattedDateTimeStart != null && asFormattedDateTimeEnd != null) { 164 | mysar.getDataView() 165 | .setTitle(String.format("%s from %s to %s", Hostname, asFormattedDateTimeStart, 166 | asFormattedDateTimeEnd)); 167 | } 168 | } 169 | } 170 | 171 | protected Map ListofGraph = new HashMap(); 172 | 173 | protected String lastStat = null; 174 | protected Object currentStatObj = null; 175 | 176 | protected String ostype = null; 177 | protected String Hostname = null; 178 | protected String OSversion = null; 179 | protected String Kernel = null; 180 | protected String CpuType = null; 181 | protected String MacAddress = null; 182 | protected String Memory = null; 183 | protected String NBDisk = null; 184 | protected String NBCpu = null; 185 | protected String ENT = null; 186 | 187 | } 188 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/VersionNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.BufferedReader; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.InputStreamReader; 15 | 16 | public final class VersionNumber { 17 | 18 | private static final Logger log = LoggerFactory.getLogger(VersionNumber.class); 19 | 20 | static { 21 | 22 | StringBuilder tmpstr = new StringBuilder(); 23 | 24 | InputStream is = VersionNumber.class.getClassLoader().getResourceAsStream("kSar.version"); 25 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { 26 | 27 | String line; 28 | while ((line = reader.readLine()) != null) { 29 | tmpstr.append(line); 30 | } 31 | 32 | version_string = tmpstr.toString(); 33 | 34 | } catch (IOException ex) { 35 | log.error("Unable to read ksar version", ex); 36 | } 37 | } 38 | 39 | public static String getVersionString() { 40 | return version_string; 41 | } 42 | 43 | private static String version_string; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/export/FileCSV.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.export; 7 | 8 | import net.atomique.ksar.graph.Graph; 9 | import net.atomique.ksar.kSar; 10 | import net.atomique.ksar.ui.SortedTreeNode; 11 | import net.atomique.ksar.ui.TreeNodeInfo; 12 | import org.jfree.data.time.RegularTimePeriod; 13 | import org.jfree.data.time.Second; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | import java.io.BufferedWriter; 18 | import java.io.IOException; 19 | import java.nio.charset.StandardCharsets; 20 | import java.nio.file.Files; 21 | import java.nio.file.Paths; 22 | import java.time.LocalDateTime; 23 | import java.time.format.DateTimeFormatter; 24 | import javax.swing.JDialog; 25 | import javax.swing.JProgressBar; 26 | 27 | public class FileCSV implements Runnable { 28 | 29 | private static final Logger log = LoggerFactory.getLogger(FileCSV.class); 30 | 31 | public FileCSV(String filename, kSar hissar) { 32 | csvfilename = filename; 33 | mysar = hissar; 34 | } 35 | 36 | public FileCSV(String filename, kSar hissar, JProgressBar g, JDialog d) { 37 | this(filename, hissar); 38 | 39 | progress_bar = g; 40 | dialog = d; 41 | } 42 | 43 | public void run() { 44 | 45 | // print header 46 | tmpcsv.append("Date;"); 47 | 48 | export_treenode_header(mysar.graphtree); 49 | tmpcsv.append("\n"); 50 | 51 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yy HH:mm:ss"); 52 | 53 | for (LocalDateTime tmpLDT : mysar.myparser.getDateSamples()) { 54 | 55 | String text = tmpLDT.format(formatter); 56 | tmpcsv.append(text).append(";"); 57 | 58 | Second tmp = new Second(tmpLDT.getSecond(), 59 | tmpLDT.getMinute(), 60 | tmpLDT.getHour(), 61 | tmpLDT.getDayOfMonth(), 62 | tmpLDT.getMonthValue(), 63 | tmpLDT.getYear()); 64 | 65 | export_treenode_data(mysar.graphtree, tmp); 66 | tmpcsv.append("\n"); 67 | 68 | } 69 | 70 | try (BufferedWriter out = Files.newBufferedWriter( Paths.get(csvfilename), StandardCharsets.UTF_8)) { 71 | 72 | out.write(tmpcsv.toString()); 73 | 74 | } catch (IOException ex) { 75 | log.error("CSV IO Exception", ex); 76 | } 77 | 78 | if (dialog != null) { 79 | dialog.dispose(); 80 | } 81 | } 82 | 83 | private void export_treenode_header(SortedTreeNode node) { 84 | int num = node.getChildCount(); 85 | 86 | if (num > 0) { 87 | /*Object obj1 = node.getUserObject(); 88 | if (obj1 instanceof ParentNodeInfo) { 89 | ParentNodeInfo tmpnode = (ParentNodeInfo) obj1; 90 | List nodeobj = tmpnode.getNode_object(); 91 | }*/ 92 | for (int i = 0; i < num; i++) { 93 | SortedTreeNode l = (SortedTreeNode) node.getChildAt(i); 94 | export_treenode_header(l); 95 | } 96 | } else { 97 | Object obj1 = node.getUserObject(); 98 | if (obj1 instanceof TreeNodeInfo) { 99 | TreeNodeInfo tmpnode = (TreeNodeInfo) obj1; 100 | Graph nodeobj = tmpnode.getNode_object(); 101 | if (nodeobj.doPrint()) { 102 | tmpcsv.append(nodeobj.getCsvHeader()); 103 | 104 | } 105 | } 106 | } 107 | } 108 | 109 | private void export_treenode_data(SortedTreeNode node, RegularTimePeriod time) { 110 | int num = node.getChildCount(); 111 | 112 | if (num > 0) { 113 | /*Object obj1 = node.getUserObject(); 114 | if (obj1 instanceof ParentNodeInfo) { 115 | ParentNodeInfo tmpnode = (ParentNodeInfo) obj1; 116 | List nodeobj = tmpnode.getNode_object(); 117 | }*/ 118 | for (int i = 0; i < num; i++) { 119 | SortedTreeNode l = (SortedTreeNode) node.getChildAt(i); 120 | export_treenode_data(l, time); 121 | } 122 | } else { 123 | Object obj1 = node.getUserObject(); 124 | if (obj1 instanceof TreeNodeInfo) { 125 | TreeNodeInfo tmpnode = (TreeNodeInfo) obj1; 126 | Graph nodeobj = tmpnode.getNode_object(); 127 | if (nodeobj.doPrint()) { 128 | tmpcsv.append(nodeobj.getCsvLine(time)); 129 | update_ui(); 130 | 131 | } 132 | } 133 | } 134 | } 135 | 136 | private void update_ui() { 137 | if (progress_bar != null) { 138 | progress_bar.setValue(++progress_info); 139 | progress_bar.repaint(); 140 | } 141 | 142 | } 143 | 144 | private final StringBuilder tmpcsv = new StringBuilder(); 145 | private int progress_info = 0; 146 | private final String csvfilename; 147 | private final kSar mysar; 148 | private JProgressBar progress_bar = null; 149 | private JDialog dialog = null; 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/graph/IEEE1541Number.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.graph; 7 | 8 | import java.text.DecimalFormat; 9 | import java.text.FieldPosition; 10 | import java.text.NumberFormat; 11 | import java.text.ParsePosition; 12 | 13 | public class IEEE1541Number extends NumberFormat { 14 | 15 | private final static double IEC_kibi = 1024.0; 16 | private final static double IEC_mebi = 1048576.0; 17 | private final static double IEC_gibi = 1073741824.0; 18 | 19 | /* 20 | public IEEE1541Number() { 21 | } 22 | */ 23 | 24 | public IEEE1541Number(int value) { 25 | kilo = value; 26 | } 27 | 28 | public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { 29 | DecimalFormat formatter = new DecimalFormat("#,##0.0"); 30 | 31 | if (kilo == 0) { 32 | return toAppendTo.append(formatter.format(number)); 33 | } 34 | if ((number * kilo) < IEC_kibi) { 35 | return toAppendTo.append(formatter.format(number)); 36 | } 37 | if ((number * kilo) < IEC_mebi) { 38 | 39 | toAppendTo.append(formatter.format((number * kilo) / IEC_kibi)).append(" Ki"); 40 | return toAppendTo; 41 | } 42 | if ((number * kilo) < (IEC_gibi)) { 43 | toAppendTo.append(formatter.format((number * kilo) / (IEC_mebi))).append(" Mi"); 44 | return toAppendTo; 45 | } 46 | 47 | toAppendTo.append(formatter.format((number * kilo) / (IEC_gibi))).append(" Gi"); 48 | return toAppendTo; 49 | } 50 | 51 | public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { 52 | return format((double) (number * kilo), toAppendTo, pos); 53 | } 54 | 55 | public Number parse(String source, ParsePosition parsePosition) { 56 | return null; 57 | } 58 | 59 | private int kilo = 0; 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/graph/ISNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.graph; 7 | 8 | import java.text.DecimalFormat; 9 | import java.text.FieldPosition; 10 | import java.text.NumberFormat; 11 | import java.text.ParsePosition; 12 | 13 | public class ISNumber extends NumberFormat { 14 | 15 | private final static double IS_kilo = 1000.0; 16 | private final static double IS_mega = 1000000.0; 17 | private final static double IS_giga = 1000000000.0; 18 | 19 | /* 20 | public ISNumber() { 21 | } 22 | */ 23 | 24 | public ISNumber(int value) { 25 | kilo = value; 26 | } 27 | 28 | public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { 29 | DecimalFormat formatter = new DecimalFormat("#,##0.0"); 30 | 31 | if (kilo == 0) { 32 | return toAppendTo.append(formatter.format(number)); 33 | } 34 | if ((number * kilo) < IS_kilo) { 35 | return toAppendTo.append(formatter.format(number)); 36 | } 37 | if ((number * kilo) < IS_mega) { 38 | 39 | toAppendTo.append(formatter.format((number * kilo) / IS_kilo)).append(" K"); 40 | return toAppendTo; 41 | } 42 | if ((number * kilo) < (IS_giga)) { 43 | toAppendTo.append(formatter.format((number * kilo) / (IS_mega))).append(" M"); 44 | return toAppendTo; 45 | } 46 | 47 | toAppendTo.append(formatter.format((number * kilo) / (IS_giga))).append(" G"); 48 | return toAppendTo; 49 | } 50 | 51 | public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { 52 | return format((double) (number * kilo), toAppendTo, pos); 53 | } 54 | 55 | public Number parse(String source, ParsePosition parsePosition) { 56 | return null; 57 | } 58 | 59 | private int kilo = 0; 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/graph/List.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.graph; 7 | 8 | import net.atomique.ksar.kSar; 9 | import net.atomique.ksar.ui.NaturalComparator; 10 | import net.atomique.ksar.ui.ParentNodeInfo; 11 | import net.atomique.ksar.ui.SortedTreeNode; 12 | import net.atomique.ksar.ui.TreeNodeInfo; 13 | import net.atomique.ksar.xml.GraphConfig; 14 | import org.jfree.data.time.Second; 15 | 16 | import java.awt.LayoutManager; 17 | import java.time.LocalDateTime; 18 | import java.util.SortedMap; 19 | import java.util.TreeMap; 20 | import javax.swing.JPanel; 21 | import javax.swing.border.TitledBorder; 22 | 23 | public class List { 24 | 25 | public List(kSar hissar, GraphConfig g, String stitle, String sheader, int firstdatacolumn) { 26 | mysar = hissar; 27 | HeaderStr = sheader; 28 | graphconfig = g; 29 | Title = stitle; 30 | FirstDataColumn = firstdatacolumn; 31 | ParentNodeInfo tmp = new ParentNodeInfo(Title, this); 32 | parentTreeNode = new SortedTreeNode(tmp); 33 | mysar.add2tree(mysar.graphtree, parentTreeNode); 34 | } 35 | 36 | public int parse_line(LocalDateTime ldt, String s) { 37 | 38 | Second now = new Second(ldt.getSecond(), 39 | ldt.getMinute(), 40 | ldt.getHour(), 41 | ldt.getDayOfMonth(), 42 | ldt.getMonthValue(), 43 | ldt.getYear()); 44 | 45 | return parse_line(now, s); 46 | } 47 | 48 | public int parse_line(Second now, String s) { 49 | String[] cols = s.split("\\s+"); 50 | Graph tmp; 51 | if (!nodeHashList.containsKey(cols[FirstDataColumn])) { 52 | tmp = new Graph(mysar, graphconfig, Title + " " + cols[FirstDataColumn], HeaderStr, FirstDataColumn + 1, 53 | null); 54 | nodeHashList.put(cols[FirstDataColumn], tmp); 55 | TreeNodeInfo infotmp = new TreeNodeInfo(cols[FirstDataColumn], tmp); 56 | SortedTreeNode nodetmp = new SortedTreeNode(infotmp); 57 | mysar.add2tree(parentTreeNode, nodetmp); 58 | } else { 59 | tmp = nodeHashList.get(cols[FirstDataColumn]); 60 | } 61 | 62 | return tmp.parse_line(now, s); 63 | } 64 | 65 | 66 | public JPanel run() { 67 | JPanel tmppanel = new JPanel(); 68 | LayoutManager tmplayout; 69 | int graphnumber = nodeHashList.size(); 70 | int linenum = (int) Math.floor(graphnumber / 2); 71 | if (graphnumber % 2 != 0) { 72 | linenum++; 73 | } 74 | tmplayout = new java.awt.GridLayout(linenum, 2); 75 | tmppanel.setLayout(tmplayout); 76 | 77 | 78 | for (Graph graph : nodeHashList.values()) { 79 | tmppanel.add(graph.get_ChartPanel()); 80 | } 81 | 82 | return tmppanel; 83 | } 84 | 85 | public boolean isPrintSelected() { 86 | boolean leaftoprint = false; 87 | for (Graph graph : nodeHashList.values()) { 88 | if (graph.isPrintSelected()) { 89 | leaftoprint = true; 90 | break; 91 | } 92 | } 93 | return leaftoprint; 94 | } 95 | 96 | public String getTitle() { 97 | return Title; 98 | } 99 | 100 | public JPanel getprintform() { 101 | JPanel panel = new JPanel(); 102 | panel.setBorder(new TitledBorder(Title)); 103 | panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.PAGE_AXIS)); 104 | return panel; 105 | } 106 | 107 | 108 | protected GraphConfig graphconfig = null; 109 | protected SortedTreeNode parentTreeNode = null; 110 | protected kSar mysar = null; 111 | protected String HeaderStr = null; 112 | protected SortedMap nodeHashList = new TreeMap<>(NaturalComparator.NULLS_FIRST); 113 | protected int FirstDataColumn = 0; 114 | protected String Title = null; 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/kSar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar; 7 | 8 | import net.atomique.ksar.graph.Graph; 9 | import net.atomique.ksar.ui.DataView; 10 | import net.atomique.ksar.ui.SortedTreeNode; 11 | import net.atomique.ksar.ui.TreeNodeInfo; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.beans.PropertyVetoException; 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.lang.reflect.InvocationTargetException; 19 | import javax.swing.JDesktopPane; 20 | 21 | public class kSar { 22 | 23 | private static final Logger log = LoggerFactory.getLogger(kSar.class); 24 | 25 | public kSar(JDesktopPane DesktopPane) { 26 | dataview = new DataView(this); 27 | dataview.toFront(); 28 | dataview.setVisible(true); 29 | dataview.setTitle("Empty"); 30 | DesktopPane.add(dataview); 31 | try { 32 | int num = DesktopPane.getAllFrames().length; 33 | if (num != 1) { 34 | dataview.reshape(5 * num, 5 * num, 800, 600); 35 | } else { 36 | dataview.reshape(0, 0, 800, 600); 37 | } 38 | dataview.setSelected(true); 39 | } catch (PropertyVetoException vetoe) { 40 | log.error("PropertyVetoException", vetoe); 41 | } 42 | if (GlobalOptions.getCLfilename() != null) { 43 | do_fileread(GlobalOptions.getCLfilename()); 44 | } 45 | } 46 | 47 | public kSar() { 48 | } 49 | 50 | public void do_fileread(String filename) { 51 | if (filename == null) { 52 | launched_action = new FileRead(this); 53 | } else { 54 | launched_action = new FileRead(this, filename); 55 | } 56 | reload_action = ((FileRead) launched_action).get_action(); 57 | do_action(); 58 | } 59 | 60 | public void do_localcommand(String cmd) { 61 | if (cmd == null) { 62 | launched_action = new LocalCommand(this); 63 | } else { 64 | launched_action = new LocalCommand(this, cmd); 65 | } 66 | reload_action = ((LocalCommand) launched_action).get_action(); 67 | do_action(); 68 | } 69 | 70 | public void do_sshread(String cmd) { 71 | if (cmd == null) { 72 | launched_action = new SSHCommand(this); 73 | //mysar.reload_command=t.get_command(); 74 | } else { 75 | launched_action = new SSHCommand(this, cmd); 76 | } 77 | 78 | reload_action = ((SSHCommand) launched_action).get_action(); 79 | do_action(); 80 | } 81 | 82 | private void do_action() { 83 | if (reload_action == null) { 84 | log.info("action is null"); 85 | return; 86 | } 87 | if (launched_action != null) { 88 | if (dataview != null) { 89 | dataview.notifyrun(true); 90 | } 91 | launched_action.start(); 92 | } 93 | } 94 | 95 | public int parse(BufferedReader br) { 96 | String current_line; 97 | long parsing_start; 98 | long parsing_end; 99 | String[] columns; 100 | int parser_return; 101 | 102 | parsing_start = System.currentTimeMillis(); 103 | 104 | try { 105 | while ((current_line = br.readLine()) != null && !action_interrupted) { 106 | Parsing = true; 107 | 108 | lines_parsed++; 109 | if (current_line.length() == 0) { 110 | continue; 111 | } 112 | columns = current_line.split("\\s+"); 113 | 114 | if (columns.length == 0) { 115 | continue; 116 | } 117 | 118 | //log.debug("Header Line : {}", current_line); 119 | String firstColumn = columns[0]; 120 | 121 | try { 122 | Class classtmp = GlobalOptions.getParser(firstColumn); 123 | if (classtmp != null) { 124 | if (myparser == null) { 125 | myparser = (OSParser) classtmp.getDeclaredConstructor().newInstance(); 126 | myparser.init(this, current_line); 127 | 128 | continue; 129 | } else { 130 | if (myparser.getParserName().equals(firstColumn)) { 131 | myparser.parse_header(current_line); 132 | continue; 133 | } 134 | } 135 | } 136 | } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { 137 | log.error("Parser Exception", ex); 138 | } 139 | 140 | 141 | if (myparser == null) { 142 | log.error("unknown parser: {}", firstColumn); 143 | Parsing = false; 144 | return -1; 145 | } 146 | 147 | parser_return = myparser.parse(current_line, columns); 148 | 149 | switch (parser_return) { 150 | 151 | case 0: 152 | break; 153 | 154 | case 1: 155 | log.trace("L{} {}", lines_parsed, current_line); 156 | break; 157 | 158 | case 2: 159 | log.trace("L{}
{}", lines_parsed, current_line); 160 | break; 161 | 162 | case 3: 163 | log.trace("L{} {}", lines_parsed, current_line); 164 | break; 165 | 166 | case -1: 167 | log.error("L{} {}", lines_parsed, current_line); 168 | break; 169 | 170 | default: 171 | log.error("L{} PARSE unexpected return value: {}", lines_parsed, parser_return); 172 | } 173 | 174 | myparser.updateUITitle(); 175 | } 176 | } catch (IOException ex) { 177 | log.error("IO Exception", ex); 178 | Parsing = false; 179 | } 180 | 181 | if (dataview != null) { 182 | dataview.treehome(); 183 | dataview.notifyrun(false); 184 | dataview.setHasData(true); 185 | } 186 | 187 | parsing_end = System.currentTimeMillis(); 188 | log.debug("time to parse: {} ms", (parsing_end - parsing_start)); 189 | log.debug("lines parsed: {}", lines_parsed); 190 | if (myparser != null) { 191 | log.debug("number of datesamples: {}", myparser.DateSamples.size()); 192 | } 193 | Parsing = false; 194 | return -1; 195 | } 196 | 197 | void cleared() { 198 | aborted(); 199 | } 200 | 201 | private void aborted() { 202 | if (dataview != null) { 203 | log.trace("reset menu"); 204 | dataview.notifyrun(false); 205 | } 206 | } 207 | 208 | public void interrupt_parsing() { 209 | if (isParsing()) { 210 | action_interrupted = true; 211 | } 212 | } 213 | 214 | public void add2tree(SortedTreeNode parent, SortedTreeNode newNode) { 215 | if (dataview != null) { 216 | dataview.add2tree(parent, newNode); 217 | } 218 | } 219 | 220 | public int get_page_to_print() { 221 | page_to_print = 0; 222 | count_printSelected(graphtree); 223 | return page_to_print; 224 | } 225 | 226 | private void count_printSelected(SortedTreeNode node) { 227 | int num = node.getChildCount(); 228 | 229 | if (num > 0) { 230 | for (int i = 0; i < num; i++) { 231 | SortedTreeNode l = (SortedTreeNode) node.getChildAt(i); 232 | count_printSelected(l); 233 | } 234 | } else { 235 | Object obj1 = node.getUserObject(); 236 | if (obj1 instanceof TreeNodeInfo) { 237 | TreeNodeInfo tmpnode = (TreeNodeInfo) obj1; 238 | Graph nodeobj = tmpnode.getNode_object(); 239 | if (nodeobj.isPrintSelected()) { 240 | page_to_print++; 241 | } 242 | } 243 | } 244 | } 245 | 246 | DataView getDataView() { 247 | return dataview; 248 | } 249 | 250 | public boolean isParsing() { 251 | return Parsing; 252 | } 253 | 254 | private DataView dataview = null; 255 | private long lines_parsed; 256 | private String reload_action = "Empty"; 257 | private Thread launched_action = null; 258 | private boolean action_interrupted = false; 259 | public OSParser myparser = null; 260 | private boolean Parsing = false; 261 | public SortedTreeNode graphtree = new SortedTreeNode("kSar"); 262 | private int page_to_print = 0; 263 | } 264 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/parser/AIX.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import net.atomique.ksar.OSParser; 9 | import net.atomique.ksar.graph.Graph; 10 | import net.atomique.ksar.graph.List; 11 | import net.atomique.ksar.xml.GraphConfig; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.time.LocalDateTime; 16 | import java.time.LocalTime; 17 | import java.time.format.DateTimeFormatter; 18 | import java.time.format.DateTimeParseException; 19 | 20 | public class AIX extends OSParser { 21 | 22 | private static final Logger log = LoggerFactory.getLogger(AIX.class); 23 | 24 | boolean under_average = false; 25 | 26 | public void parse_header(String s) { 27 | String[] columns = s.split("\\s+"); 28 | 29 | setOstype(columns[0]); 30 | setHostname(columns[1]); 31 | setOSversion(columns[2] + "." + columns[3]); 32 | setMacAddress(columns[4]); 33 | setDate(columns[5]); 34 | 35 | } 36 | 37 | @Override 38 | public int parse(String line, String[] columns) { 39 | 40 | if ("Average".equals(columns[0])) { 41 | under_average = true; 42 | return 0; 43 | } 44 | 45 | if (line.indexOf("unix restarts") >= 0 || line.indexOf(" unix restarted") >= 0) { 46 | return 0; 47 | } 48 | 49 | // match the System [C|c]onfiguration line on AIX 50 | if (line.indexOf("System Configuration") >= 0 || line.indexOf("System configuration") >= 0) { 51 | return 0; 52 | } 53 | 54 | if (line.indexOf("State change") >= 0) { 55 | return 0; 56 | } 57 | 58 | 59 | try { 60 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeFormat); 61 | parsetime = LocalTime.parse(columns[0], formatter); 62 | 63 | LocalDateTime nowStat; 64 | nowStat = LocalDateTime.of(parsedate, parsetime); 65 | 66 | this.setStartAndEndOfGraph(nowStat); 67 | firstdatacolumn = 1; 68 | } catch (DateTimeParseException ex) { 69 | if (!"DEVICE".equals(currentStat) || "CPUS".equals(currentStat)) { 70 | log.error("unable to parse time {}", columns[0], ex); 71 | return -1; 72 | } 73 | firstdatacolumn = 0; 74 | } 75 | 76 | 77 | /** XML COLUMN PARSER **/ 78 | String checkStat = myosconfig.getStat(columns, firstdatacolumn); 79 | 80 | if (checkStat != null) { 81 | Object obj = ListofGraph.get(checkStat); 82 | if (obj == null) { 83 | GraphConfig mygraphinfo = myosconfig.getGraphConfig(checkStat); 84 | if (mygraphinfo != null) { 85 | if ("unique".equals(mygraphinfo.getType())) { 86 | obj = new Graph(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn, 87 | mysar.graphtree); 88 | ListofGraph.put(checkStat, obj); 89 | currentStat = checkStat; 90 | return 0; 91 | } 92 | if ("multiple".equals(mygraphinfo.getType())) { 93 | obj = new List(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn); 94 | ListofGraph.put(checkStat, obj); 95 | currentStat = checkStat; 96 | return 0; 97 | } 98 | } else { 99 | // no graph associate 100 | currentStat = checkStat; 101 | return 0; 102 | } 103 | } else { 104 | currentStat = checkStat; 105 | return 0; 106 | } 107 | } 108 | 109 | //log.trace("{} {}", currentStat, line); 110 | 111 | 112 | if (lastStat != null) { 113 | if (!lastStat.equals(currentStat)) { 114 | 115 | log.debug("Stat change from {} to {}", lastStat, currentStat); 116 | 117 | lastStat = currentStat; 118 | under_average = false; 119 | } 120 | } else { 121 | lastStat = currentStat; 122 | } 123 | 124 | if ("IGNORE".equals(currentStat)) { 125 | return 1; 126 | } 127 | if ("NONE".equals(currentStat)) { 128 | return -1; 129 | } 130 | 131 | if (under_average) { 132 | return 0; 133 | } 134 | currentStatObj = ListofGraph.get(currentStat); 135 | if (currentStatObj == null) { 136 | return -1; 137 | } else { 138 | 139 | LocalDateTime nowStat = LocalDateTime.of(parsedate, parsetime); 140 | 141 | DateSamples.add(nowStat); 142 | 143 | if (currentStatObj instanceof Graph) { 144 | Graph ag = (Graph) currentStatObj; 145 | return ag.parse_line(nowStat, line); 146 | } 147 | if (currentStatObj instanceof List) { 148 | List ag = (List) currentStatObj; 149 | return ag.parse_line(nowStat, line); 150 | } 151 | } 152 | return -1; 153 | } 154 | 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/parser/HPUX.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import net.atomique.ksar.OSParser; 9 | import net.atomique.ksar.graph.Graph; 10 | import net.atomique.ksar.graph.List; 11 | import net.atomique.ksar.xml.GraphConfig; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.time.LocalDateTime; 16 | import java.time.LocalTime; 17 | import java.time.format.DateTimeFormatter; 18 | import java.time.format.DateTimeParseException; 19 | 20 | public class HPUX extends OSParser { 21 | 22 | private static final Logger log = LoggerFactory.getLogger(HPUX.class); 23 | 24 | boolean under_average = false; 25 | 26 | public void parse_header(String s) { 27 | String[] columns = s.split("\\s+"); 28 | setOstype(columns[0]); 29 | setHostname(columns[1]); 30 | setOSversion(columns[2]); 31 | setKernel(columns[3]); 32 | setCpuType(columns[4]); 33 | setDate(columns[5]); 34 | 35 | } 36 | 37 | 38 | @Override 39 | public int parse(String line, String[] columns) { 40 | 41 | if ("Average".equals(columns[0])) { 42 | under_average = true; 43 | return 0; 44 | } 45 | 46 | if (line.indexOf("unix restarts") >= 0 || line.indexOf(" unix restarted") >= 0) { 47 | return 0; 48 | } 49 | 50 | // match the System [C|c]onfiguration line on AIX 51 | if (line.indexOf("System Configuration") >= 0 || line.indexOf("System configuration") >= 0) { 52 | return 0; 53 | } 54 | 55 | if (line.indexOf("State change") >= 0) { 56 | return 0; 57 | } 58 | 59 | 60 | try { 61 | timeFormat = "HH:mm:ss"; 62 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeFormat); 63 | parsetime = LocalTime.parse(columns[0], formatter); 64 | 65 | LocalDateTime nowStat; 66 | nowStat = LocalDateTime.of(parsedate, parsetime); 67 | 68 | this.setStartAndEndOfGraph(nowStat); 69 | firstdatacolumn = 1; 70 | } catch (DateTimeParseException ex) { 71 | if (!"DEVICE".equals(currentStat) && !"CPU".equals(currentStat)) { 72 | log.error("unable to parse time {}", columns[0], ex); 73 | return -1; 74 | } 75 | firstdatacolumn = 0; 76 | } 77 | 78 | 79 | /** XML COLUMN PARSER **/ 80 | String checkStat = myosconfig.getStat(columns, firstdatacolumn); 81 | 82 | if (checkStat != null) { 83 | Object obj = ListofGraph.get(checkStat); 84 | if (obj == null) { 85 | GraphConfig mygraphinfo = myosconfig.getGraphConfig(checkStat); 86 | if (mygraphinfo != null) { 87 | if ("unique".equals(mygraphinfo.getType())) { 88 | obj = new Graph(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn, 89 | mysar.graphtree); 90 | ListofGraph.put(checkStat, obj); 91 | currentStat = checkStat; 92 | return 0; 93 | } 94 | if ("multiple".equals(mygraphinfo.getType())) { 95 | obj = new List(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn); 96 | ListofGraph.put(checkStat, obj); 97 | currentStat = checkStat; 98 | return 0; 99 | } 100 | } else { 101 | // no graph associate 102 | currentStat = checkStat; 103 | return 0; 104 | } 105 | } else { 106 | currentStat = checkStat; 107 | return 0; 108 | } 109 | } 110 | 111 | //log.trace("{} {}", currentStat, line); 112 | 113 | 114 | if (lastStat != null) { 115 | if (!lastStat.equals(currentStat)) { 116 | log.debug("Stat change from {} to {}", lastStat, currentStat); 117 | lastStat = currentStat; 118 | under_average = false; 119 | } 120 | } else { 121 | lastStat = currentStat; 122 | } 123 | 124 | if ("IGNORE".equals(currentStat)) { 125 | return 1; 126 | } 127 | if ("NONE".equals(currentStat)) { 128 | return -1; 129 | } 130 | 131 | if (under_average) { 132 | return 0; 133 | } 134 | currentStatObj = ListofGraph.get(currentStat); 135 | if (currentStatObj == null) { 136 | return -1; 137 | } else { 138 | 139 | LocalDateTime nowStat = LocalDateTime.of(parsedate, parsetime); 140 | 141 | DateSamples.add(nowStat); 142 | 143 | if (currentStatObj instanceof Graph) { 144 | Graph ag = (Graph) currentStatObj; 145 | return ag.parse_line(nowStat, line); 146 | } 147 | if (currentStatObj instanceof List) { 148 | List ag = (List) currentStatObj; 149 | return ag.parse_line(nowStat, line); 150 | } 151 | } 152 | return -1; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/parser/Linux.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import net.atomique.ksar.Config; 9 | import net.atomique.ksar.GlobalOptions; 10 | import net.atomique.ksar.OSParser; 11 | import net.atomique.ksar.graph.Graph; 12 | import net.atomique.ksar.graph.List; 13 | import net.atomique.ksar.ui.LinuxDateFormat; 14 | import net.atomique.ksar.xml.GraphConfig; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import java.time.LocalDateTime; 19 | import java.time.LocalTime; 20 | import java.time.format.DateTimeFormatter; 21 | import java.time.format.DateTimeParseException; 22 | import java.util.Arrays; 23 | import java.util.HashSet; 24 | import java.util.Locale; 25 | 26 | public class Linux extends OSParser { 27 | 28 | private static final Logger log = LoggerFactory.getLogger(Linux.class); 29 | private String LinuxDateFormat; 30 | private DateTimeFormatter formatter; 31 | 32 | // https://translationproject.org/domain/sysstat.html 33 | // https://github.com/sysstat/sysstat/tree/master/nls 34 | // look for - msgid "Average:" && msgid "Summary:" 35 | private final HashSet IgnoreLinesBeginningWith = new HashSet<>(Arrays.asList( 36 | "##", 37 | "Average:", "Summary:", "Summary", // en.po 38 | "Moyenne :", "Moyenne?:", "Résumé:", // fr.po (ANSI,UTF-8) 39 | "Durchschn.:", "Zusammenfassung:", // de.po 40 | "Media:", "Resumen:" // es.po 41 | )); 42 | 43 | public void parse_header(String s) { 44 | //Linux 3.10.0-1160.53.1.el7.x86_64 (hostname) 01/03/23 _x86_64_ (8 CPU) 45 | 46 | log.debug("Header Line : {}", s); 47 | String[] columns = s.split("\\s+", 5); 48 | 49 | setOstype(columns[0]); 50 | setKernel(columns[1]); 51 | 52 | // remove surrounding brackets (hostname) 53 | setHostname(columns[2].substring(1, columns[2].length() - 1)); 54 | 55 | checkDateFormat(); 56 | setDate(columns[3]); 57 | } 58 | 59 | private void checkDateFormat() { 60 | 61 | LinuxDateFormat = Config.getLinuxDateFormat(); 62 | if ("Always ask".equals(LinuxDateFormat)) { 63 | askDateFormat(); 64 | } 65 | 66 | if ("Automatic Detection".equals(LinuxDateFormat)) { 67 | dateFormat = "Automatic Detection"; 68 | timeColumn = 0; 69 | } else { 70 | 71 | // day and year format specifiers must be lowercase, month uppercase 72 | String[] parts = LinuxDateFormat.split(" ", 3); 73 | 74 | dateFormat = parts[0]; 75 | dateFormat = dateFormat.replaceAll("D{2}", "dd"); 76 | dateFormat = dateFormat.replaceAll("Y{2}", "yy"); 77 | 78 | // 12hour 79 | if (parts.length == 3 && parts[2].contains("AM|PM")) { 80 | timeFormat = "hh:mm:ss a"; 81 | timeColumn = 2; 82 | } 83 | } 84 | log.debug("Date Format: {}, Time Format: {}", dateFormat, timeFormat); 85 | } 86 | 87 | private void askDateFormat() { 88 | 89 | log.trace("askDateFormat - provide date format"); 90 | if (GlobalOptions.hasUI()) { 91 | LinuxDateFormat tmp = new LinuxDateFormat(GlobalOptions.getUI(), true); 92 | tmp.setTitle("Provide date format"); 93 | if (tmp.isOk()) { 94 | LinuxDateFormat = tmp.getDateFormat(); 95 | if (tmp.hasToRemenber()) { 96 | Config.setLinuxDateFormat(tmp.getDateFormat()); 97 | Config.save(); 98 | } 99 | } 100 | } 101 | } 102 | 103 | @Override 104 | public int parse(String line, String[] columns) { 105 | 106 | if (IgnoreLinesBeginningWith.contains(columns[0])) { 107 | currentStat = "NONE"; 108 | return 1; 109 | } 110 | 111 | if (line.contains("LINUX RESTART")) { 112 | return 1; 113 | } 114 | 115 | try { 116 | if (timeColumn == 0) { 117 | if ((columns[0] + " " + columns[1]).matches("^\\d\\d:\\d\\d:\\d\\d [AP]M$")) { 118 | timeFormat = "hh:mm:ss a"; 119 | timeColumn = 2; 120 | } else { 121 | timeColumn = 1; 122 | } 123 | } 124 | 125 | if (formatter == null) { 126 | if (timeColumn == 2) { 127 | formatter = DateTimeFormatter.ofPattern(timeFormat, Locale.US); 128 | } else { 129 | formatter = DateTimeFormatter.ofPattern(timeFormat); 130 | } 131 | log.debug("Time formatter: {}",formatter); 132 | } 133 | 134 | if (timeColumn == 2) { 135 | parsetime = LocalTime.parse(columns[0] + " " + columns[1], formatter); 136 | } else { 137 | parsetime = LocalTime.parse(columns[0], formatter); 138 | } 139 | 140 | LocalDateTime nowStat; 141 | if (parsedate != null && parsetime != null) { 142 | nowStat = LocalDateTime.of(parsedate, parsetime); 143 | } else { 144 | throw new IllegalArgumentException("date/time is missing"); 145 | } 146 | 147 | this.setStartAndEndOfGraph(nowStat); 148 | firstdatacolumn = timeColumn; 149 | } catch (DateTimeParseException | IllegalArgumentException ex) { 150 | log.error("unable to parse time {}", columns[0], ex); 151 | return -1; 152 | } 153 | 154 | // XML COLUMN PARSER 155 | String checkStat = myosconfig.getStat(columns, firstdatacolumn); 156 | if (checkStat != null) { 157 | Object obj = ListofGraph.get(checkStat); 158 | if (obj == null) { 159 | GraphConfig mygraphinfo = myosconfig.getGraphConfig(checkStat); 160 | if (mygraphinfo != null) { 161 | if ("unique".equals(mygraphinfo.getType())) { 162 | obj = new Graph(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn, 163 | mysar.graphtree); 164 | 165 | ListofGraph.put(checkStat, obj); 166 | currentStat = checkStat; 167 | return 2; 168 | } 169 | if ("multiple".equals(mygraphinfo.getType())) { 170 | obj = new List(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn); 171 | 172 | ListofGraph.put(checkStat, obj); 173 | currentStat = checkStat; 174 | return 2; 175 | } 176 | } else { 177 | // no graph associate 178 | currentStat = checkStat; 179 | return 3; 180 | } 181 | } else { 182 | currentStat = checkStat; 183 | return 2; 184 | } 185 | } 186 | 187 | if (lastStat != null) { 188 | if (!lastStat.equals(currentStat)) { 189 | log.debug("Stat change from {} to {}", lastStat, currentStat); 190 | lastStat = currentStat; 191 | } 192 | } else { 193 | lastStat = currentStat; 194 | } 195 | 196 | if ("IGNORE".equals(currentStat)) { 197 | return 0; 198 | } 199 | if ("NONE".equals(currentStat)) { 200 | return -1; 201 | } 202 | 203 | currentStatObj = ListofGraph.get(currentStat); 204 | if (currentStatObj == null) { 205 | return -1; 206 | } else { 207 | 208 | LocalDateTime nowStat = LocalDateTime.of(parsedate, parsetime); 209 | 210 | DateSamples.add(nowStat); 211 | 212 | if (currentStatObj instanceof Graph) { 213 | Graph ag = (Graph) currentStatObj; 214 | return ag.parse_line(nowStat, line); 215 | } 216 | if (currentStatObj instanceof List) { 217 | List ag = (List) currentStatObj; 218 | return ag.parse_line(nowStat, line); 219 | } 220 | } 221 | return -1; 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/parser/SunOS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import net.atomique.ksar.GlobalOptions; 9 | import net.atomique.ksar.OSParser; 10 | import net.atomique.ksar.graph.Graph; 11 | import net.atomique.ksar.graph.List; 12 | import net.atomique.ksar.ui.HostInfoView; 13 | import net.atomique.ksar.xml.GraphConfig; 14 | import net.atomique.ksar.xml.HostInfo; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import java.time.LocalDateTime; 19 | import java.time.LocalTime; 20 | import java.time.format.DateTimeFormatter; 21 | import java.time.format.DateTimeParseException; 22 | 23 | public class SunOS extends OSParser { 24 | 25 | private static final Logger log = LoggerFactory.getLogger(SunOS.class); 26 | 27 | boolean under_average = false; 28 | 29 | public void parse_header(String s) { 30 | 31 | String[] columns = s.split("\\s+"); 32 | 33 | setOstype(columns[0]); 34 | setHostname(columns[1]); 35 | setOSversion(columns[2]); 36 | setKernel(columns[3]); 37 | setCpuType(columns[4]); 38 | 39 | dateFormat = "MM/dd/yyyy"; 40 | setDate(columns[5]); 41 | 42 | if (GlobalOptions.hasUI()) { 43 | HostInfo tmphostinfo = GlobalOptions.getHostInfo(this.gethostName()); 44 | if (tmphostinfo == null) { 45 | tmphostinfo = new HostInfo(this.gethostName()); 46 | } 47 | HostInfoView tmpview = new HostInfoView(GlobalOptions.getUI(), tmphostinfo); 48 | tmpview.setVisible(true); 49 | 50 | } 51 | 52 | } 53 | 54 | @Override 55 | public int parse(String line, String[] columns) { 56 | 57 | if ("Average".equals(columns[0])) { 58 | under_average = true; 59 | return 0; 60 | } 61 | 62 | if (line.indexOf("unix restarts") >= 0 || line.indexOf(" unix restarted") >= 0) { 63 | return 0; 64 | } 65 | 66 | // match the System [C|c]onfiguration line on AIX 67 | if (line.indexOf("System Configuration") >= 0 || line.indexOf("System configuration") >= 0) { 68 | return 0; 69 | } 70 | 71 | if (line.indexOf("State change") >= 0) { 72 | return 0; 73 | } 74 | 75 | 76 | try { 77 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeFormat); 78 | parsetime = LocalTime.parse(columns[0], formatter); 79 | 80 | LocalDateTime nowStat; 81 | nowStat = LocalDateTime.of(parsedate, parsetime); 82 | 83 | this.setStartAndEndOfGraph(nowStat); 84 | firstdatacolumn = 1; 85 | } catch (DateTimeParseException ex) { 86 | if (!"DEVICE".equals(currentStat)) { 87 | log.error("unable to parse time {}", columns[0], ex); 88 | return -1; 89 | } 90 | firstdatacolumn = 0; 91 | } 92 | 93 | 94 | /** XML COLUMN PARSER **/ 95 | String checkStat = myosconfig.getStat(columns, firstdatacolumn); 96 | 97 | if (checkStat != null) { 98 | Object obj = ListofGraph.get(checkStat); 99 | if (obj == null) { 100 | GraphConfig mygraphinfo = myosconfig.getGraphConfig(checkStat); 101 | if (mygraphinfo != null) { 102 | if ("unique".equals(mygraphinfo.getType())) { 103 | obj = new Graph(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn, 104 | mysar.graphtree); 105 | ListofGraph.put(checkStat, obj); 106 | currentStat = checkStat; 107 | return 0; 108 | } 109 | if ("multiple".equals(mygraphinfo.getType())) { 110 | obj = new List(mysar, mygraphinfo, mygraphinfo.getTitle(), line, firstdatacolumn); 111 | ListofGraph.put(checkStat, obj); 112 | currentStat = checkStat; 113 | return 0; 114 | } 115 | } else { 116 | // no graph associate 117 | currentStat = checkStat; 118 | return 0; 119 | } 120 | } else { 121 | currentStat = checkStat; 122 | return 0; 123 | } 124 | } 125 | 126 | //log.trace("{} {}", currentStat, line); 127 | 128 | 129 | if (lastStat != null) { 130 | if (!lastStat.equals(currentStat)) { 131 | 132 | log.debug("Stat change from {} to {}", lastStat, currentStat); 133 | 134 | lastStat = currentStat; 135 | under_average = false; 136 | } 137 | } else { 138 | lastStat = currentStat; 139 | } 140 | if ("IGNORE".equals(currentStat)) { 141 | return 1; 142 | } 143 | if ("NONE".equals(currentStat)) { 144 | return -1; 145 | } 146 | 147 | if (under_average) { 148 | return 0; 149 | } 150 | currentStatObj = ListofGraph.get(currentStat); 151 | if (currentStatObj == null) { 152 | return -1; 153 | } else { 154 | 155 | LocalDateTime nowStat = LocalDateTime.of(parsedate, parsetime); 156 | 157 | DateSamples.add(nowStat); 158 | 159 | if (currentStatObj instanceof Graph) { 160 | Graph ag = (Graph) currentStatObj; 161 | return ag.parse_line(nowStat, line); 162 | } 163 | if (currentStatObj instanceof List) { 164 | List ag = (List) currentStatObj; 165 | return ag.parse_line(nowStat, line); 166 | } 167 | } 168 | return -1; 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/AboutBox.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 |
116 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/AboutBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import net.atomique.ksar.VersionNumber; 9 | 10 | public class AboutBox extends javax.swing.JDialog { 11 | 12 | /** 13 | * Creates new form AboutBox 14 | */ 15 | public AboutBox(java.awt.Frame parent) { 16 | super(parent); 17 | initComponents(); 18 | setLocationRelativeTo(parent); 19 | setModal(true); 20 | setVisible(true); 21 | } 22 | 23 | /** 24 | * This method is called from within the constructor to 25 | * initialize the form. 26 | * WARNING: Do NOT modify this code. The content of this method is 27 | * always regenerated by the Form Editor. 28 | */ 29 | @SuppressWarnings("unchecked") 30 | // //GEN-BEGIN:initComponents 31 | private void initComponents() { 32 | 33 | jPanel3 = new javax.swing.JPanel(); 34 | versionlabel = new javax.swing.JLabel(); 35 | jPanel2 = new javax.swing.JPanel(); 36 | urllabel = new javax.swing.JLabel(); 37 | authorlabel = new javax.swing.JLabel(); 38 | licencelabel = new javax.swing.JLabel(); 39 | tipslabel = new javax.swing.JLabel(); 40 | jPanel1 = new javax.swing.JPanel(); 41 | OkButton = new javax.swing.JButton(); 42 | 43 | setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 44 | getContentPane().setLayout( 45 | new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS)); 46 | 47 | jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); 48 | 49 | versionlabel.setText("kSar version: " + VersionNumber.getVersionString()); 50 | 51 | javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); 52 | jPanel3.setLayout(jPanel3Layout); 53 | jPanel3Layout.setHorizontalGroup( 54 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 55 | .addGap(0, 357, Short.MAX_VALUE) 56 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 57 | .addGroup(jPanel3Layout.createSequentialGroup() 58 | .addGap(0, 118, Short.MAX_VALUE) 59 | .addComponent(versionlabel) 60 | .addGap(0, 119, Short.MAX_VALUE))) 61 | ); 62 | jPanel3Layout.setVerticalGroup( 63 | jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 64 | .addGap(0, 16, Short.MAX_VALUE) 65 | .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 66 | .addGroup(jPanel3Layout.createSequentialGroup() 67 | .addGap(0, 0, Short.MAX_VALUE) 68 | .addComponent(versionlabel) 69 | .addGap(0, 0, Short.MAX_VALUE))) 70 | ); 71 | 72 | getContentPane().add(jPanel3); 73 | 74 | jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.PAGE_AXIS)); 75 | 76 | urllabel.setText("website: http://sourceforge.net/projects/ksar/"); 77 | jPanel2.add(urllabel); 78 | 79 | authorlabel.setText("Author: xavier cherif"); 80 | jPanel2.add(authorlabel); 81 | 82 | licencelabel.setText("License: BSD (see LICENCE file)"); 83 | jPanel2.add(licencelabel); 84 | 85 | tipslabel.setText("ARS LONGA, VITA BREVIS"); 86 | jPanel2.add(tipslabel); 87 | 88 | getContentPane().add(jPanel2); 89 | 90 | OkButton.setText("Ok"); 91 | OkButton.addActionListener(new java.awt.event.ActionListener() { 92 | public void actionPerformed(java.awt.event.ActionEvent evt) { 93 | OkButtonActionPerformed(evt); 94 | } 95 | }); 96 | jPanel1.add(OkButton); 97 | 98 | getContentPane().add(jPanel1); 99 | 100 | pack(); 101 | } // //GEN-END:initComponents 102 | 103 | private void OkButtonActionPerformed( 104 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_OkButtonActionPerformed 105 | setVisible(false); 106 | dispose(); 107 | } //GEN-LAST:event_OkButtonActionPerformed 108 | 109 | 110 | // Variables declaration - do not modify//GEN-BEGIN:variables 111 | private javax.swing.JButton OkButton; 112 | private javax.swing.JLabel authorlabel; 113 | private javax.swing.JPanel jPanel1; 114 | private javax.swing.JPanel jPanel2; 115 | private javax.swing.JPanel jPanel3; 116 | private javax.swing.JLabel licencelabel; 117 | private javax.swing.JLabel tipslabel; 118 | private javax.swing.JLabel urllabel; 119 | private javax.swing.JLabel versionlabel; 120 | // End of variables declaration//GEN-END:variables 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/Desktop.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/GraphSelection.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/GraphSelection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import java.awt.Component; 9 | import javax.swing.JCheckBox; 10 | import javax.swing.JPanel; 11 | 12 | public class GraphSelection extends javax.swing.JDialog { 13 | 14 | /** 15 | * Creates new form GraphSelection 16 | */ 17 | public GraphSelection(java.awt.Frame parent, boolean modal, DataView myview) { 18 | super(parent, modal); 19 | this.myview = myview; 20 | initComponents(); 21 | setLocationRelativeTo(parent); 22 | toFront(); 23 | } 24 | 25 | /** 26 | * This method is called from within the constructor to 27 | * initialize the form. 28 | * WARNING: Do NOT modify this code. The content of this method is 29 | * always regenerated by the Form Editor. 30 | */ 31 | @SuppressWarnings("unchecked") 32 | // //GEN-BEGIN:initComponents 33 | private void initComponents() { 34 | 35 | jPanel1 = new javax.swing.JPanel(); 36 | jScrollPane1 = new javax.swing.JScrollPane(); 37 | jPanel3 = new javax.swing.JPanel(); 38 | jPanel2 = new javax.swing.JPanel(); 39 | selectallButton = new javax.swing.JButton(); 40 | unselectallButton = new javax.swing.JButton(); 41 | jSeparator2 = new javax.swing.JSeparator(); 42 | cancelButton = new javax.swing.JButton(); 43 | okButton = new javax.swing.JButton(); 44 | 45 | setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 46 | 47 | jPanel1.setLayout(new java.awt.BorderLayout()); 48 | 49 | jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 400)); 50 | jScrollPane1.setRequestFocusEnabled(false); 51 | 52 | jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.PAGE_AXIS)); 53 | jScrollPane1.setViewportView(jPanel3); 54 | 55 | jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER); 56 | 57 | getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); 58 | 59 | selectallButton.setText("Select All"); 60 | selectallButton.addActionListener(new java.awt.event.ActionListener() { 61 | public void actionPerformed(java.awt.event.ActionEvent evt) { 62 | selectallButtonActionPerformed(evt); 63 | } 64 | }); 65 | jPanel2.add(selectallButton); 66 | 67 | unselectallButton.setText("Unselect All"); 68 | unselectallButton.addActionListener(new java.awt.event.ActionListener() { 69 | public void actionPerformed(java.awt.event.ActionEvent evt) { 70 | unselectallButtonActionPerformed(evt); 71 | } 72 | }); 73 | jPanel2.add(unselectallButton); 74 | 75 | jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL); 76 | jPanel2.add(jSeparator2); 77 | 78 | cancelButton.setText("Cancel"); 79 | cancelButton.addActionListener(new java.awt.event.ActionListener() { 80 | public void actionPerformed(java.awt.event.ActionEvent evt) { 81 | cancelButtonActionPerformed(evt); 82 | } 83 | }); 84 | jPanel2.add(cancelButton); 85 | 86 | okButton.setText("Ok"); 87 | okButton.addActionListener(new java.awt.event.ActionListener() { 88 | public void actionPerformed(java.awt.event.ActionEvent evt) { 89 | okButtonActionPerformed(evt); 90 | } 91 | }); 92 | jPanel2.add(okButton); 93 | 94 | getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); 95 | 96 | pack(); 97 | } // //GEN-END:initComponents 98 | 99 | private void cancelButtonActionPerformed( 100 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_cancelButtonActionPerformed 101 | this.dispose(); 102 | } //GEN-LAST:event_cancelButtonActionPerformed 103 | 104 | private void okButtonActionPerformed( 105 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_okButtonActionPerformed 106 | this.dispose(); 107 | OkforExport = true; 108 | } //GEN-LAST:event_okButtonActionPerformed 109 | 110 | private void selectallButtonActionPerformed( 111 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_selectallButtonActionPerformed 112 | toggle_checkbox(jPanel3, true); 113 | } //GEN-LAST:event_selectallButtonActionPerformed 114 | 115 | private void unselectallButtonActionPerformed( 116 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_unselectallButtonActionPerformed 117 | toggle_checkbox(jPanel3, false); 118 | } //GEN-LAST:event_unselectallButtonActionPerformed 119 | 120 | public void toggle_checkbox(JPanel panel, boolean checked) { 121 | Component[] list = panel.getComponents(); 122 | for (int i = 0; i < list.length; i++) { 123 | Component tmp = list[i]; 124 | if (tmp instanceof JPanel) { 125 | JPanel obj = (JPanel) tmp; 126 | toggle_checkbox(obj, checked); 127 | } 128 | if (tmp instanceof JCheckBox) { 129 | JCheckBox obj = (JCheckBox) tmp; 130 | obj.setSelected(checked); 131 | } 132 | } 133 | } 134 | 135 | public void addPrintCheckBox(JCheckBox tmp) { 136 | jPanel3.add(tmp); 137 | jPanel1.validate(); 138 | } 139 | 140 | public void addPrintCheckBox(JPanel tmp) { 141 | jPanel3.add(tmp); 142 | jPanel1.validate(); 143 | } 144 | 145 | // Variables declaration - do not modify//GEN-BEGIN:variables 146 | private javax.swing.JButton cancelButton; 147 | private javax.swing.JPanel jPanel1; 148 | private javax.swing.JPanel jPanel2; 149 | private javax.swing.JPanel jPanel3; 150 | private javax.swing.JScrollPane jScrollPane1; 151 | private javax.swing.JSeparator jSeparator2; 152 | private javax.swing.JButton okButton; 153 | private javax.swing.JButton selectallButton; 154 | private javax.swing.JButton unselectallButton; 155 | // End of variables declaration//GEN-END:variables 156 | private DataView myview = null; 157 | public boolean OkforExport = false; 158 | } 159 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/GraphView.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/GraphView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import net.atomique.ksar.Config; 9 | import net.atomique.ksar.GlobalOptions; 10 | import net.atomique.ksar.graph.Graph; 11 | import org.jfree.chart.ChartPanel; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.io.BufferedWriter; 16 | import java.io.File; 17 | import java.io.FileWriter; 18 | import java.io.IOException; 19 | import javax.swing.JFileChooser; 20 | import javax.swing.JOptionPane; 21 | 22 | public class GraphView extends javax.swing.JPanel { 23 | 24 | private static final Logger log = LoggerFactory.getLogger(GraphView.class); 25 | 26 | /** 27 | * Creates new form GraphView 28 | */ 29 | public GraphView() { 30 | initComponents(); 31 | } 32 | 33 | 34 | public void setGraph(Graph graph) { 35 | this.thegraph = graph; 36 | if (mychartpanel != null) { 37 | graphPanel.remove(mychartpanel); 38 | } 39 | mychartpanel = graph.get_ChartPanel(); 40 | graphPanel.add(mychartpanel); 41 | this.validate(); 42 | } 43 | 44 | /** 45 | * This method is called from within the constructor to 46 | * initialize the form. 47 | * WARNING: Do NOT modify this code. The content of this method is 48 | * always regenerated by the Form Editor. 49 | */ 50 | @SuppressWarnings("unchecked") 51 | // //GEN-BEGIN:initComponents 52 | private void initComponents() { 53 | 54 | graphPanel = new javax.swing.JPanel(); 55 | buttonPanel = new javax.swing.JPanel(); 56 | csvButton = new javax.swing.JButton(); 57 | jpgBuitton = new javax.swing.JButton(); 58 | pngButton = new javax.swing.JButton(); 59 | ctrlcButton = new javax.swing.JButton(); 60 | printButton = new javax.swing.JButton(); 61 | 62 | setLayout(new java.awt.BorderLayout()); 63 | 64 | graphPanel.setLayout(new java.awt.BorderLayout()); 65 | add(graphPanel, java.awt.BorderLayout.CENTER); 66 | 67 | csvButton.setText("Export CSV"); 68 | csvButton.addActionListener(new java.awt.event.ActionListener() { 69 | public void actionPerformed(java.awt.event.ActionEvent evt) { 70 | csvButtonActionPerformed(evt); 71 | } 72 | }); 73 | buttonPanel.add(csvButton); 74 | 75 | jpgBuitton.setText("Export JPG"); 76 | jpgBuitton.addActionListener(new java.awt.event.ActionListener() { 77 | public void actionPerformed(java.awt.event.ActionEvent evt) { 78 | jpgBuittonActionPerformed(evt); 79 | } 80 | }); 81 | buttonPanel.add(jpgBuitton); 82 | 83 | pngButton.setText("Export PNG"); 84 | pngButton.addActionListener(new java.awt.event.ActionListener() { 85 | public void actionPerformed(java.awt.event.ActionEvent evt) { 86 | pngButtonActionPerformed(evt); 87 | } 88 | }); 89 | buttonPanel.add(pngButton); 90 | 91 | ctrlcButton.setText("Copy"); 92 | ctrlcButton.addActionListener(new java.awt.event.ActionListener() { 93 | public void actionPerformed(java.awt.event.ActionEvent evt) { 94 | ctrlcButtonActionPerformed(evt); 95 | } 96 | }); 97 | buttonPanel.add(ctrlcButton); 98 | 99 | printButton.setText("Print"); 100 | printButton.addActionListener(new java.awt.event.ActionListener() { 101 | public void actionPerformed(java.awt.event.ActionEvent evt) { 102 | printButtonActionPerformed(evt); 103 | } 104 | }); 105 | buttonPanel.add(printButton); 106 | 107 | add(buttonPanel, java.awt.BorderLayout.SOUTH); 108 | } // //GEN-END:initComponents 109 | 110 | private void csvButtonActionPerformed( 111 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_csvButtonActionPerformed 112 | String filename; 113 | String buffer; 114 | 115 | filename = askSaveFilename("Export CSV", Config.getLastExportDirectory()); 116 | 117 | if (filename == null) { 118 | return; 119 | } 120 | Config.setLastExportDirectory(filename); 121 | if (!Config.getLastExportDirectory().isDirectory()) { 122 | Config.setLastExportDirectory(Config.getLastExportDirectory().getParentFile()); 123 | Config.save(); 124 | } 125 | 126 | buffer = thegraph.make_csv(); 127 | 128 | log.debug(buffer); 129 | 130 | BufferedWriter out; 131 | try { 132 | out = new BufferedWriter(new FileWriter(filename)); 133 | } catch (IOException e) { 134 | out = null; 135 | } 136 | if (out == null) { 137 | return; 138 | } 139 | try { 140 | out.write(buffer); 141 | out.flush(); 142 | out.close(); 143 | } catch (IOException e) { 144 | 145 | } 146 | 147 | 148 | } //GEN-LAST:event_csvButtonActionPerformed 149 | 150 | private void jpgBuittonActionPerformed( 151 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_jpgBuittonActionPerformed 152 | String filename = askSaveFilename("Export JPG", Config.getLastExportDirectory()); 153 | if (filename == null) { 154 | return; 155 | } 156 | thegraph.saveJPG(filename, Config.getImageWidth(), Config.getImageHeight()); 157 | } //GEN-LAST:event_jpgBuittonActionPerformed 158 | 159 | private void ctrlcButtonActionPerformed( 160 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_ctrlcButtonActionPerformed 161 | mychartpanel.doCopy(); 162 | } //GEN-LAST:event_ctrlcButtonActionPerformed 163 | 164 | private void printButtonActionPerformed( 165 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_printButtonActionPerformed 166 | mychartpanel.createChartPrintJob(); 167 | } //GEN-LAST:event_printButtonActionPerformed 168 | 169 | private void pngButtonActionPerformed( 170 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_pngButtonActionPerformed 171 | String filename = askSaveFilename("Export PNG", Config.getLastExportDirectory()); 172 | if (filename == null) { 173 | return; 174 | } 175 | thegraph.savePNG(filename, Config.getImageWidth(), Config.getImageHeight()); 176 | } //GEN-LAST:event_pngButtonActionPerformed 177 | 178 | 179 | private String askSaveFilename(String title, File chdirto) { 180 | String filename = null; 181 | JFileChooser chooser = new JFileChooser(); 182 | chooser.setDialogTitle(title); 183 | if (chdirto != null) { 184 | chooser.setCurrentDirectory(chdirto); 185 | } 186 | int returnVal = chooser.showSaveDialog(GlobalOptions.getUI()); 187 | if (returnVal == JFileChooser.APPROVE_OPTION) { 188 | filename = chooser.getSelectedFile().getAbsolutePath(); 189 | } 190 | 191 | if (filename == null) { 192 | return null; 193 | } 194 | 195 | if (new File(filename).exists()) { 196 | String[] choix = {"Yes", "No"}; 197 | int resultat = 198 | JOptionPane.showOptionDialog(null, "Overwrite " + filename + " ?", "File Exist", 199 | JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choix, 200 | choix[1]); 201 | if (resultat != 0) { 202 | return null; 203 | } 204 | } 205 | return filename; 206 | } 207 | 208 | // Variables declaration - do not modify//GEN-BEGIN:variables 209 | private javax.swing.JPanel buttonPanel; 210 | private javax.swing.JButton csvButton; 211 | private javax.swing.JButton ctrlcButton; 212 | private javax.swing.JPanel graphPanel; 213 | private javax.swing.JButton jpgBuitton; 214 | private javax.swing.JButton pngButton; 215 | private javax.swing.JButton printButton; 216 | // End of variables declaration//GEN-END:variables 217 | private Graph thegraph = null; 218 | private ChartPanel mychartpanel = null; 219 | } 220 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/HostInfoView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import net.atomique.ksar.GlobalOptions; 9 | import net.atomique.ksar.xml.HostInfo; 10 | 11 | public class HostInfoView extends javax.swing.JDialog { 12 | 13 | /** 14 | * Creates new form HostInfoView 15 | */ 16 | public HostInfoView(java.awt.Frame parent, HostInfo tmphostinfo) { 17 | 18 | super(parent, true); 19 | hostinfo = tmphostinfo; 20 | initComponents(); 21 | Hostname.setText(hostinfo.getHostname()); 22 | AliasField.setText(hostinfo.getAlias()); 23 | jTextArea1.setText(hostinfo.getDescription()); 24 | memboxcombo.setSelectedItem(hostinfo.getMemBlockSize().toString()); 25 | setLocationRelativeTo(parent); 26 | } 27 | 28 | /** 29 | * This method is called from within the constructor to 30 | * initialize the form. 31 | * WARNING: Do NOT modify this code. The content of this method is 32 | * always regenerated by the Form Editor. 33 | */ 34 | @SuppressWarnings("unchecked") 35 | // //GEN-BEGIN:initComponents 36 | private void initComponents() { 37 | 38 | jPanel1 = new javax.swing.JPanel(); 39 | hostnamePanel = new javax.swing.JPanel(); 40 | HostNameLabel = new javax.swing.JLabel(); 41 | Hostname = new javax.swing.JLabel(); 42 | AliasPanel = new javax.swing.JPanel(); 43 | AliasLabel = new javax.swing.JLabel(); 44 | AliasField = new javax.swing.JTextField(); 45 | DescriptionPanel = new javax.swing.JPanel(); 46 | descriptionLabel = new javax.swing.JLabel(); 47 | jScrollPane1 = new javax.swing.JScrollPane(); 48 | jTextArea1 = new javax.swing.JTextArea(); 49 | MemoryPanel = new javax.swing.JPanel(); 50 | memBlockSizeLabel = new javax.swing.JLabel(); 51 | memboxcombo = new javax.swing.JComboBox(); 52 | jPanel2 = new javax.swing.JPanel(); 53 | OkButton = new javax.swing.JButton(); 54 | 55 | setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 56 | setTitle("Host Information"); 57 | 58 | jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 59 | jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.PAGE_AXIS)); 60 | 61 | hostnamePanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); 62 | 63 | HostNameLabel.setLabelFor(Hostname); 64 | HostNameLabel.setText("Hostname:"); 65 | hostnamePanel.add(HostNameLabel); 66 | 67 | Hostname.setText("hostname"); 68 | hostnamePanel.add(Hostname); 69 | 70 | jPanel1.add(hostnamePanel); 71 | 72 | AliasPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); 73 | 74 | AliasLabel.setText("Alias"); 75 | AliasLabel.setPreferredSize(new java.awt.Dimension(52, 14)); 76 | AliasPanel.add(AliasLabel); 77 | 78 | AliasField.setMinimumSize(new java.awt.Dimension(120, 20)); 79 | AliasField.setPreferredSize(new java.awt.Dimension(120, 20)); 80 | AliasPanel.add(AliasField); 81 | 82 | jPanel1.add(AliasPanel); 83 | 84 | DescriptionPanel.setLayout( 85 | new javax.swing.BoxLayout(DescriptionPanel, javax.swing.BoxLayout.PAGE_AXIS)); 86 | 87 | descriptionLabel.setText("Description"); 88 | descriptionLabel.setPreferredSize(new java.awt.Dimension(52, 14)); 89 | DescriptionPanel.add(descriptionLabel); 90 | 91 | jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 200)); 92 | 93 | jTextArea1.setColumns(20); 94 | jTextArea1.setRows(5); 95 | jTextArea1.setPreferredSize(new java.awt.Dimension(300, 200)); 96 | jScrollPane1.setViewportView(jTextArea1); 97 | 98 | DescriptionPanel.add(jScrollPane1); 99 | 100 | jPanel1.add(DescriptionPanel); 101 | 102 | MemoryPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); 103 | 104 | memBlockSizeLabel.setText("Memory Block Size:"); 105 | MemoryPanel.add(memBlockSizeLabel); 106 | 107 | memboxcombo.setModel(new javax.swing.DefaultComboBoxModel( 108 | new String[]{"1024", "2048", "4096", "8192", "16384"})); 109 | MemoryPanel.add(memboxcombo); 110 | 111 | jPanel1.add(MemoryPanel); 112 | 113 | getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); 114 | 115 | jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 15, 5)); 116 | 117 | OkButton.setText("Ok"); 118 | OkButton.addActionListener(new java.awt.event.ActionListener() { 119 | public void actionPerformed(java.awt.event.ActionEvent evt) { 120 | OkButtonActionPerformed(evt); 121 | } 122 | }); 123 | jPanel2.add(OkButton); 124 | 125 | getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); 126 | 127 | pack(); 128 | } // //GEN-END:initComponents 129 | 130 | private void OkButtonActionPerformed( 131 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_OkButtonActionPerformed 132 | this.dispose(); 133 | hostinfo.setAlias(AliasField.getText()); 134 | hostinfo.setDescription(jTextArea1.getText()); 135 | hostinfo.setMemBlockSize(memboxcombo.getSelectedItem().toString()); 136 | GlobalOptions.addHostInfo(hostinfo); 137 | } //GEN-LAST:event_OkButtonActionPerformed 138 | 139 | 140 | // Variables declaration - do not modify//GEN-BEGIN:variables 141 | private javax.swing.JTextField AliasField; 142 | private javax.swing.JLabel AliasLabel; 143 | private javax.swing.JPanel AliasPanel; 144 | private javax.swing.JPanel DescriptionPanel; 145 | private javax.swing.JLabel HostNameLabel; 146 | private javax.swing.JLabel Hostname; 147 | private javax.swing.JPanel MemoryPanel; 148 | private javax.swing.JButton OkButton; 149 | private javax.swing.JLabel descriptionLabel; 150 | private javax.swing.JPanel hostnamePanel; 151 | private javax.swing.JPanel jPanel1; 152 | private javax.swing.JPanel jPanel2; 153 | private javax.swing.JScrollPane jScrollPane1; 154 | private javax.swing.JTextArea jTextArea1; 155 | private javax.swing.JLabel memBlockSizeLabel; 156 | private javax.swing.JComboBox memboxcombo; 157 | // End of variables declaration//GEN-END:variables 158 | HostInfo hostinfo = null; 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/LinuxDateFormat.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/LinuxDateFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import javax.swing.DefaultComboBoxModel; 9 | 10 | public class LinuxDateFormat extends javax.swing.JDialog { 11 | 12 | /** 13 | * Creates new form LinuxDateFormat 14 | */ 15 | public LinuxDateFormat(java.awt.Frame parent, boolean modal) { 16 | super(parent, modal); 17 | initComponents(); 18 | load_linuxformat(); 19 | pack(); 20 | setLocationRelativeTo(parent); 21 | toFront(); 22 | setVisible(true); 23 | 24 | } 25 | 26 | private void load_linuxformat() { 27 | LinuxFormatComboModel.addElement("Automatic Detection"); 28 | LinuxFormatComboModel.addElement("MM/DD/YY 23:59:59"); 29 | LinuxFormatComboModel.addElement("MM/DD/YYYY 23:59:59"); 30 | LinuxFormatComboModel.addElement("DD/MM/YY 23:59:59"); 31 | LinuxFormatComboModel.addElement("DD/MM/YYYY 23:59:59"); 32 | LinuxFormatComboModel.addElement("YYYY-MM-DD 23:59:59"); 33 | LinuxFormatComboModel.addElement("MM/DD/YY 12:59:59 AM|PM"); 34 | LinuxFormatComboModel.addElement("MM/DD/YYYY 12:59:59 AM|PM"); 35 | LinuxFormatComboModel.addElement("DD/MM/YY 12:59:59 AM|PM"); 36 | LinuxFormatComboModel.addElement("DD/MM/YYYY 12:59:59 AM|PM"); 37 | LinuxFormatComboModel.addElement("YYYY-MM-DD 12:59:59 AM|PM"); 38 | } 39 | 40 | /** 41 | * This method is called from within the constructor to 42 | * initialize the form. 43 | * WARNING: Do NOT modify this code. The content of this method is 44 | * always regenerated by the Form Editor. 45 | */ 46 | @SuppressWarnings("unchecked") 47 | // //GEN-BEGIN:initComponents 48 | private void initComponents() { 49 | 50 | jPanel1 = new javax.swing.JPanel(); 51 | jPanel3 = new javax.swing.JPanel(); 52 | jLabel1 = new javax.swing.JLabel(); 53 | jComboBox1 = new javax.swing.JComboBox(); 54 | jPanel4 = new javax.swing.JPanel(); 55 | jCheckBox1 = new javax.swing.JCheckBox(); 56 | jPanel2 = new javax.swing.JPanel(); 57 | OkButton = new javax.swing.JButton(); 58 | 59 | setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 60 | 61 | jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.PAGE_AXIS)); 62 | 63 | jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); 64 | 65 | jLabel1.setLabelFor(jComboBox1); 66 | jLabel1.setText("Select date format:"); 67 | jPanel3.add(jLabel1); 68 | 69 | jComboBox1.setModel(LinuxFormatComboModel); 70 | jComboBox1.setPreferredSize(new java.awt.Dimension(300, 27)); 71 | jPanel3.add(jComboBox1); 72 | 73 | jPanel1.add(jPanel3); 74 | 75 | jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); 76 | 77 | jCheckBox1.setText("Always use this format"); 78 | jPanel4.add(jCheckBox1); 79 | 80 | jPanel1.add(jPanel4); 81 | 82 | getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); 83 | 84 | OkButton.setText("Ok"); 85 | OkButton.addActionListener(new java.awt.event.ActionListener() { 86 | public void actionPerformed(java.awt.event.ActionEvent evt) { 87 | OkButtonActionPerformed(evt); 88 | } 89 | }); 90 | jPanel2.add(OkButton); 91 | 92 | getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH); 93 | 94 | pack(); 95 | } // //GEN-END:initComponents 96 | 97 | private void OkButtonActionPerformed( 98 | java.awt.event.ActionEvent evt) { //GEN-FIRST:event_OkButtonActionPerformed 99 | this.dispose(); 100 | ok_to_proceed = true; 101 | } //GEN-LAST:event_OkButtonActionPerformed 102 | 103 | public boolean hasToRemenber() { 104 | return jCheckBox1.isSelected(); 105 | } 106 | 107 | public String getDateFormat() { 108 | return (String) jComboBox1.getSelectedItem(); 109 | } 110 | 111 | public boolean isOk() { 112 | return ok_to_proceed; 113 | } 114 | 115 | // Variables declaration - do not modify//GEN-BEGIN:variables 116 | private javax.swing.JButton OkButton; 117 | private javax.swing.JCheckBox jCheckBox1; 118 | private javax.swing.JComboBox jComboBox1; 119 | private javax.swing.JLabel jLabel1; 120 | private javax.swing.JPanel jPanel1; 121 | private javax.swing.JPanel jPanel2; 122 | private javax.swing.JPanel jPanel3; 123 | private javax.swing.JPanel jPanel4; 124 | // End of variables declaration//GEN-END:variables 125 | 126 | DefaultComboBoxModel LinuxFormatComboModel = new DefaultComboBoxModel<>(); 127 | boolean ok_to_proceed = false; 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/NaturalComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import java.util.Comparator; 9 | import java.util.regex.Matcher; 10 | import java.util.regex.Pattern; 11 | 12 | /** 13 | * Compares strings in "human natural order". 14 | * E.g. {@code "cpu 2" < "cpu 10"}, and {@code "cpu 1 core 10 thread1" > "cpu1core2thread2"} 15 | */ 16 | public class NaturalComparator implements Comparator { 17 | public final static Comparator INSTANCE = new NaturalComparator(); 18 | public final static Comparator NULLS_FIRST = Comparator.nullsFirst(INSTANCE); 19 | 20 | private final static Pattern WORD_PATTERN = Pattern.compile("\\s*+([^0-9\\s]++|\\d++)"); 21 | 22 | @Override 23 | public int compare(String a, String b) { 24 | if (a == null || b == null) { 25 | return 0; // nulls should be handled in other comparator 26 | } 27 | 28 | Matcher ma = WORD_PATTERN.matcher(a); 29 | Matcher mb = WORD_PATTERN.matcher(b); 30 | 31 | while (true) { 32 | boolean findA = ma.find(); 33 | boolean findB = mb.find(); 34 | if (findA && !findB) { 35 | return 1; 36 | } 37 | if (!findA) { 38 | return findB ? -1 : 0; 39 | } 40 | String u = ma.group(1); 41 | String v = mb.group(1); 42 | 43 | if (Character.isDigit(u.charAt(0)) && Character.isDigit(v.charAt(0))) { 44 | int res = Integer.compare(u.length(), v.length()); 45 | if (res != 0) { 46 | // The shorter the length the smaller the number 47 | return res; 48 | } 49 | } 50 | // Ether both are numeric of equal length (see above if) 51 | // or they are non-numeric, then we compare as strings 52 | // or one of them is numeric and another is not, then we compare as strings anyway 53 | int res = u.compareTo(v); 54 | if (res != 0) { 55 | return res; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/ParentNodeInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import net.atomique.ksar.graph.List; 9 | 10 | public class ParentNodeInfo { 11 | 12 | public ParentNodeInfo(String t, List list) { 13 | node_title = t; 14 | node_object = list; 15 | } 16 | 17 | public List getNode_object() { 18 | return node_object; 19 | } 20 | 21 | public String getNode_title() { 22 | return node_title; 23 | } 24 | 25 | public String toString() { 26 | return node_title; 27 | } 28 | 29 | private String node_title = null; 30 | private List node_object = null; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/SortedTreeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import java.util.Comparator; 9 | import javax.swing.tree.DefaultMutableTreeNode; 10 | import javax.swing.tree.MutableTreeNode; 11 | 12 | public class SortedTreeNode extends DefaultMutableTreeNode implements Comparable { 13 | 14 | public static final long serialVersionUID = 15071L; 15 | 16 | private static final Comparator comparator = 17 | Comparator.nullsFirst( 18 | Comparator.comparing("all"::equals) 19 | .thenComparing("sum"::equals) 20 | .thenComparing("lo"::equals) 21 | .reversed() 22 | .thenComparing(NaturalComparator.INSTANCE)); 23 | 24 | public SortedTreeNode(String name) { 25 | super(name); 26 | } 27 | 28 | public SortedTreeNode(TreeNodeInfo tmp) { 29 | super(tmp); 30 | } 31 | 32 | public SortedTreeNode(ParentNodeInfo tmp) { 33 | super(tmp); 34 | } 35 | 36 | @Override 37 | public void insert(final MutableTreeNode newChild, final int childIndex) { 38 | super.insert(newChild, childIndex); 39 | this.children.sort(null); 40 | } 41 | 42 | public int compareTo(final SortedTreeNode o) { 43 | return comparator.compare(this.toString(), o.toString()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/ui/TreeNodeInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import net.atomique.ksar.graph.Graph; 9 | 10 | public class TreeNodeInfo { 11 | 12 | public TreeNodeInfo(String t, Graph graph) { 13 | node_title = t; 14 | node_object = graph; 15 | } 16 | 17 | public Graph getNode_object() { 18 | return node_object; 19 | } 20 | 21 | public String getNode_title() { 22 | return node_title; 23 | } 24 | 25 | public String toString() { 26 | return node_title; 27 | } 28 | 29 | private String node_title = null; 30 | private Graph node_object = null; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/CnxHistory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.Iterator; 12 | import java.util.TreeSet; 13 | 14 | public class CnxHistory { 15 | 16 | private static final Logger log = LoggerFactory.getLogger(CnxHistory.class); 17 | 18 | public CnxHistory(String link) { 19 | this.link = link; 20 | commandList = new TreeSet(); 21 | String[] s = link.split("@", 2); 22 | if (s.length != 2) { 23 | return; 24 | } 25 | this.setUsername(s[0]); 26 | String[] t = s[1].split(":"); 27 | if (t.length == 2) { 28 | this.setHostname(t[0]); 29 | this.setPort(t[1]); 30 | } else { 31 | this.setHostname(s[1]); 32 | this.setPort("22"); 33 | } 34 | } 35 | 36 | public void addCommand(String s) { 37 | commandList.add(s); 38 | } 39 | 40 | public TreeSet getCommandList() { 41 | return commandList; 42 | } 43 | 44 | public String getHostname() { 45 | return hostname; 46 | } 47 | 48 | public void setHostname(String hostname) { 49 | this.hostname = hostname; 50 | } 51 | 52 | public String getUsername() { 53 | return username; 54 | } 55 | 56 | public void setUsername(String username) { 57 | this.username = username; 58 | } 59 | 60 | public String getPort() { 61 | return port; 62 | } 63 | 64 | public int getPortInt() { 65 | return Integer.parseInt(port); 66 | } 67 | 68 | public void setPort(String port) { 69 | this.port = port; 70 | } 71 | 72 | public String getLink() { 73 | return link; 74 | } 75 | 76 | public boolean isValid() { 77 | if (username == null) { 78 | return false; 79 | } 80 | if (hostname == null) { 81 | return false; 82 | } 83 | return !commandList.isEmpty(); 84 | } 85 | 86 | public void dump() { 87 | log.debug(username + "@" + hostname + ":" + commandList); 88 | } 89 | 90 | public String save() { 91 | StringBuilder tmp = new StringBuilder(); 92 | if ("22".equals(port)) { 93 | tmp.append("\t\t\n"); 94 | } else { 95 | tmp.append("\t\t\n"); 96 | } 97 | Iterator ite = commandList.iterator(); 98 | while (ite.hasNext()) { 99 | tmp.append("\t\t\t").append(ite.next()).append("\n"); 100 | } 101 | tmp.append("\t\t\n"); 102 | return tmp.toString(); 103 | } 104 | 105 | private String username = null; 106 | private String hostname = null; 107 | private TreeSet commandList = null; 108 | private String port = null; 109 | private String link = null; 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/ColumnConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.awt.Color; 12 | 13 | public class ColumnConfig { 14 | 15 | private static final Logger log = LoggerFactory.getLogger(ColumnConfig.class); 16 | 17 | public ColumnConfig(String s) { 18 | data_title = s; 19 | } 20 | 21 | public void setData_color(String dataColorString) { 22 | 23 | String[] color_indices = dataColorString.split(","); 24 | 25 | if (color_indices.length == 3) { 26 | try { 27 | this.data_color = new Color(Integer.parseInt(color_indices[0]), 28 | Integer.parseInt(color_indices[1]), 29 | Integer.parseInt(color_indices[2])); 30 | } catch (IllegalArgumentException iae) { 31 | log.warn("Column color error for {} - <{}>", data_title, dataColorString, iae); 32 | } 33 | } else { 34 | log.warn("Wrong Color definition for {} - <{}>",data_title, dataColorString); 35 | } 36 | } 37 | 38 | public Color getData_color() { 39 | return data_color; 40 | } 41 | 42 | public String getData_title() { 43 | return data_title; 44 | } 45 | 46 | public void setType(String s) { 47 | if ("gauge".equals(s)) { 48 | type = 1; 49 | } 50 | if ("counter".equals(s)) { 51 | type = 2; 52 | } 53 | } 54 | 55 | public int getType() { 56 | return type; 57 | } 58 | 59 | public boolean is_valid() { 60 | 61 | return data_color != null; 62 | } 63 | 64 | private int type = 0; 65 | private Color data_color = null; 66 | private String data_title; 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/GraphConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | import java.util.LinkedHashMap; 9 | 10 | public class GraphConfig { 11 | 12 | public GraphConfig(String name, String title, String type) { 13 | this.name = name; 14 | this.title = title; 15 | this.type = type; 16 | plotlist = new LinkedHashMap<>(); 17 | stacklist = new LinkedHashMap<>(); 18 | } 19 | 20 | public String getTitle() { 21 | return title; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public String getType() { 29 | return type; 30 | } 31 | 32 | public void addPlot(PlotStackConfig s) { 33 | plotlist.put(s.getTitle(), s); 34 | } 35 | 36 | public LinkedHashMap getPlotlist() { 37 | return plotlist; 38 | } 39 | 40 | public void addStack(PlotStackConfig s) { 41 | stacklist.put(s.getTitle(), s); 42 | } 43 | 44 | public LinkedHashMap getStacklist() { 45 | return stacklist; 46 | } 47 | 48 | private String name; 49 | private String title; 50 | private String type; 51 | private LinkedHashMap plotlist; 52 | private LinkedHashMap stacklist; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/HostInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | public class HostInfo { 9 | 10 | public HostInfo(String s) { 11 | this.setHostname(s); 12 | } 13 | 14 | public Integer getMemBlockSize() { 15 | return MemBlockSize; 16 | } 17 | 18 | public void setMemBlockSize(Integer MemBlockSize) { 19 | this.MemBlockSize = MemBlockSize; 20 | } 21 | 22 | public void setMemBlockSize(String MemBlockSizestr) { 23 | try { 24 | this.MemBlockSize = Integer.parseInt(MemBlockSizestr); 25 | } catch (NumberFormatException nfe) { 26 | } 27 | } 28 | 29 | public String getAlias() { 30 | return aka_hostname; 31 | } 32 | 33 | public void setAlias(String aka_hostname) { 34 | this.aka_hostname = aka_hostname; 35 | } 36 | 37 | public String getDescription() { 38 | return description; 39 | } 40 | 41 | public void setDescription(String description) { 42 | this.description = description; 43 | } 44 | 45 | public String getHostname() { 46 | return sar_hostname; 47 | } 48 | 49 | public void setHostname(String sar_hostname) { 50 | this.sar_hostname = sar_hostname; 51 | } 52 | 53 | public String save() { 54 | StringBuilder tmp = new StringBuilder(); 55 | tmp.append("\t\t\n"); 56 | tmp.append("\t\t\t" + aka_hostname + "\n"); 57 | tmp.append("\t\t\t" + description + "\n"); 58 | tmp.append("\t\t\t" + MemBlockSize + "\n"); 59 | tmp.append("\t\t\n"); 60 | return tmp.toString(); 61 | } 62 | 63 | 64 | private String sar_hostname = null; 65 | private String aka_hostname = null; 66 | private String description = null; 67 | private Integer MemBlockSize = 1; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/OSConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | import java.util.Arrays; 9 | import java.util.HashMap; 10 | 11 | public class OSConfig { 12 | 13 | public OSConfig(String s) { 14 | OsName = s; 15 | } 16 | 17 | public void addStat(StatConfig s) { 18 | StatHash.put(s.getStatName(), s); 19 | } 20 | 21 | public void addGraph(GraphConfig s) { 22 | GraphHash.put(s.getName(), s); 23 | } 24 | 25 | public String getOsName() { 26 | return OsName; 27 | } 28 | 29 | public String getStat(String[] columns, int firstdatacolumn) { 30 | //this is called for each line of source file 31 | 32 | String[] s1 = Arrays.copyOfRange(columns, firstdatacolumn, columns.length); 33 | String header = String.join(" ", s1); 34 | 35 | //cache Mapping of HeaderStr to StatName - get StatHash more efficiently 36 | createCacheForMappingOfHeaderStr2StatName(); 37 | String statName = MappingStatHeaderName.get(header); 38 | 39 | if (statName != null) { 40 | return StatHash.get(statName).getGraphName(); 41 | } else { 42 | return null; 43 | } 44 | 45 | } 46 | 47 | private void createCacheForMappingOfHeaderStr2StatName() { 48 | //do this only once - all Stats are known - create reverse maaping 49 | if (MappingStatHeaderName == null) { 50 | 51 | MappingStatHeaderName = new HashMap<>(); 52 | 53 | StatHash.forEach((k, v) -> { 54 | String statName = v.getStatName(); 55 | String graphHeader = v.getHeaderStr(); 56 | 57 | MappingStatHeaderName.put(graphHeader, statName); 58 | }); 59 | } 60 | } 61 | 62 | public StatConfig getStat(String statName) { 63 | if (StatHash.isEmpty()) { 64 | return null; 65 | } 66 | 67 | StatConfig[] result = {null}; 68 | StatHash.keySet().forEach((String item) -> { 69 | StatConfig tmp = StatHash.get(item); 70 | if (tmp.getGraphName().equals(statName)) { 71 | result[0] = tmp; 72 | } 73 | }); 74 | return result[0]; 75 | } 76 | 77 | public GraphConfig getGraphConfig(String s) { 78 | if (GraphHash.isEmpty()) { 79 | return null; 80 | } 81 | return GraphHash.get(s); 82 | } 83 | 84 | public HashMap getStatHash() { 85 | return StatHash; 86 | } 87 | 88 | public HashMap getGraphHash() { 89 | return GraphHash; 90 | } 91 | 92 | 93 | private String OsName = null; 94 | private HashMap StatHash = new HashMap<>(); 95 | private HashMap GraphHash = new HashMap<>(); 96 | 97 | private HashMap MappingStatHeaderName; 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/PlotStackConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | import net.atomique.ksar.graph.IEEE1541Number; 9 | import net.atomique.ksar.graph.ISNumber; 10 | import org.jfree.chart.axis.NumberAxis; 11 | import org.jfree.data.Range; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.text.NumberFormat; 16 | 17 | public class PlotStackConfig { 18 | private static final Logger log = LoggerFactory.getLogger(PlotStackConfig.class); 19 | 20 | 21 | public PlotStackConfig(String title) { 22 | this.title = title; 23 | } 24 | 25 | public String[] getHeader() { 26 | return Header; 27 | } 28 | 29 | public String getTitle() { 30 | return title; 31 | } 32 | 33 | public void setHeaderStr(String s) { 34 | this.Header = s.split("\\s+"); 35 | HeaderStr = s; 36 | } 37 | 38 | public String getHeaderStr() { 39 | return HeaderStr; 40 | } 41 | 42 | public int getSize() { 43 | return size; 44 | } 45 | 46 | public void setSize(int size) { 47 | this.size = size; 48 | } 49 | 50 | public void setSize(String size) { 51 | this.size = Integer.valueOf(size); 52 | } 53 | 54 | public NumberAxis getAxis() { 55 | NumberAxis tmp = new NumberAxis(title); 56 | 57 | if (base == 1024) { 58 | 59 | NumberFormat decimalformat1 = new IEEE1541Number((int) factor); 60 | tmp.setNumberFormatOverride(decimalformat1); 61 | 62 | } else if (base == 1000) { 63 | 64 | NumberFormat decimalformat1 = new ISNumber((int) factor); 65 | tmp.setNumberFormatOverride(decimalformat1); 66 | 67 | } else if (base != 0) { 68 | log.error("base value is not handled"); 69 | } 70 | 71 | if (range != null) { 72 | tmp.setRange(range); 73 | } 74 | return tmp; 75 | } 76 | 77 | public void setBase(String s) { 78 | if (s == null) { 79 | return; 80 | } 81 | base = Integer.parseUnsignedInt(s); 82 | } 83 | 84 | public void setFactor(String s) { 85 | factor = Double.parseDouble(s); 86 | } 87 | 88 | public void setRange(String s) { 89 | String[] t = s.split(","); 90 | if (t.length == 2) { 91 | double min = Double.parseDouble(t[0]); 92 | double max = Double.parseDouble(t[1]); 93 | range = new Range(min, max); 94 | } 95 | } 96 | 97 | private double factor; 98 | private int base = 0; 99 | private Range range = null; 100 | private int size = 1; 101 | private String title; 102 | private String[] Header = null; 103 | private String HeaderStr = null; 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/net/atomique/ksar/xml/StatConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.xml; 7 | 8 | public class StatConfig { 9 | 10 | public StatConfig(String s) { 11 | StatName = s; 12 | } 13 | 14 | public String getGraphName() { 15 | return GraphName; 16 | } 17 | 18 | public void setGraphName(String GraphName) { 19 | this.GraphName = GraphName; 20 | } 21 | 22 | public String getHeaderStr() { 23 | return HeaderStr; 24 | } 25 | 26 | public void setHeaderStr(String s) { 27 | HeaderStr = s; 28 | } 29 | 30 | public String getStatName() { 31 | return StatName; 32 | } 33 | 34 | public boolean canDuplicateTime() { 35 | return duplicatetime; 36 | } 37 | 38 | public void setDuplicateTime(String s) { 39 | if ("yes".equals(s) || "true".equals(s)) { 40 | duplicatetime = true; 41 | } 42 | } 43 | 44 | 45 | private String StatName = null; 46 | private String GraphName = null; 47 | private String HeaderStr = null; 48 | private boolean duplicatetime = false; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/resources/AIX.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | cswch/s 15 | CSWCH 16 | 17 | 18 | iget/s lookuppn/s dirblk/s 19 | FILE 20 | 21 | 22 | scall/s sread/s swrit/s fork/s exec/s rchar/s wchar/s 23 | SYSCALL 24 | 25 | 26 | bread/s lread/s %rcache bwrit/s lwrit/s %wcache pread/s pwrit/s 27 | BUFFER 28 | 29 | 30 | device %busy avque r+w/s blks/s avwait avserv 31 | DEVICE 32 | 33 | 34 | device %busy avque r+w/s Kbs/s avwait avserv 35 | DEVICE 36 | 37 | 38 | msg/s sema/s 39 | MSGS 40 | 41 | 42 | ksched/s kproc-ov kexit/s 43 | IGNORE 44 | 45 | 46 | runq-sz %runocc swpq-sz %swpocc 47 | RUNQ 48 | 49 | 50 | slots cycle/s fault/s odio/s 51 | SLOT 52 | 53 | 54 | proc-sz inod-sz file-sz thrd-sz 55 | IGNORE 56 | 57 | 58 | rawch/s canch/s outch/s rcvin/s xmtin/s mdmin/s 59 | TTY 60 | 61 | 62 | %usr %sys %wio %idle 63 | CPU 64 | 65 | 66 | %usr %sys %wio %idle physc 67 | CPU 68 | 69 | 70 | cpu %usr %sys %wio %idle physc 71 | CPUS 72 | 73 | 74 | %usr %sys %wio %idle physc %entc 75 | CPU 76 | 77 | 78 | 79 | 80 | 81 | %usr %sys %wio 82 | 83 | 84 | %idle 85 | 86 | 87 | 88 | 89 | %usr %sys %wio 90 | 91 | 92 | %idle 93 | 94 | 95 | 96 | 97 | runq-sz 98 | 99 | 100 | swpq-sz 101 | 102 | 103 | %runocc %swpocc 104 | 0,100 105 | 106 | 107 | 108 | 109 | rawch/s canch/s outch/s rcvin/s xmtin/s mdmin/s 110 | 111 | 112 | 113 | 114 | cswch/s 115 | 116 | 117 | 118 | 119 | iget/s lookuppn/s dirblk/s 120 | 121 | 122 | 123 | 124 | scall/s 125 | 126 | 127 | sread/s swrit/s 128 | 129 | 130 | fork/s exec/s 131 | 132 | 133 | rchar/s wchar/s 134 | 135 | 136 | 137 | 138 | bread/s lread/s 139 | 140 | 141 | bwrit/s lwrit/s 142 | 143 | 144 | pread/s pwrit/s 145 | 146 | 147 | %rcache %wcache 148 | 149 | 150 | 151 | 152 | %busy 153 | 154 | 155 | avque 156 | 157 | 158 | r+w/s 159 | 160 | 161 | blks/s 162 | 163 | 164 | Kbs/s 165 | 166 | 167 | avwait 168 | 169 | 170 | avserv 171 | 172 | 173 | 174 | 175 | msg/s 176 | 177 | 178 | sema/s 179 | 180 | 181 | 182 | 183 | cycle/s fault/s odio/s 184 | 185 | 186 | slots 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /src/main/resources/HPUX.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | %usr %sys %wio %idle 15 | CPU 16 | 17 | 18 | device %busy avque r+w/s blks/s avwait avserv 19 | DEVICE 20 | 21 | 22 | runq-sz %runocc swpq-sz %swpocc 23 | RUNQ 24 | 25 | 26 | bread/s lread/s %rcache bwrit/s lwrit/s %wcache pread/s pwrit/s 27 | BUFFER 28 | 29 | 30 | swpin/s bswin/s swpot/s bswot/s pswch/s 31 | SWAP 32 | 33 | 34 | scall/s sread/s swrit/s fork/s exec/s rchar/s wchar/s 35 | SYSCALL 36 | 37 | 38 | iget/s namei/s dirbk/s 39 | FILE 40 | 41 | 42 | rawch/s canch/s outch/s rcvin/s xmtin/s mdmin/s 43 | TTY 44 | 45 | 46 | text-sz ov proc-sz ov inod-sz ov file-sz ov 47 | IGNORE 48 | 49 | 50 | msg/s sema/s 51 | MSGS 52 | 53 | 54 | cpu %usr %sys %wio %idle 55 | CPU 56 | 57 | 58 | 59 | %usr %sys %wio 60 | 0,100 61 | 62 | 63 | %idle 64 | 65 | 66 | 67 | 68 | %busy 69 | 70 | 71 | avque 72 | 73 | 74 | r+w/s 75 | 76 | 77 | blks/s 78 | 79 | 80 | avwait 81 | 82 | 83 | avserv 84 | 85 | 86 | 87 | 88 | runq-sz 89 | 90 | 91 | swpq-sz 92 | 93 | 94 | 95 | 96 | bread/s lread/s 97 | 98 | 99 | bwrit/s lwrit/s 100 | 101 | 102 | pread/s pwrit/s 103 | 104 | 105 | %rcache %wcache 106 | 107 | 108 | 109 | 110 | swpin/s swpot/s 111 | 112 | 113 | bswin/s bswot/s 114 | 115 | 116 | pswch/s 117 | 118 | 119 | 120 | 121 | scall/s 122 | 123 | 124 | sread/s swrit/s 125 | 126 | 127 | fork/s exec/s 128 | 129 | 130 | rchar/s wchar/s 131 | 132 | 133 | 134 | 135 | iget/s namei/s dirbk/s 136 | 137 | 138 | 139 | 140 | rawch/s canch/s outch/s rcvin/s xmtin/s mdmin/s 141 | 142 | 143 | 144 | 145 | msg/s 146 | 147 | 148 | sema/s 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /src/main/resources/config.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 54 | 55 | 56 | 57 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 77 | 78 | 79 | 80 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 97 | 98 | 99 | 100 | 104 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | ksar_all.log 15 | false 16 | 17 | %d{yyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/resources/logo_ksar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vlsi/ksar/0332fdf7f398880fc7658579f713872d40203868/src/main/resources/logo_ksar.jpg -------------------------------------------------------------------------------- /src/main/resources/net/atomique/ksar/Language/Message.properties: -------------------------------------------------------------------------------- 1 | # To change this template, choose Tools | Templates 2 | # and open the template in the editor. 3 | 4 | INPUT_REQUIRE_ARG=-input requires a filename as the argument 5 | TOO_MANY_ARGUMENTS=too many arguments: {} 6 | UNKNOWN_OPTION=unknown option: {} 7 | -------------------------------------------------------------------------------- /src/main/resources/net/atomique/ksar/Language/Message_fr_FR.properties: -------------------------------------------------------------------------------- 1 | # To change this template, choose Tools | Templates 2 | # and open the template in the editor. 3 | 4 | INPUT_REQUIRE_ARG=-input necessite un nom de fichier comme argument 5 | -------------------------------------------------------------------------------- /src/test/java/net/atomique/ksar/graph/IEEE1541NumberTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.graph; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.params.provider.Arguments.arguments; 10 | 11 | import org.junit.jupiter.api.Assertions; 12 | import org.junit.jupiter.params.ParameterizedTest; 13 | import org.junit.jupiter.params.provider.Arguments; 14 | import org.junit.jupiter.params.provider.MethodSource; 15 | 16 | import java.text.DecimalFormat; 17 | import java.util.stream.Stream; 18 | 19 | public class IEEE1541NumberTest { 20 | public static Stream testValues() { 21 | DecimalFormat fmt = new DecimalFormat("#,##0.0"); 22 | 23 | return Stream.of( 24 | arguments(791.5, fmt.format(791.5), fmt.format(791.5) + " Ki"), 25 | arguments(9462.04, fmt.format(9.2) + " Ki", fmt.format(9.2) + " Mi"), 26 | arguments(25414.88, fmt.format(24.8) + " Ki", fmt.format(24.8) + " Mi"), 27 | arguments(725414.88, fmt.format(708.4) + " Ki", fmt.format(708.4) + " Mi"), 28 | arguments(2725414.88, fmt.format(2.6) + " Mi", fmt.format(2.6) + " Gi"), 29 | arguments(27254140.88, fmt.format(26.0) + " Mi", fmt.format(26.0) + " Gi"), 30 | arguments(272541400.88, fmt.format(259.9) + " Mi", fmt.format(259.9) + " Gi"), 31 | arguments(2725414000.88, fmt.format(2.5) + " Gi", fmt.format(2599.2) + " Gi"), 32 | arguments(27254140000.88, fmt.format(25.4) + " Gi", fmt.format(25991.6) + " Gi"), 33 | arguments(272541400000.88, fmt.format(253.8) + " Gi", fmt.format(259915.7) + " Gi") 34 | ); 35 | } 36 | 37 | @ParameterizedTest 38 | @MethodSource("testValues") 39 | public void testFormat(double testNumber, String expectedFactor1, String expectedFactor1024) { 40 | Assertions.assertAll( 41 | () -> assertEquals( 42 | expectedFactor1, 43 | new IEEE1541Number(1).format(testNumber), 44 | () -> "factor=1; input number: " + testNumber 45 | ), 46 | () -> assertEquals( 47 | expectedFactor1024, 48 | new IEEE1541Number(1024).format(testNumber), 49 | () -> "factor=1024; input number: " + testNumber 50 | ) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/net/atomique/ksar/graph/ISNumberTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.graph; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertAll; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | import static org.junit.jupiter.params.provider.Arguments.arguments; 11 | 12 | import org.junit.jupiter.params.ParameterizedTest; 13 | import org.junit.jupiter.params.provider.Arguments; 14 | import org.junit.jupiter.params.provider.MethodSource; 15 | 16 | import java.text.DecimalFormat; 17 | import java.util.stream.Stream; 18 | 19 | public class ISNumberTest { 20 | public static Stream testValues() { 21 | DecimalFormat fmt = new DecimalFormat("#,##0.0"); 22 | 23 | return Stream.of( 24 | arguments(791.5, fmt.format(791.5), fmt.format(791.5) + " K"), 25 | arguments(9462.04, fmt.format(9.5) + " K", fmt.format(9.5) + " M"), 26 | arguments(25414.88, fmt.format(25.4) + " K", fmt.format(25.4) + " M"), 27 | arguments(725414.88, fmt.format(725.4) + " K", fmt.format(725.4) + " M"), 28 | arguments(2725414.88, fmt.format(2.7) + " M", fmt.format(2.7) + " G"), 29 | arguments(27254140.88, fmt.format(27.3) + " M", fmt.format(27.3) + " G"), 30 | arguments(272541400.88, fmt.format(272.5) + " M", fmt.format(272.5) + " G"), 31 | arguments(2725414000.88, fmt.format(2.7) + " G", fmt.format(2725.4) + " G"), 32 | arguments(27254140000.88, fmt.format(27.3) + " G", fmt.format(27254.1) + " G"), 33 | arguments(272541400000.88, fmt.format(272.5) + " G", fmt.format(272541.4) + " G") 34 | ); 35 | } 36 | 37 | @ParameterizedTest 38 | @MethodSource("testValues") 39 | public void testFormat(double testNumber, String expectedFactor1, String expectedFactor1000) { 40 | assertAll( 41 | () -> assertEquals( 42 | expectedFactor1, 43 | new ISNumber(1).format(testNumber), 44 | () -> "factor=1; input number: " + testNumber 45 | ), 46 | () -> assertEquals( 47 | expectedFactor1000, 48 | new ISNumber(1000).format(testNumber), 49 | () -> "factor=1000; input number: " + testNumber 50 | ) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/net/atomique/ksar/parser/HpuxHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.params.provider.Arguments.arguments; 10 | 11 | import net.atomique.ksar.kSar; 12 | import org.junit.jupiter.params.ParameterizedTest; 13 | import org.junit.jupiter.params.provider.Arguments; 14 | import org.junit.jupiter.params.provider.MethodSource; 15 | 16 | import java.time.LocalDateTime; 17 | import java.time.format.DateTimeFormatter; 18 | import java.util.stream.Stream; 19 | 20 | public class HpuxHeaderTest { 21 | @ParameterizedTest 22 | @MethodSource("testValues") 23 | public void test(String header, String sarString, LocalDateTime expectedDate) { 24 | HPUX sut = new HPUX(); 25 | String[] columns = sarString.split("\\s+"); 26 | kSar ksar = new kSar(); 27 | sut.init(ksar, header); 28 | sut.parse(sarString, columns); 29 | assertEquals(expectedDate, sut.getStartOfGraph(), () -> "header: " + header + ", sar string: " + sarString); 30 | } 31 | 32 | public static Stream testValues() { 33 | String str = "2018-03-21 00:05:01"; 34 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 35 | LocalDateTime dateTime = LocalDateTime.parse(str, formatter); 36 | 37 | return Stream.of( 38 | arguments( 39 | "HP-UX hostname.example.com B.11.31 U ia64 03/21/18", 40 | "00:05:01 19 8 29 45", 41 | dateTime)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/net/atomique/ksar/parser/LinuxHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.params.provider.Arguments.arguments; 10 | 11 | import net.atomique.ksar.Config; 12 | import net.atomique.ksar.kSar; 13 | import org.junit.jupiter.params.ParameterizedTest; 14 | import org.junit.jupiter.params.provider.Arguments; 15 | import org.junit.jupiter.params.provider.MethodSource; 16 | 17 | import java.time.LocalDateTime; 18 | import java.time.format.DateTimeFormatter; 19 | import java.util.stream.Stream; 20 | 21 | public class LinuxHeaderTest { 22 | @ParameterizedTest 23 | @MethodSource("testValues") 24 | public void test(String header, String sarString, LocalDateTime expectedDate) { 25 | String[] columns = sarString.split("\\s+"); 26 | kSar ksar = new kSar(); 27 | Config.setLinuxDateFormat("Automatic Detection"); 28 | Linux sut = new Linux(); 29 | sut.init(ksar, header); 30 | sut.parse(sarString, columns); 31 | assertEquals(expectedDate, sut.getStartOfGraph(), () -> "header: " + header + ", sar string: " + sarString); 32 | } 33 | 34 | public static Stream testValues() { 35 | String str = "2016-03-28 09:10:01"; 36 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 37 | LocalDateTime dateTime = LocalDateTime.parse(str, formatter); 38 | 39 | return Stream.of( 40 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 03/28/16 _x86_64_ (48 CPU)", 41 | "09:10:01 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 42 | dateTime), 43 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 03/28/2016 _x86_64_ (48 CPU)", 44 | "09:10:01 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 45 | dateTime), 46 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 20160328 _x86_64_ (48 CPU)", 47 | "09:10:01 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 48 | dateTime), 49 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 2016-03-28 _x86_64_ (48 CPU)", 50 | "09:10:01 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 51 | dateTime), 52 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 03/28/16 _x86_64_ (48 CPU)", 53 | "09:10:01 AM 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 54 | dateTime), 55 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 03/28/2016 _x86_64_ (48 CPU)", 56 | "09:10:01 AM 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 57 | dateTime), 58 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 20160328 _x86_64_ (48 CPU)", 59 | "09:10:01 AM 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 60 | dateTime), 61 | arguments("Linux 3.10.0-327.el7.x86_64 (hostname.example.com) 2016-03-28 _x86_64_ (48 CPU)", 62 | "09:10:01 AM 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00", 63 | dateTime)); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/net/atomique/ksar/parser/SolarisHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.parser; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.params.provider.Arguments.arguments; 10 | 11 | import net.atomique.ksar.kSar; 12 | import org.junit.jupiter.params.ParameterizedTest; 13 | import org.junit.jupiter.params.provider.Arguments; 14 | import org.junit.jupiter.params.provider.MethodSource; 15 | 16 | import java.time.LocalDateTime; 17 | import java.time.format.DateTimeFormatter; 18 | import java.util.stream.Stream; 19 | 20 | public class SolarisHeaderTest { 21 | @ParameterizedTest 22 | @MethodSource("testValues") 23 | public void test(String header, String sarString, LocalDateTime expectedDate) { 24 | String[] columns = sarString.split("\\s+"); 25 | kSar ksar = new kSar(); 26 | SunOS sut = new SunOS(); 27 | sut.init(ksar, header); 28 | sut.parse(sarString, columns); 29 | assertEquals(expectedDate, sut.getStartOfGraph(), () -> "header: " + header + ", sar string: " + sarString); 30 | } 31 | 32 | public static Stream testValues() { 33 | String str = "05/31/2018 00:05:01"; 34 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss"); 35 | LocalDateTime dateTime = LocalDateTime.parse(str, formatter); 36 | 37 | return Stream.of( 38 | arguments("SunOS hostname.example.com 5.11 11.3 sun4v 05/31/2018", 39 | "00:05:01 %usr %sys %wio %idle", 40 | dateTime)); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/net/atomique/ksar/ui/NaturalComparatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The kSAR Project. All rights reserved. 3 | * See the LICENSE file in the project root for more information. 4 | */ 5 | 6 | package net.atomique.ksar.ui; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | import static org.junit.jupiter.params.provider.Arguments.arguments; 10 | 11 | import org.junit.jupiter.params.ParameterizedTest; 12 | import org.junit.jupiter.params.provider.Arguments; 13 | import org.junit.jupiter.params.provider.MethodSource; 14 | 15 | import java.util.stream.Stream; 16 | 17 | public class NaturalComparatorTest { 18 | 19 | public static Stream data() { 20 | return Stream.of( 21 | arguments("1", "2", -1), 22 | arguments("1", "10", -1), 23 | arguments("1", "100", -1), 24 | arguments("11", "10", 1), 25 | arguments("10", "10", 0), 26 | arguments("2", "1", 1), 27 | arguments("2", "10", -1), 28 | arguments("02", "10", -1), 29 | arguments("02", "1", 1), 30 | 31 | arguments("a", "b", -1), 32 | arguments("a", "aa", -1), 33 | arguments("c", "a", 1), 34 | arguments("d", "d", 0), 35 | 36 | arguments("qw42", "ab42", 1), 37 | arguments("qw42", "ab43", 1), 38 | arguments("ab42", "ab43", -1), 39 | arguments("ab420", "ab43", 1), 40 | arguments("ab42cd", "ab42", 1), 41 | arguments("ab42cd", "ab42cd", 0), 42 | arguments("ab42cd2", "ab42cd10", -1), 43 | 44 | arguments("sdc", "sdc1", -1), 45 | arguments("sdc1", "sdc", 1), 46 | 47 | arguments("cpu 2", "cpu10", -1), 48 | arguments("cpu 1core10", "cpu1 core 2", 1), 49 | 50 | arguments(" cpu42", " cpu 42 ", 0), 51 | arguments(" cpu42", " cpu 120 ", -1), 52 | 53 | arguments("cpu 2", "cpu2core3", -1), 54 | arguments("cpu 1 core 10 thread1", "cpu1core2thread2", 1), 55 | arguments("", "cpu", -1), 56 | 57 | arguments("all", "0", 1) 58 | ); 59 | } 60 | 61 | @ParameterizedTest 62 | @MethodSource("data") 63 | public void testNaturalOrder(String a, String b, int expected) { 64 | NaturalComparator c = new NaturalComparator(); 65 | int res = c.compare(a, b); 66 | 67 | assertEquals(expected, Integer.signum(res), () -> a + " vs " + b); 68 | } 69 | } 70 | --------------------------------------------------------------------------------