-
Notifications
You must be signed in to change notification settings - Fork 0
Add files for event support to time-in-area project #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Output to send all 'alerting_state_change' metrics to the event producer binary. | ||
| # The event is configured through the GKeyFile content specified when | ||
| # running the binary, using the following format: | ||
| # [topics] | ||
| # namespace = <NAMESPACE_NAME_STRING> | ||
| # nice_name = <NICE_NAME_STRING> | ||
| # topic_0 = <TOPIC_0_NAME_STRING> | ||
| # topic_1 = <TOPIC_1_NAME_STRING> | ||
| # topic_2 = <TOPIC_2_NAME_STRING> | ||
| # | ||
| # [settings] | ||
| # # true if event should be stateful | ||
| # # false if event should be stateless | ||
| # stateful = <true|false> | ||
| # | ||
| # [item.<ITEM_NAME>] | ||
| # kind = <data|source> | ||
| # data_type = <int|double|bool|string> | ||
| # value = <STARTING_VALUE> | ||
| # | ||
| # The [topics] and [settings] groups and all their key-value pairs | ||
| # are mandatory for successfully declaring the event. | ||
| # Items are optional, and multiple can be defined. | ||
| # | ||
| # The binary expects the passed json metrics to have the following | ||
| # format: | ||
| # | ||
| # { | ||
| # "fields": {<ITEM_NAME>: <NEW_VALUE> (...)}, | ||
| # "name":"<NAME>", | ||
| # "tags":{<TAGS>}, | ||
| # "timestamp":<TIMESTAMP> | ||
| # } | ||
| # | ||
| # Only the "fields" value matters, since it is the only part | ||
| # that is used by the binary. It will parse every key-value | ||
| # pair in "fields" and use those as the values to update | ||
| # in the event's items before sending it. If any item present | ||
| # during event declaration isn't specified in "fields", the | ||
| # the event will simply send the event with that key's | ||
| # previous value. | ||
| [[outputs.execd]] | ||
| # Only consume the 'alerting_state_change' metrics | ||
| namepass = ["alerting_state_change"] | ||
|
|
||
| # The binary expects JSON formatted metrics | ||
| data_format = "json" | ||
|
|
||
| # Command to run the binary, event structure is | ||
| # provided through GKeyFile-formatted input. | ||
| command = [ | ||
| "${EXECUTABLES_DIR}/output_event", "--config-inline", | ||
| """[topics] | ||
| namespace = tnsaxis | ||
| nice_name = FixedIT Time-in-Area Event | ||
| topic_0 = CameraApplicationPlatform | ||
| topic_1 = FixedITDataAgent | ||
| topic_2 = TimeInArea | ||
|
|
||
| [settings] | ||
| stateful = true | ||
|
|
||
| [item.active] | ||
| kind = data | ||
| data_type = bool | ||
| value = false | ||
| """ | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # This configuration file sets up a heartbeat metric | ||
| # and applies a Starlark processor for inactivity monitoring. | ||
| # The Starlark processor checks if there have been any alarming | ||
| # detections since the last heartbeat, and if not, sets | ||
| # the alarming state to "false". Note that it only monitors | ||
| # for alarming state metrics in general, it does not keep | ||
| # track of what or how many objects triggered the alarm. | ||
|
|
||
| # ---- Heartbeat (1 metric/second) ---- | ||
| [[inputs.exec]] | ||
| # This is a static heartbeat to trigger the inactivity monitor, | ||
| # so it does not matter what data it includes. | ||
| commands = ["sh -c 'echo heartbeat value=1i'"] | ||
| data_format = "influx" | ||
| interval = "1s" | ||
| name_override = "alarming_state_heartbeat" | ||
|
|
||
| # ---- Starlark processor ---- | ||
| # This gets triggered by both the heartbeat and any alarming state metrics. | ||
| # This makes sure the code is run at least once per second even if there | ||
| # are no alarming state metrics. | ||
| [[processors.starlark]] | ||
| namepass = ["alarming_state_heartbeat", "alerting_frame_two"] | ||
| source = ''' | ||
| """ | ||
| Monitor if an alerting_frame_two metric has not been sent | ||
| since the last alarming_state_heartbeat metric. | ||
| When we have an alerting object in the monitored zone, | ||
| we will get a metric every time we observe that object. | ||
| Once the object leaves the area, we stop receiving | ||
| alerting_frame_two metrics. This function makes sure that | ||
| we send a metric every time we go from no alerting objects | ||
| to at least one alerting object, and from at least one | ||
| alerting object to no alerting object. | ||
| """ | ||
| load("logging.star", "log") | ||
|
|
||
| """ | ||
| We initialize the state to keep it as a persistent | ||
| state between calls. We can use it to store information | ||
| such as the "has_alarm_since_last_heartbeat" or | ||
| "previous_alarm_state" values. | ||
| """ | ||
| state = { | ||
| # This variable is used to track if an "alerting_frame_two" | ||
| # metric has been received since the last | ||
| # "alarming_state_heartbeat" metric. | ||
| "has_alarm_since_last_heartbeat": False, | ||
|
|
||
| # This variable is used to check the alarm states | ||
| # previous value, to see if there has been a change | ||
| # from active to inactive or the other way around, | ||
| # since we only want to report on state changes. | ||
| "previous_alarm_state": None | ||
| } | ||
|
|
||
| def apply(metric): | ||
| # If we got an alerting frame, update the state to alerting state | ||
| # and return without producing any metric. | ||
| if metric.name == "alerting_frame_two": | ||
| state["has_alarm_since_last_heartbeat"] = True | ||
| return | ||
|
|
||
| # Validate that the metric is a heartbeat | ||
| if metric.name != "alarming_state_heartbeat": | ||
| log.debug("Error: received metric with unexpected name: " + metric.name) | ||
| return | ||
|
|
||
| has_alarm_since_last_heartbeat = state.get("has_alarm_since_last_heartbeat") | ||
daniel-falk marked this conversation as resolved.
Show resolved
Hide resolved
daniel-falk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| previous_alarm_state = state.get("previous_alarm_state") | ||
|
|
||
| # We want to track if the alarm has been triggered between | ||
| # heartbeats, so we always reset the state to False at | ||
| # each heartbeat so we can start monitoring again. | ||
| state["has_alarm_since_last_heartbeat"] = False | ||
daniel-falk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| state["previous_alarm_state"] = has_alarm_since_last_heartbeat | ||
|
|
||
| # We only want to report state changes, so we check the previous state | ||
| if (has_alarm_since_last_heartbeat != previous_alarm_state): | ||
| alarming_state_metric = Metric("alerting_state_change") | ||
| alarming_state_metric.time = metric.time | ||
| alarming_state_metric.fields["active"] = has_alarm_since_last_heartbeat | ||
| return alarming_state_metric | ||
| return | ||
| ''' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,12 @@ def apply(metric): | |
| # Create a new metric with the alerting name | ||
| alerting_metric = deepcopy(metric) | ||
| alerting_metric.name = "alerting_frame" | ||
| return alerting_metric | ||
|
|
||
| # Duplicate the metric, since it needs to get | ||
| # to two processors | ||
| alerting_metric_two = deepcopy(metric) | ||
| alerting_metric_two.name = "alerting_frame_two" | ||
| return [alerting_metric, alerting_metric_two] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Violates Single Metric Return Convention (Bugbot Rules)The |
||
|
|
||
| # Track doesn't exceed threshold - don't output | ||
| log.debug("apply: track_id=" + track_id + " duration=" + str(time_in_area) + "s < threshold=" + str(threshold) + "s - FILTER OUT") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.