0.2.18 • Published 3 years ago

@alexmcarrow/metricfromfuture v0.2.18

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Metric From Future

CodeQL

v0.2.18

Metric Server for calculation timing of script execution time

  • When script is run, metric use script execution time
  • When script is end with unix-code=0, metric use STDOUT as integer of script measuring
  • When script is end with unix-code>0, metric use 1000 second execution time - as error signal

Lifecycle

The Collector for each Metric starts the Runner with the specified frequency.

The launch of a new Runner is not limited to the already / still working Runners of this Metric.

Each Runner starts with time = -1 to handle fast execution correctly. Then its execution time will tend to a value equal to 0 .

Runner's working hours are not limited.

The collector with a frequency of 1 (one) second removes the current running time of the Runner (s). The highest value is more significant. This value is considered a LIVE -value.

When the Runner finishes working, he outputs to STDOUT the value that determines the time that the script has measured and considers it necessary to consider SAVE -value.

The SAVE -value is considered correct as long as it is less than any LIVE -value of the Runners of this Metric.


Used ENVs

ENVdescription
NODE_ENVIf not production redefine PATH_LOG & PATH_CONFIG to local logs-folder & local config.json
PATH_LOGPath (folder) to logs folder
PATH_CONFIGPath (file) to config.json

Example of config.json (see: config.json._)

{
    "server": {
        "port": 20744,
        "logs": false
    },
    "metric": {
        "check": {
            "interval": 15,
            "run": "/usr/bin/sh /home/user/check.sh",
            "notice": 20,
            "warning": 35,
            "error": 45,
            "history": 10,
            "call": "/usr/bin/sh /home/user/send.sh --metric=$1 --level=$2 --time=$3"
        },
    }
}

config.json structure

JSON-sectiontypedescription
server.portintegerMFF HTTP-RPC port
server.logsbooleanMFF can generate log-files
metric.[name]stringMetric section
metric.[name].intervalintegerMetric execution interval
metric.[name].runstringMetric execution script
metric.[name].noticeintegerMetric NOTICE timing
metric.[name].warningintegerMetric WARNING timing
metric.[name].errorintegerMetric ERROR timing
metric.[name].historyintegerMetric history storage size
metric.[name].callRegExp-stringMetric history execution script on (notice, warning, error) Can use RegExp params: $1 - Metric name [check] $2 - Logging level [notice\|warning\|error] $3 - Metric timing [10]

Logs

Each metric creates a file of the same name in the logs folder This log file contains records of not OK work ( notice , warning , error )

1634225398829|2021-10-14T15:29:58.829Z|alpha|notice|10
1634225398829|2021-10-14T15:29:58.829Z|alpha|warning|20
1634225398829|2021-10-14T15:29:58.829Z|alpha|error|1000

Log file structure (example by first row)

sectiontypedescription
1634225398829integerUnixtimestamp of record create
2021-10-14T15:29:58.829ZdatetimezUTC formated date-time
alphastringMetric name
noticestringLogging level
10integerMetric timing

HTTP-RPC

URI-pathvarsdescription
/---root of rpc
/?get=*---get all metrics data
/?get=all---get all metrics data
/?get=[name]name - metric nameget specific metric data
/?get=_sys---Metric name

Example of output for URI-path = /

{
    "c": 1,
    "d": { }
}
JSON-sectiontypedescription
cintegerResult code
dstringData section

Example of output for URI-path = /?get=* or /?get=all

{
    "c": 1,
    "d": {
        "alpha": {
            "v": 5,
            "t": 1634412899058,
            "dt": "2021-10-16T19:34:59.058Z",
            "hist": {
                "1634710497731": {
                    "v": 40,
                    "t": 1634710497731,
                    "dt": "2021-10-20T06:14:57.731Z"
                },
            }
        }
    }
}
JSON-sectiontypedescription
cintegerResult code
dstringData section
d.[name]objectMetric section
d.[name].vintActual timing for metric
d.[name].tintUnixtimestamp (with milliseconds) for actual timing
d.[name].dtintDatetime for actual timing
d.[name].histobjectHistory block
d.[name].hist.[histblock]stringUnixtimestamp (with milliseconds) of history block
d.[name].hist.[histblock].vintHistory timing
d.[name].hist.[histblock].tintHistory Unixtimestamp (with milliseconds)
d.[name].hist.[histblock].dtstringHistory Datetime

Example of output for URI-path = /?get=[name]

{
    "c": 1,
    "d": {
        "v": 5,
        "t": 1634413031384,
        "dt": "2021-10-16T19:37:11.384Z",
        "hist": {
            "1634710497731": {
                "v": 40,
                "t": 1634710497731,
                "dt": "2021-10-20T06:14:57.731Z"
            },
        }
    }
}
JSON-sectiontypedescription
cintegerResult code
dstringData section
d.vintActual timing for metric
d.tintUnixtimestamp for actual timing
d.dtintDatetime for actual timing
d.histobjectHistory block
d.hist.[histblock]stringUnixtimestamp (with milliseconds) of history block
d.hist.[histblock].vintHistory timing
d.hist.[histblock].tintHistory Unixtimestamp (with milliseconds)
d.hist.[histblock].dtstringHistory Datetime

Example of output for URI-path = /?get=_sys

{
    "c": 1,
    "d": {
        "alpha": {
            "v": 5,
            "t": 1634413183725,
            "dt": "2021-10-16T19:39:43.725Z",
            "hist": {
                "1634710497731": {
                    "v": 40,
                    "t": 1634710497731,
                    "dt": "2021-10-20T06:14:57.731Z"
                },
            },
            "r": {
                "6ad5e63d9b3f2dd54442c19bc64908a5": -1
            }
        }
    }
}
JSON-sectiontypedescription
cintegerResult code
dstringData section
d.[name]objectMetric section
d.[name].vintActual timing for metric
d.[name].tintUnixtimestamp for actual timing
d.[name].dtintDatetime for actual timing
d.[name].histobjectHistory block
d.[name].hist.[histblock]stringUnixtimestamp (with milliseconds) of history block
d.[name].hist.[histblock].vintHistory timing
d.[name].hist.[histblock].tintHistory Unixtimestamp (with milliseconds)
d.[name].hist.[histblock].dtstringHistory Datetime
d.[name].robjectList of exucuted Runners for this metric
d.[name].r[id]stringID of exucuted Runner
d.[name].r[id]=[value]intTime of Runner execution

License

The MIT License (MIT).

Please see LICENSE for more information.

Maintained by Alex McArrow