Skip to content

Commit

Permalink
Prometheus (#11)
Browse files Browse the repository at this point in the history
* Begin adding prometheus metric support

* Deeply navigate all metrics for prometheus

* Readme blurb
  • Loading branch information
zix99 authored Aug 28, 2019
1 parent 41188e8 commit 7f2be8a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ The following types are supported:

SshSysMon uses handlebars to template its summary output. See the [templating](/templates) for more information.

#### Prometheus

SshSysMon supports writing to a format supported by prometheus, which can in-turn be pushed to a pushgateway via a pipe.

```sh
sshmon -f prometheus myconfig.yml | curl --data-binary @- http://prometheus.example.com/metrics/job/sshmon
```

### Writing Your Own Component

To learn how to write a specific type of component, visit its readme in the appropriate subfolder.
Expand Down
29 changes: 28 additions & 1 deletion sshsysmon/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,39 @@ def __coalesce(this, *args):
def __alphanum(this, val, replaceWith='_'):
return sanitize(val, replaceWith)

def __numeric(this, val):
if hasattr(val, '__float__'):
return float(val)
if hasattr(val, '__int__'):
return int(val)
return 1 if val else 0

def __deepEach(this, options, obj):
results = []
def deepWalk(obj, address):
if isinstance(obj, list):
for i in range(len(obj)):
deepWalk(obj[i], '{}[{}]'.format(address, i))
elif isinstance(obj, dict):
for k, v in obj.items():
deepWalk(v, k if not address else '{}.{}'.format(address, k))
else:
kwargs = {
'key': address,
}
scope = pybars.Scope(obj, this, options['root'], **kwargs)
results.extend(options['fn'](scope))
deepWalk(obj, '')
return results

__helpers = {
'ifEq' : __ifEq,
'replace' : __replace,
'coalesce' : __coalesce,
'alphanum': __alphanum,
'format': __format
'format': __format,
'numeric': __numeric,
'deepEach': __deepEach,
}

def __template(src, data):
Expand Down
10 changes: 10 additions & 0 deletions sshsysmon/templates/prometheus.hb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TYPE sshmon_alert gauge
{{#servers}}{{#inspectors}}{{#alarms}}
sshmon_alert{server="{{alphanum ../../name}}",inspector="{{alphanum ../type}}",alarm="{{alphanum name}}"} {{#if fired}}1{{else}}0{{/if}}
{{! new line intentional }}
{{/alarms}}{{/inspectors}}{{/servers}}
# TYPE sshmon_metric gauge
{{#servers}}{{#inspectors}}{{#deepEach metrics}}
sshmon_metric{server="{{alphanum ../../name}}",inspector="{{alphanum ../type}}",name="{{alphanum @key}}"} {{numeric this}}
{{! intentionally blank}}
{{/deepEach}}{{/inspectors}}{{/servers}}

0 comments on commit 7f2be8a

Please sign in to comment.