Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: infra_libs/ts_mon/targets.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: add noncululativedistribution metric to ts_mon imports Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « infra_libs/ts_mon/standard_metrics.py ('k') | infra_libs/ts_mon/test/config_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Classes representing the monitoring interface for tasks or devices."""
6
7
8 class Target(object):
9 """Abstract base class for a monitoring target.
10
11 A Target is a "thing" that should be monitored, for example, a device or a
12 process. The majority of the time, a single process will have only a single
13 Target.
14
15 Do not directly instantiate an object of this class.
16 Use the concrete child classes instead:
17 * TaskTarget to monitor a job or tasks running in (potentially) many places;
18 * DeviceTarget to monitor a host machine that may be running a task.
19 """
20 def _populate_target_pb(self, metric):
21 """Populate the 'target' embedded message field of a metric protobuf."""
22 raise NotImplementedError()
23
24
25 class DeviceTarget(Target):
26 """Monitoring interface class for monitoring specific hosts or devices."""
27
28 def __init__(self, region, network, hostname):
29 """Create a Target object exporting info about a specific device.
30
31 Args:
32 region (str): physical region in which the device is located.
33 network (str): virtual network on which the device is located.
34 hostname (str): name by which the device self-identifies.
35 """
36 super(DeviceTarget, self).__init__()
37 self._region = region
38 self._network = network
39 self._hostname = hostname
40 self._realm = 'ACQ_CHROME'
41 self._alertable = True
42
43 def _populate_target_pb(self, metric):
44 """Populate the 'network_device' embedded message of a metric protobuf.
45
46 Args:
47 metric (metrics_pb2.MetricsData): the metric proto to be populated.
48 """
49 # Note that this disregards the pop, asn, role, and vendor fields.
50 metric.network_device.metro = self._region
51 metric.network_device.hostgroup = self._network
52 metric.network_device.hostname = self._hostname
53 metric.network_device.realm = self._realm
54 metric.network_device.alertable = self._alertable
55
56
57 class TaskTarget(Target):
58 """Monitoring interface class for monitoring active jobs or processes."""
59
60 def __init__(self, service_name, job_name,
61 region, hostname, task_num=0):
62 """Create a Target object exporting info about a specific task.
63
64 Args:
65 service_name (str): service of which this task is a part.
66 job_name (str): specific name of this task.
67 region (str): general region in which this task is running.
68 hostname (str): specific machine on which this task is running.
69 task_num (int): replication id of this task.
70 """
71 super(TaskTarget, self).__init__()
72 self._service_name = service_name
73 self._job_name = job_name
74 self._region = region
75 self._hostname = hostname
76 self._task_num = task_num
77
78 def _populate_target_pb(self, metric):
79 """Populate the 'task' embedded message field of a metric protobuf.
80
81 Args:
82 metric (metrics_pb2.MetricsData): the metric proto to be populated.
83 """
84 metric.task.service_name = self._service_name
85 metric.task.job_name = self._job_name
86 metric.task.data_center = self._region
87 metric.task.host_name = self._hostname
88 metric.task.task_num = self._task_num
OLDNEW
« no previous file with comments | « infra_libs/ts_mon/standard_metrics.py ('k') | infra_libs/ts_mon/test/config_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698